fix: externalize JWT signing secret - #19
Open
28Hus wants to merge 1 commit into
Open
Conversation
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
The JWT signing secret was hardcoded in both the shared user module and gateway service. Anyone who could read the public repository could forge valid HS512 tokens and impersonate arbitrary users.
The application stores tokens in Redis after successful login and uses this state for
checkLoginand logout. However, the gateway's protected routes do not query Redis. They only verify the JWT signature and expiration time, so a forged token does not need any corresponding server-side cache entry.This change removes the hardcoded secret and requires it to be provided by the deployment environment.
Changes
INDEX12306_JWT_SECRETenvironment variable.README.md.Security Impact
Before this change, the public repository secret could be used to create arbitrary HS512 JWTs containing attacker-controlled:
userIdusernamerealNameThe gateway accepted these claims for protected routes without checking whether the token had been issued by the login flow or existed in Redis.
Verification
The following checks passed locally:
INDEX12306_JWT_SECRETis configured.Deployment Notes
Existing deployments must configure
INDEX12306_JWT_SECRETbefore upgrading:The same secret must be configured for the user service and gateway within the same deployment. Different environments should use different secrets.
After rotating a leaked secret, all relevant services should be restarted so that tokens signed with the old secret are no longer accepted.
Scope
This PR addresses the publicly exposed hardcoded JWT signing key.
The existing Redis token storage is not currently used by the gateway authorization filter to validate protected requests. Adding server-side token-state validation would be a separate behavior change and is not included in this PR.