Skip to content

Split authn Validate into verify, accept and buildPrincipal - #507

Merged
jhrozek merged 1 commit into
mainfrom
ts-02-wp2-verify-accept
Nov 21, 2026
Merged

jhrozek merged 1 commit into
mainfrom
ts-02-wp2-verify-accept

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Split Validator.Validate into verify (signature, iss, exp/nbf/iat, sub), accept (audience, typ, cnf) and buildPrincipal. A later PR in this stack adds TrustSet, which picks the validator of the token's issuer and runs both steps with one clock reading of its own.
  • Validate reads the clock once; every temporal check uses that instant.
  • Audience is checked by hand rather than by golang-jwt, so empty or mistyped values all get ReasonAudience.
  • New default refusals with ReasonTokenKind: a typ on the deny list (ID-JAG, logout, secevent, DPoP, token introspection) unless AcceptedTokenTypes lists it, and a cnf claim unless Config.AllowCNF is set.

Behaviour changes (may break existing callers)

  • typ is checked after the signature; typ and AcceptedTokenTypes are no longer trimmed, and padded entries are configuration errors; a non-string typ is refused.
  • An aud array with an empty element is refused; a mixed-type aud array reports audience; audience is checked after sub and lifetime.
  • The default typ deny list and the cnf refusal.
  • Release-note item for toolhive: the cnf refusal 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 set Config.AllowCNF and 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

rdimitrov
rdimitrov previously approved these changes Nov 19, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from ts-01-wp2-jose-errors to main November 19, 2026 15:38
@jhrozek
jhrozek dismissed rdimitrov’s stale review November 19, 2026 15:38

The base branch was changed.

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]>
@jhrozek
jhrozek force-pushed the ts-02-wp2-verify-accept branch from b7fc581 to 2564bb7 Compare November 19, 2026 15:46
@jhrozek

jhrozek commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@rdimitrov #506 was squash-merged, so I rebased this branch onto main and dropped the old #506 commit. The diff is unchanged and go test -race ./authn/... passes. The push dismissed your approval, so could you re-approve when you get a chance?

@jhrozek

jhrozek commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @rdimitrov. I added a release-note bullet for the cnf default to the PR description. It says that DPoP- and mTLS-bound tokens which used to pass are now refused, and that consumers must set Config.AllowCNF and verify the binding themselves. I'll carry it into the toolhive release notes. The review shows as dismissed, so please re-approve when you get a chance.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving: the code is unchanged since my last review (the dismissal came from the rebase onto main after #506 merged), and the release-note item for the cnf default covers my earlier point. Thanks!

@jhrozek
jhrozek merged commit 9eb5f94 into main Nov 21, 2026
6 checks passed
@jhrozek
jhrozek deleted the ts-02-wp2-verify-accept branch November 21, 2026 16:29
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.

2 participants