Repository navigation
feat(auth)!: require the at+jwt token type - #361
Merged
Merged
Conversation
Accept only OAuth 2.0 access tokens as per RFC 9068, i.e., JWTs whose `typ` header is `at+jwt` or `application/at+jwt` (compared case-insensitively), so that other JWTs of trusted issuers, such as ID tokens, cannot be used as access tokens. Tokens of other types or without `typ` header are rejected with 401 before any request to the identity provider. New options `security.auth.token_types` (accepted `typ` values) and `security.auth.verify_token_type` (opt-out for identity providers that do not set `typ`, with a startup warning as for `verify_audience`). BREAKING CHANGE: tokens without an accepted `typ` header are rejected; set `security.auth.verify_token_type: false` for identity providers that do not set it. Documented in "Migrating to 0.16.0". Closes #338 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reviewer's GuideThis breaking authentication change restricts bearer tokens to configured RFC 9068 Sequence diagram for access-token type validationsequenceDiagram
participant Client
participant FOCA
participant IdentityProvider
Client->>FOCA: validate_token(token)
FOCA->>FOCA: get_unverified_header(token)
alt verify_token_type and typ not accepted
FOCA-->>Client: 401 Unauthorized
FOCA-->>Client: WWW-Authenticate: Bearer error="invalid_token"
else typ accepted or verify_token_type disabled
FOCA->>IdentityProvider: _get_oidc_config(issuer, conf)
IdentityProvider-->>FOCA: Discovery document and public keys
FOCA-->>Client: Validated token claims
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #361 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 1796 1810 +14
=========================================
+ Hits 1796 1810 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Ignore surrounding whitespace in configured token types, so that a padded entry does not silently reject every token; test non-string `typ` headers and mixed-case `application/at+jwt`. Say in the migration notes that apps using LS Login need no changes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Link the 0.16 migration notes from the README and the docs index, add the token types to the example configurations, mention the token type check in the `validate_token` docstring, and note that a generic type such as `JWT` does not tell access tokens apart from ID tokens. Co-Authored-By: Claude Fable 5.1 <[email protected]>
uniqueg
marked this pull request as ready for review
October 21, 2026 23:15
Python 3.10 support was dropped in #360 without a migration note. Co-Authored-By: Claude Fable 5.1 <[email protected]>
sourcery-ai
Bot
dismissed
their stale review
October 21, 2026 23:25
Sourcery withdrew this approval because the latest commits introduced blocking findings.
2 tasks
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
Closes #338
FOCA accepted any signed JWT of a trusted issuer as an access token, including ID tokens. RFC 9068 has resource servers require the
typheaderat+jwt(orapplication/at+jwt) precisely so that other JWTs cannot be used as access tokens; LS Login issues such tokens.security.auth.token_types(default:["at+jwt", "application/at+jwt"]): acceptedtypheader values, compared case-insensitively (media types, RFC 7515 §4.1.9) and ignoring surrounding whitespace in the configured values. Tokens of other types or withouttypare rejected with401andWWW-Authenticate: Bearer error="invalid_token", before any request to the identity provider.security.auth.verify_token_type(default:true): opt-out for identity providers that do not settyp, mirroringverify_audience; a startup warning is logged when disabled, and the config fails validation iftoken_typesis empty or blank while the check is on.security.authoptions, "How tokens are validated", a new "Migrating to 0.16.0" page (breaking change + how to disable; linked from README, docs index and changelog), config template and example configs.Breaking change (
feat(auth)!): tokens without an acceptedtypheader are rejected. Apps using LS Login need no changes; others setverify_token_type: falseor list theirtypintoken_types.Verification
Locally (Python 3.13, MongoDB 7.0 on port 12345):
pytest: 1064 passed (full suite, first commit); auth and config tests re-run after the review fixes (205 passed)coverage report:foca/security/auth.pyandfoca/models/config.pyat 100%ruff check,ruff format --check,mypy: cleanmkdocs build --strict: OKReviews: adversarial and quality review found no high or medium findings; low findings fixed in the follow-up commits (whitespace in configured types, non-string
typtest, README/index links, example configs,validate_tokendocstring,JWT-type caveat), except those below.CI: all checks passed (also after the review fixes); Sourcery approved.
Declined review findings
verify_token_typeas a key in the config template rather than only in a comment: the template mirrors howverify_audienceis presented (comment next toaudience).Open questions
None.
🤖 Generated with Claude Code