From 5017e73bb54e626d4dc060fd553c972663eec45f Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 14 Feb 2026 18:31:40 -0500 Subject: [PATCH] fix(backend): use GenerateSecureRandomString for api-keys, paste ids, and refresh tokens --- SharpbinV3.Server/Services/ApiKeyService.cs | 2 +- SharpbinV3.Server/Services/AuthService.cs | 2 +- SharpbinV3.Server/Services/PasteService.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SharpbinV3.Server/Services/ApiKeyService.cs b/SharpbinV3.Server/Services/ApiKeyService.cs index c4d4b06..b3ee93b 100644 --- a/SharpbinV3.Server/Services/ApiKeyService.cs +++ b/SharpbinV3.Server/Services/ApiKeyService.cs @@ -29,7 +29,7 @@ namespace SharpbinV3.Server.Services public async Task<(ApiKey apiKey, string key)> CreateAsync(Guid userUUID, string name) { - var key = Utilities.GenerateRandomString(KeyLength); + var key = Utilities.GenerateSecureRandomString(KeyLength); var keyHash = ComputeHash(key); var apiKey = new ApiKey diff --git a/SharpbinV3.Server/Services/AuthService.cs b/SharpbinV3.Server/Services/AuthService.cs index ce8cc43..516b29d 100644 --- a/SharpbinV3.Server/Services/AuthService.cs +++ b/SharpbinV3.Server/Services/AuthService.cs @@ -92,7 +92,7 @@ namespace SharpbinV3.Server.Services var jwtToken = jwtHandler.WriteToken(token); var jti = claims.First(c => c.Type == JwtRegisteredClaimNames.Jti).Value; - var rawRefreshToken = Utilities.GenerateRandomString(36) + Guid.NewGuid(); + var rawRefreshToken = Utilities.GenerateSecureRandomString(36) + Guid.NewGuid(); var refreshToken = new RefreshToken { Id = Guid.NewGuid(), diff --git a/SharpbinV3.Server/Services/PasteService.cs b/SharpbinV3.Server/Services/PasteService.cs index 064c08b..2e8bbd9 100644 --- a/SharpbinV3.Server/Services/PasteService.cs +++ b/SharpbinV3.Server/Services/PasteService.cs @@ -35,7 +35,7 @@ namespace SharpbinV3.Server.Services var paste = new Paste { UUID = Guid.CreateVersion7(), - ID = Utilities.GenerateRandomString(8), + ID = Utilities.GenerateSecureRandomString(8), Title = title, AuthorUUID = author?.UUID, User = author,