Repository navigation
Split authn Validate into verify, accept and buildPrincipal - #507
Conversation
6ebda8e to
b7fc581
Compare
629f161 to
02a6f0b
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
LGTM. The verify/accept split is clean and reading the clock once is a good fix. Doing audience by hand removes the string-matching on golang-jwt error messages for aud. Heads-up for consumers: refusing cnf by default will reject DPoP- and mTLS-bound access tokens that used to pass. That is the right default since the binding isn't verified, but it should be called out in the release notes for toolhive.
Later patches in this series add TrustSet, which picks the validator of the token's issuer and then runs that validator's signature checks and policy checks with one clock reading of its own. That needs signature checking and policy checking to be separate steps, so split Validate: verify signature, iss, exp/nbf/iat, sub (needs key material) accept audience, typ, cnf (policy over verified claims) buildPrincipal assemble the Principal Validate reads the clock once and passes it to verify (parser clock via WithTimeFunc), so every temporal check uses one instant. accept takes the same instant but does not use it yet; later patches use it for lifetime limits and custom checks. Audience is now checked by hand instead of by golang-jwt, so it can vary per policy and so empty or mistyped values get one uniform ReasonAudience. New default refusals, both with the new ReasonTokenKind, to stop a validly signed token that is not an access token from passing as a bearer token: - a typ on the deny list (ID-JAG, logout, secevent, dpop, token-introspection), unless AcceptedTokenTypes lists it - a cnf claim, unless Config.AllowCNF is set: such a token is bound to a key this package does not verify Behaviour changes (may break existing callers): - typ is checked after the signature (wrong typ with an unknown kid now reports unknown_kid) - typ and AcceptedTokenTypes are no longer whitespace-trimmed - an aud array with an empty element is refused - a mixed-type aud array reports audience - audience is checked after sub and lifetime - a non-string typ is refused - default typ deny list - cnf refusal - whitespace-padded AcceptedTokenTypes entries are configuration errors Co-Authored-By: Claude Opus 5.5 <[email protected]>
b7fc581 to
2564bb7
Compare
|
@rdimitrov #506 was squash-merged, so I rebased this branch onto |
|
Thanks for the review, @rdimitrov. I added a release-note bullet for the |
Summary
Validator.Validateintoverify(signature,iss,exp/nbf/iat,sub),accept(audience,typ,cnf) andbuildPrincipal. A later PR in this stack addsTrustSet, which picks the validator of the token's issuer and runs both steps with one clock reading of its own.Validatereads the clock once; every temporal check uses that instant.ReasonAudience.ReasonTokenKind: atypon the deny list (ID-JAG, logout, secevent, DPoP, token introspection) unlessAcceptedTokenTypeslists it, and acnfclaim unlessConfig.AllowCNFis set.Behaviour changes (may break existing callers)
typis checked after the signature;typandAcceptedTokenTypesare no longer trimmed, and padded entries are configuration errors; a non-stringtypis refused.audarray with an empty element is refused; a mixed-typeaudarray reportsaudience; audience is checked aftersuband lifetime.typdeny list and thecnfrefusal.cnfrefusal rejects DPoP- and mTLS-bound access tokens that used to pass. The binding is not verified here, so refusing is the safe default. Consumers that accept such tokens must setConfig.AllowCNFand verify the binding themselves.Stacked on #506.
Stack: #506 (jose, errors) → #507 (verify/accept) → #508 (checks) → #509 (scopes, algs) → #510 (JWKS close race) → #511 (ProviderOnly) → #514 (TrustSet) → #515 (guards)
Test plan
go vet ./...go test -race ./authn/... ./jose/...🤖 Generated with Claude Code