Reject unexpected JWT algorithms, and refuse a guessable signing key - #850
Open
yuzi-co wants to merge 1 commit into
Open
Reject unexpected JWT algorithms, and refuse a guessable signing key#850yuzi-co wants to merge 1 commit into
yuzi-co wants to merge 1 commit into
Conversation
yuzi-co
force-pushed
the
security/jwt-hardening
branch
from
August 2, 2026 21:28
5cdf5d4 to
33a7a3c
Compare
Two faults in the session token, either of which forges a session. The parser accepted whatever algorithm the token named. A token presented with alg "none", or signed with HMAC where the server expects its own HMAC secret, was therefore parsed on the attacker's terms. The parser now accepts only the algorithm the server issues and rejects everything else before verification. The signing secret fell back to a compiled-in default when the configured key was missing or unreadable. Every device that hit that path shared one key, so a token minted on any of them was valid on all of them. Reading the key now fails loudly instead: a server that cannot load a secret does not start, rather than starting with one an attacker already knows.
yuzi-co
force-pushed
the
security/jwt-hardening
branch
from
August 13, 2026 17:47
33a7a3c to
dec75ad
Compare
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.
Two faults in the session token, either of which lets an attacker forge a session.
1. The parser accepts whatever algorithm the token names
Nothing pins the expected signing method, so a token is parsed on the terms it declares rather than the terms the server issues. The parser now accepts only the algorithm the server signs with and rejects everything else before verification.
middleware/jwt_alg_test.gopresents tokens with a different algorithm and asserts they are refused.2. The signing secret falls back to a compiled-in default
When the configured key is missing or unreadable, the server used a built-in value and carried on. Every device that took that path shared one signing key, so a token minted on any one of them was valid on all of them — and the key is in the source.
Loading the key now fails loudly. A server that cannot load a secret does not start, instead of starting with one an attacker already has.
config/jwt_test.gocovers the missing, unreadable and valid cases.Note on the second half
This changes a failure into a hard stop at startup, which is a behaviour change. It seemed like the right trade — a device that silently accepts forged sessions is worse than one that refuses to start — but if you would rather it generate and persist a fresh random key instead of exiting, that is a small change and I am happy to make it.
Verified with
go build,go vet,go test, andGOOS=linux GOARCH=riscv64 go build. Tests need-tags novision(#846) to run off-device.Touches
middleware/jwt.go, as does #847, but in a different function — they merge cleanly in either order.