Repository navigation
Add opt-in at+jwt typ for embedded AS access tokens - #6942
Merged
Merged
Conversation
jhrozek
requested review from
ChrisJBurns,
JAORMX,
amirejaz,
rdimitrov and
tgrunnagle
as code owners
October 26, 2026 13:04
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6942 +/- ##
==========================================
- Coverage 80.09% 80.08% -0.02%
==========================================
Files 839 840 +1
Lines 85339 85365 +26
==========================================
+ Hits 68351 68363 +12
- Misses 16983 16997 +14
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
reviewed
Oct 26, 2026
ChrisJBurns
left a comment
Collaborator
There was a problem hiding this comment.
See the inline comments.
ChrisJBurns
previously approved these changes
Oct 26, 2026
The embedded authorization server will optionally type its JWT access tokens as at+jwt (RFC 9068). Add the setting and its validation to the server parameters; the default stays JWT. Co-authored-by: Mecatl <[email protected]>
Add Config.AccessTokenType and runner.WithAccessTokenType so an embedder can type access tokens as at+jwt. The setting is Go-only, like the subject identifier audiences, and defaults to JWT. Co-authored-by: Mecatl <[email protected]>
Wrap fosite's JWT signer so every access token it signs carries the JOSE header typ: at+jwt (RFC 9068). The header is copied first, so the stored session header is never changed. Co-authored-by: Mecatl <[email protected]>
Install the at+jwt signer in the provider when AccessTokenType is at+jwt. Integration tests decode the JOSE header for every grant that issues access tokens, check that a configuration change takes effect at the next refresh, and check that an access token is still refused as a JWT-bearer assertion. Co-authored-by: Mecatl <[email protected]>
Test that the JWT-bearer grant refuses an at+jwt access token as an assertion, and that the pkg/auth token validator, which the vMCP also uses, accepts access tokens typed JWT, at+jwt, or untyped. Co-authored-by: Mecatl <[email protected]>
Describe the opt-in at+jwt access token type in the auth server architecture docs: which tokens it affects, when a change takes effect, how ToolHive's consumers handle it, and the risk of resource servers that only accept typ JWT. Co-authored-by: Mecatl <[email protected]>
Correct the docs on why the server's own access tokens are never JWT-bearer assertions, make the signer's header copy explicit, and drop redundant or non-proving test cases. Co-authored-by: Mecatl <[email protected]>
The access-token signer added in the previous commits set typ at+jwt on every JWT it signed, so any future JWT routed through the same signer, such as an ID-JAG, would be mistyped. The signer now sets at+jwt only when the header has no typ. Access tokens are unchanged because sessions never store a typ. Co-authored-by: Mecatl <[email protected]>
ChrisJBurns
approved these changes
Oct 26, 2026
This was referenced Oct 27, 2026
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.
Summary
RFC 9068 §2.1 says JWT access tokens must carry the JOSE header
typ: at+jwt, and §4 says resource servers must check it. The type is what lets a resource server tell an access token apart from another JWT with the same issuer and audience. Access tokens from the embedded authorization server always carry fosite's defaulttyp: JWT. Two things make this matter now:at+jwt, so sign-in fails.oauth-id-jag+jwt.This adds an opt-in, Go-only setting for the access-token
typ. The default staysJWT.authserver.Config.AccessTokenTypeandrunner.WithAccessTokenTypeaccept""/"JWT"(the default) or"at+jwt". Any other value fails server construction. Following the subject identifier audiences setting (Add opt-in upstream subject identifiers #6908), it is deliberately not a RunConfig field yet, so config files, the CLI and operator CRDs can't set it.at+jwt,createProviderwraps fosite's access-token signer so every JWT access token is signed withtyp: at+jwt. That covers the authorization code (+PKCE), refresh, device code, RFC 8693 token exchange, RFC 7523 JWT-bearer and ID-JAG redemption grants. With the default, the signer is not wrapped, and the code path is the one used today.typstored in the sessionat+jwtaccess token is still refused as a JWT-bearer assertionat+jwtsubject tokenpkg/authtoken validator, which the vMCP also uses, acceptsJWT,at+jwtand notypdocs/arch/11-auth-server-storage.md.Fixes #6941
Type of change
Test plan
task test)task test-e2e)task lint-fix)Targeted
go testruns of every new and changed test, all passing:TestValidateAccessTokenTypeTestNewAuthorizationServerConfig_AccessTokenTypeTestATJWTAccessTokenSigner_GenerateTestConfigValidateAccessTokenTypeTestNewEmbeddedAuthServersubtests andTestWithAccessTokenTypeReplacesValueTestIntegration_AccessTokenTypeTestIntegration_AccessTokenTypeAppliesAtRefreshTestIntegration_AccessTokenAtJWTRefusedAsJWTBearerAssertionTestValidateAssertionType_TypTestTokenValidatorPlus the neighbouring integration tests whose helpers changed.
Mutation check: with the
createProviderwiring disabled, everyat+jwtintegration case fails and the default cases still pass.Changes
pkg/authserver/server/provider.goAccessTokenTypeJWT/AccessTokenTypeATJWT,ValidateAccessTokenType, theAccessTokenTypefield on params and config (normalized toJWT)pkg/authserver/server/access_token_signer.gotyp: at+jwton a copy of the headerpkg/authserver/server_impl.gocreateProviderwhen the setting isat+jwtpkg/authserver/config.goConfig.AccessTokenTypeand its validationpkg/authserver/runner/embeddedauthserver.goWithAccessTokenTypeoptiondocs/arch/11-auth-server-storage.md,docs/arch/README.mdDoes this introduce a user-facing change?
For Go embedders only.
typ: JWT.runner.WithAccessTokenType("at+jwt")(or setsConfig.AccessTokenType) getstyp: at+jwton access tokens from every grant.Deployments through thv, the vMCP or the operator can't set it and see no change.
Special notes for reviewers
typset insession.Newwould therefore keep its old value across refreshes after the setting changes. It would also need all six call sites changed. The wrapper sets the type when the token is signed instead, on a copy of the header, so a stored session is never changed.TestIntegration_AccessTokenTypeAppliesAtRefreshchecks both directions of a change and that the stored session has notyp.at+jwt. A comment increateProvidersays so.JWT. Nimbus JOSE+JWT's default type verifier accepts onlyJWTor notyp. Spring Security'sNimbusJwtDecoderused that default before 6.5, so Java resource servers on those versions rejectat+jwt. 6.5 addedvalidateType, which defaults to off. The setting is Go-only, so thv, vMCP and operator users couldn't opt out of anat+jwtdefault. Planned follow-up: make the setting a RunConfig field, then switch the default with a release note.Config.ValidateandvalidateParamsvalidate the value. This matches howSubjectIdentifierAudiencesis checked, and the second check covers direct callers ofNewAuthorizationServerConfig.typon the consuming side is out of scope, as the issue says.Implementation plan
Approved implementation plan
Plan: optional
typ: at+jwton embedded AS access tokens (#6941)Worktree:
.worktrees/jwt-plus-at, branchjwt-plus-at. One PR. Fixes #6941, part of #6886.Decisions
JWT;at+jwtis opt-inJWTor notyp. A Go-only setting gives thv, vMCP and operator users no way to opt out, so the default must not change.authserver.Config.AccessTokenType+runner.WithAccessTokenTypeWithSubjectIdentifierAudiences(#6908). Stays out of RunConfig, the API schema, the SDK and the CRDs while it settles. Adding a RunConfig field later only adds to the API.typin a wrapper around the access-token signer, not in the sessionstorage/redis.gomarshalRequester). Atypset per session would stay stale across refreshes after the setting changes, and would need all sixsession.Newcall sites.at+jwtJWT,at+jwt. Empty meansJWT. Anything else fails validation.application/at+jwtis not offered: RFC 9068 allows it, but no consumer needs it.typ, so we only add tests.Background (verified)
Token.toJoseHeaderwritestyp: JWTfirst and then lets values from the header map replace it. Atypin the header handed toSigner.Generatetherefore wins.DefaultJWTStrategy.generate(handler/oauth2/strategy_jwt.go:131) is the only caller ofSigner.Generate, and it runs only for access tokens. Refresh tokens and auth codes go through the HMAC strategy. ToolHive registers no OpenID Connect factory, so it issues no ID tokens.deviceflow/handler.go:192)validateAssertionType(tokenexchange/jwt_bearer_handler.go:376) accepts an emptytyp,JWToroauth-id-jag+jwt, so it already refuses anat+jwtaccess token presented as an assertion.pkg/auth/token.go:1136uses golang-jwt v5jwt.Parse, which does not checktyp. The vMCP's incoming auth uses the same validator (pkg/auth/utils.go:73). The token-exchange subject/actor token validator does not checktypeither.Implementation steps
Step 1: Config plumbing
pkg/authserver/server/provider.goAccessTokenTypeJWT = "JWT"andAccessTokenTypeATJWT = "at+jwt".AccessTokenType stringfield toAuthorizationServerParamsand toAuthorizationServerConfig, with doc comments.ValidateAccessTokenType(string) error(empty is OK) and call it fromvalidateParams.NewAuthorizationServerConfigcopies the field, normalizing empty toJWT.pkg/authserver/config.goConfig.AccessTokenTypewith a doc comment (defaultJWT;at+jwtper RFC 9068 §2.1; Go-only).Config.Validate, using the same validator.pkg/authserver/server_impl.gonewServer: mapcfg.AccessTokenTypeintooauthParams.pkg/authserver/runner/embeddedauthserver.goaccessTokenTypetoembeddedAuthServerOptions.WithAccessTokenType(typ string) EmbeddedAuthServerOption. The godoc says:JWTis the defaultConfiginnewEmbeddedAuthServerWithStorage.Step 2: Signer wrapper
pkg/authserver/server/access_token_signer.go, with the SPDX header:NewTypedAccessTokenSigner, or a helperWrapAccessTokenSigner(strategy *oauth2.DefaultJWTStrategy, typ string)) socreateProviderin packageauthservercan use it.Validate,Decodeand the other methods pass straight through to the embedded signer.pkg/authserver/server_impl.gocreateProvider: aftercompose.NewOAuth2JWTStrategy(...), wrap the signer when the setting isat+jwt:at+jwt.Step 3: Tests (all of them decode the JOSE header)
Shared test helper:
jwtHeaderTyp(t, token) string. It splits the token, base64url-decodes the first segment, unmarshals it and returnstyp. It fails the test iftypis missing, unless a variant asserts that it's absent.Unit tests,
pkg/authserver/server/access_token_signer_test.go:typgets set toat+jwt.kidand any other header entries are kept.jwt.Headers.Extrais not changed.Validateon a token from the wrapper succeeds.Config tests in
provider_test.go,config_test.goandrunner/embeddedauthserver_test.go:JWTandat+jwtare valid.at+JWT,application/at+jwtandfooare rejected.Config, and a repeated option replaces the earlier one.Integration tests in
pkg/authserver/integration_test.go. Run the table twice, once with the default and once withat+jwt, and check the headertypfor each grant:at+jwtaccess token, so this also checks that anat+jwtsubject is accepted)The default run expects
JWT, theat+jwtrun expectsat+jwt.Setting changed while sessions exist:
at+jwtand refresh with it.typ: at+jwt.typin its JWT header.Assertion refusal: an access token this AS issued with
at+jwt, presented as ajwt-bearerassertion, getsinvalid_grant. Add a table case to the existingvalidateAssertionTypetests and one integration-level case.Consumers:
pkg/authTokenValidatoraccepts RS256 tokens withtyp: JWT,typ: at+jwtand notyp(a table case next to the existing validator tests).pkg/authtest covers it. Add a vMCP-level test only if one already exercises incoming auth against an AS-issued token cheaply.Step 4: Docs
docs/arch/17-token-exchange-delegation.mdor the auth server part ofdocs/arch/11-auth-server-storage.md, wherever the access-token claims (tsid,sub_id) are already described. It covers:typisJWTby default, orat+jwtwithWithAccessTokenTypeoauth-id-jag+jwtWithAccessTokenTypeandConfig.AccessTokenType(step 1).task docsrun is needed: no CLI or API change.PR
Add opt-in at+jwt typ for embedded AS access tokens.github/pull_request_template.md:Fixes #6941.typ: JWT. After, the same by default; Go embedders that setWithAccessTokenType("at+jwt")gettyp: at+jwtfrom every grant.JWTand the setting stays Go-only, and the Spring/Nimbus research.<details>block.Work breakdown
Steps 1–4 above are split into work items. Small items go to a Haiku worker and large items to a Sonnet worker (go-expert-developer with a
modeloverride). An Opus reviewer checks every result.ValidateAccessTokenType, the fields onAuthorizationServerParams/AuthorizationServerConfig, the call invalidateParams, normalizing empty toJWTinNewAuthorizationServerConfig. Validator table test inprovider_test.go.server/provider.go,server/provider_test.goConfig.AccessTokenType+ validation inConfig.Validate, the mapping innewServer,runner.WithAccessTokenType+ its mapping. Tests inconfig_test.goandrunner/embeddedauthserver_test.go. Copy theWithSubjectIdentifierAudiencesshape from commit 5c8427b.config.go,server_impl.go(newServeronly),runner/embeddedauthserver.go, matching_test.gofilesaccess_token_signer.go) and its unit tests (typset,kidkept, caller header not changed, nil header,Validatepasses). Nothing gets wired in.server/access_token_signer.go,server/access_token_signer_test.gocreateProvider, with the comment about ID-JAG and stale headers. Step 3 integration tests: the sharedjwtHeaderTyphelper; the grant table (auth code+PKCE, refresh, device code, token exchange with anat+jwtsubject token, JWT-bearer, ID-JAG redemption), run once with the default and once withat+jwt; the test where the setting changes between issue and refresh; the integration-level assertion refusal. Needs to learn the existing integration harness.server_impl.go(createProvider),integration_test.govalidateAssertionTypetable case fortyp: at+jwt(refused); apkg/authTokenValidatortable case acceptingJWT,at+jwtand notyp.server/tokenexchange/jwt_bearer_handler_test.go,pkg/auth/token_test.gotsid/sub_idare documented and puts the section next to them.docs/arch/…Order: W1 → W2 → W3 → W4 → W5 → W6. Every worker shares this worktree and commits there. Running them one at a time keeps the index from racing and leaves one commit per item. W5 has no code dependencies, so it could run in its own worktree alongside W2–W4 if speed matters.
Per-item loop
task lint-fixortask testunless told to; report the commands you ran and their output"Co-Authored-By: Claude Opus 5.5trailer and nothing elseFinal pass
main. This catches problems that span items, such as the wrapper being wired in but the default path changing anyway.task lint-fix/task testonly when the user asks.Out of scope
typin ToolHive's consumers.🤖 Generated with Claude Code