Skip to content

fix: pin JWT signing algorithm to prevent HS/RS confusion in verifyToken#109

Open
hacktron-app-stg[bot] wants to merge 1 commit into
add-auth-gateway-gofrom
hacktron/fix-c11cafda
Open

fix: pin JWT signing algorithm to prevent HS/RS confusion in verifyToken#109
hacktron-app-stg[bot] wants to merge 1 commit into
add-auth-gateway-gofrom
hacktron/fix-c11cafda

Conversation

@hacktron-app-stg

Copy link
Copy Markdown

Vulnerability

verifyToken in auth_gateway.go used a jwt.Parse keyfunc that returned the HMAC secret without ever validating token.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

  • The keyfunc now type-asserts t.Method to *jwt.SigningMethodHMAC and returns an error for any other method, so a downgraded/swapped alg header is rejected before the secret is ever returned.
  • Added jwt.WithValidMethods([]string{"HS256"}) to jwt.Parse as defense-in-depth.
  • Added fmt import 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 no go.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

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.
@hacktron-app-stg
hacktron-app-stg Bot requested a review from maekuss July 23, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants