fix: remove hardcoded JWT secret key and add startup validation (CWE-798)#63
Open
saaa99999999 wants to merge 1 commit into
Open
fix: remove hardcoded JWT secret key and add startup validation (CWE-798)#63saaa99999999 wants to merge 1 commit into
saaa99999999 wants to merge 1 commit into
Conversation
…798) Replace the hardcoded "secret" signing key with an empty placeholder and add @PostConstruct validation that rejects empty, blank, or short secrets at startup, requiring developers to explicitly configure a strong key. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Author
CVE Request — Action Needed from MaintainerThis PR fixes security vulnerabilities. To assign a CVE number: GitHub only issues CVEs from the official upstream repository, not from forks. Please:
If you prefer, I can submit the CVE via MITRE (cveform.mitre.org) instead — just let me know. Thank you for reviewing this PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
application.yml:51defines a hardcoded JWT signing secretsecretKey: secret. This key is used to sign and verify all JWT tokens via HMAC-SHA256. Anyone who reads the public repository can forge valid authentication tokens for any user, achieving complete authentication bypass.Data Flow
src/main/resources/application.yml:51—secretKey: secret— hardcoded signing keyJwtProperties.java:17-18—@ConfigurationProperties(prefix = "jwt")bindsjwt.secretKeyto the fieldJwtTokenManager.java:37— Token signing:JwtTokenManager.java:73— Token verification uses the same key:JwtAuthenticationFilter.java:50— Filter extracts username from tokenJwtAuthenticationFilter.java:69— Filter validates token against extracted usernameThe
java-jwtlibrary (com.auth0:java-jwt) uses HMAC-SHA256, meaning the same key signs and verifies tokens. With a known key"secret", forged tokens pass verification.Fix
1.
application.yml:48-58— Remove hardcoded secretBefore:
After:
The
secretKey:with no value defaults to empty, causing startup failure unless the developer explicitly configures the key. Spring Boot's@ConfigurationPropertiesalso supports environment variable override:JWT_SECRETKEY=<key>.2.
JwtProperties.java— Add startup validationBefore:
After:
The
@PostConstructvalidation:openssl rand -base64 32JWT_SECRETKEYfor configurationImpact
secretis a single dictionary word and one of the most commonly used passwords. This is not a forgotten FIXME — it is an actively exploitable default.