-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 fix: Remove hardcoded JWT secret #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,8 +16,12 @@ | |||||||||||||||||||||||||||||
| var builder = WebApplication.CreateBuilder(args); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Configurar JWT | ||||||||||||||||||||||||||||||
| var key = Encoding.ASCII.GetBytes( | ||||||||||||||||||||||||||||||
| builder.Configuration["JwtSettings:Secret"] ?? "chave-super-secreta"); | ||||||||||||||||||||||||||||||
| var jwtSecret = builder.Configuration["JwtSettings:Secret"]; | ||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(jwtSecret) || jwtSecret == "YOUR_JWT_SECRET_KEY_HERE_MIN_32_CHARS" || jwtSecret.Length < 32) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| throw new InvalidOperationException("A valid JWT Secret must be configured in JwtSettings:Secret. The secret must be at least 32 characters long and not the default placeholder."); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| var key = Encoding.ASCII.GetBytes(jwtSecret); | ||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+24
|
||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(jwtSecret) || jwtSecret == "YOUR_JWT_SECRET_KEY_HERE_MIN_32_CHARS" || jwtSecret.Length < 32) | |
| { | |
| throw new InvalidOperationException("A valid JWT Secret must be configured in JwtSettings:Secret. The secret must be at least 32 characters long and not the default placeholder."); | |
| } | |
| var key = Encoding.ASCII.GetBytes(jwtSecret); | |
| if (string.IsNullOrEmpty(jwtSecret) || jwtSecret == "YOUR_JWT_SECRET_KEY_HERE_MIN_32_CHARS") | |
| { | |
| throw new InvalidOperationException("A valid JWT Secret must be configured in JwtSettings:Secret and not use the default placeholder."); | |
| } | |
| var key = Encoding.UTF8.GetBytes(jwtSecret); | |
| if (key.Length < 32) | |
| { | |
| throw new InvalidOperationException("A valid JWT Secret must be configured in JwtSettings:Secret. The secret must be at least 32 bytes long when encoded as UTF-8."); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The secret validation uses string.IsNullOrEmpty and doesn’t trim whitespace, so a value like " ..." (or an env var with trailing newline) can pass the check and be used as the signing key. Consider switching to IsNullOrWhiteSpace and validating against a trimmed value before comparing to the placeholder and checking length.