fix: pin JWT signing algorithm to prevent HS/RS confusion in verifyToken#109
Open
hacktron-app-stg[bot] wants to merge 1 commit into
Open
fix: pin JWT signing algorithm to prevent HS/RS confusion in verifyToken#109hacktron-app-stg[bot] wants to merge 1 commit into
hacktron-app-stg[bot] wants to merge 1 commit into
Conversation
The keyfunc returned the HMAC secret without checking token.Method, allowing an algorithm-confusion attack where an attacker signs a forged token with the HMAC key. Pin the accepted algorithm to HMAC in the keyfunc and via jwt.WithValidMethods.
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.
Vulnerability
verifyTokeninauth_gateway.goused ajwt.Parsekeyfunc that returned the HMAC secret without ever validatingtoken.Method. Because the library trusts whatever algorithm the token header declares when selecting verification, an attacker could craft a token with{"alg":"HS256"}, sign it with the HMAC key material (gateway-signing-key), and have it accepted — an authentication bypass (JWT algorithm confusion, CWE-347).Fix
t.Methodto*jwt.SigningMethodHMACand returns an error for any other method, so a downgraded/swappedalgheader is rejected before the secret is ever returned.jwt.WithValidMethods([]string{"HS256"})tojwt.Parseas defense-in-depth.fmtimport for the rejection error.Verification
Reasoned through the golang-jwt/v4 parse flow: the keyfunc is invoked before signature verification, so rejecting non-HMAC methods there prevents the forged-token path in the PoC (
Authorization: <HS256 token signed with gateway-signing-key>against/me). The sandbox has no Go toolchain and the repo has nogo.mod/test infrastructure, so a compile/run could not be performed; the change uses only documented v4 APIs.Automated fix by Hacktron for finding: https://staging.hacktron.ai/testestesttest/findings/c11cafda-e079-493d-9322-f02803fd88b9