[Security] Fix hardcoded JWT secret key ??use env var with startup validation (CWE-798)#45
Open
saaa99999999 wants to merge 1 commit into
Open
[Security] Fix hardcoded JWT secret key ??use env var with startup validation (CWE-798)#45saaa99999999 wants to merge 1 commit into
saaa99999999 wants to merge 1 commit into
Conversation
…artup validation (CWE-798)
Replaced the hardcoded jwt.secret with ${JWT_SECRET:} placeholder and added
@PostConstruct validation that rejects empty, known-default, and short keys.
The application now refuses to start with a clear error message if the JWT
secret is not properly configured.
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.
Security Audit Report ??springboot-jwt-starter (bfwg)
Manual code audit discovered 1 critical security vulnerability ??CWE-798: Hardcoded JWT Signing Key.
CRITICAL: CWE-798 ??Hardcoded JWT Secret Key in Public Repository (CVSS 9.1)
Location:
src/main/resources/application.yml:8Data Flow:
Description:
application.ymlcontains a hardcoded JWT signing keyp2H(++:$j*xKfKvK6n5k=},@@]CWkbj7d0iQ%6/;0}x6?[wNWR,$=0/HHx*&pJAqpublished in the public repository with 841 stars. The key is used with HS512 (HMAC-SHA512) symmetric algorithm ??the same key for both signing and verifying tokens.The key looks like a real generated key (63 complex characters), making it especially dangerous because developers are unlikely to recognize it as a default value that must be changed.
Anyone who reads the public repository can:
/auth/refreshendpoint uses the same key for re-signingTokenAuthenticationFilterextracts username from forged tokens and sets the full Spring Security contextPoC:
Fix:
application.yml:8: Replaced hardcoded secret with${JWT_SECRET:}??Spring Boot will read fromJWT_SECRETenv var, defaults to emptyTokenHelper.java:31: ChangedSECRETfrompublictoprivateTokenHelper.java:44-65: Added@PostConstruct validateSecret()that rejects empty keys, the original hardcoded key, other known weak values, and keys shorter than 32 characters. Application refuses to start with a clear error message.Before ??After:
application.yml:8:TokenHelper.java:31:TokenHelper.java:44-65(added):Changes in this PR (2 files)
${JWT_SECRET:}env var placeholder@PostConstruct validateSecret()with known-weak rejection + minimum length checkCVSS 3.1 Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N??9.1 (Critical)Manual security audit of Spring Boot JWT authentication configuration