mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
fix(auth): encrypt stored cookie keys; tighten the link and sign-out flows
- Data-protection keys are encrypted (AES-256-GCM, key derived from the server secret) before they reach the DataProtectionKeys table. - /link only follows local return paths and keeps the form when a signed-in visitor has an identity waiting to be linked. - A failed sign-out says so instead of reloading as if it worked.
This commit is contained in:
@@ -19,13 +19,18 @@ public class AuthService(IConfiguration config, DorkNetDbContext db)
|
||||
// configs) and leave Jwt:Secret as the appsettings.json placeholder;
|
||||
// the mismatched-secret bug shows up only there.
|
||||
private string SecretKey =>
|
||||
Environment.GetEnvironmentVariable("DORKNET_JWT_SECRET")
|
||||
?? Environment.GetEnvironmentVariable("RECNET_JWT_SECRET")
|
||||
?? config["Jwt:Secret"]
|
||||
ConfiguredSecret(config)
|
||||
?? throw new InvalidOperationException(
|
||||
"JWT secret not configured. Set DORKNET_JWT_SECRET env var or " +
|
||||
"Jwt:Secret in appsettings.Local.json.");
|
||||
|
||||
/// <summary>The server secret, in the one resolution order every user of
|
||||
/// it shares (token signing, token validation, key encryption).</summary>
|
||||
public static string? ConfiguredSecret(IConfiguration config) =>
|
||||
Environment.GetEnvironmentVariable("DORKNET_JWT_SECRET")
|
||||
?? Environment.GetEnvironmentVariable("RECNET_JWT_SECRET")
|
||||
?? config["Jwt:Secret"];
|
||||
|
||||
public string GenerateToken(long playerId) => CreateJwt(playerId, TimeSpan.FromHours(12), "access");
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user