fix(security): add cache-control headers to token endpoints #2217
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.
What kind of change does this PR introduce?
Bug fix - Security hardening
What is the current behavior?
Token endpoints (password grant, refresh token, PKCE, MFA, etc.) do not set
Cache-Controlheaders in their responses. This allows browsers to cache JWT token responses containing sensitive credentials.Security Impact:
about:cacheCache-Control: no-storeIssue discovered during professional security audit (OWASP OTG-AUTHN-006)
Affected endpoints:
/token?grant_type=password(password login)/token?grant_type=refresh_token(token refresh)/token?grant_type=pkce(OAuth PKCE flow)/token?grant_type=id_token(OIDC)/token?grant_type=web3(Web3 authentication)/verify(email/phone verification)/signup(user registration)What is the new behavior?
All token endpoints now return proper cache control headers:
Implementation:
sendTokenJSONhelper function ininternal/api/helpers.gosendTokenJSONinstead ofsendJSONBrowsers will no longer cache token responses, preventing exposure of JWT tokens through browser cache inspection.
Additional context
Testing performed:
make formatpassedmake vetpassedReferences:
This change affects all authentication flows but is backward compatible - it only adds headers, doesn't modify response bodies or behavior.