Skip to content

Commit

Permalink
don't show 500 when encrypted id invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 10, 2024
1 parent d9e04b4 commit 9940e68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/BE/Services/UrlEncryption/UrlEncryptionService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Chats.BE.Infrastructure.Functional;
using System.Security.Cryptography;

namespace Chats.BE.Services.UrlEncryption;

Expand Down Expand Up @@ -32,7 +33,15 @@ public string CreateSignedPath(TimedId timedId, EncryptionPurpose purpose)

public Result<int> DecodeSignedPathAsInt32(string path, long validBefore, string hash, EncryptionPurpose purpose)
{
int id = DecryptAsInt32(path, purpose);
int id;
try
{
id = DecryptAsInt32(path, purpose);
}
catch (CryptographicException)
{
return Result.Fail<int>("Invalid encrypted ID.");
}
DateTimeOffset validBeforeTime = DateTimeOffset.FromUnixTimeMilliseconds(validBefore);
if (validBeforeTime < DateTimeOffset.UtcNow)
{
Expand Down

0 comments on commit 9940e68

Please sign in to comment.