Repository navigation
[TT-14451] Authorise Tyk OAS JWT APIs by claim rules alone - #8937
Conversation
A Tyk OAS JWT API without any policy source (base policy claim, client ID base field, default policies, effective scope-to-policy mapping) now runs in claims-only mode when at least one custom claim rule restricts access: blocking, of type exact_match or contains, with a non-empty allowed value. Such APIs returned 403 before. A claims-only session is stored under a per-API key and limited to that API. It never replaces the session the identity shares across the org's other JWT APIs, and its derivable key opens no other API. Both the new-session and the existing-session path accept it. Also fix the contains rule for numeric and boolean claims, which only compared against the last allowed value. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Keep an API policy-based when a scope claim is configured, even without a scope-to-policy mapping. - Refuse claims-only JWT sessions in every key lookup except the JWT middleware's own, so their derivable key is no credential. - Bound claims-only sessions: the Redis record is deleted at the JWT's exp, or after the API's session lifetime (default one hour) when the JWT has none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR introduces a claims-only mode for Tyk OAS JWT APIs, enabling authorization based solely on custom claim rules without needing an associated policy. This simplifies configurations for users who rely on claim-based authorization. This mode is activated when no other policy sources (like
Files Changed AnalysisThe changes are focused on the gateway's JWT middleware and core authentication logic:
Architecture & Impact Assessment
Flow: Claims-Only JWT AuthenticationsequenceDiagram
participant Client
participant Gateway
participant Redis
Client->>Gateway: Request with JWT
Gateway->>Gateway: JWTMiddleware: Validate JWT signature & claims
Gateway->>Gateway: Detect claimsOnlyMode() = true
Gateway->>Gateway: Generate per-API session ID (SHA256)
Gateway->>Redis: Check for existing session
alt Session Not Found
Redis-->>Gateway: Not found
Gateway->>Gateway: Create new SessionState
Gateway->>Gateway: Add `tyk_jwt_claims_only: true` metadata
Gateway->>Gateway: Restrict AccessRights to current API
Gateway->>Gateway: Set session lifetime based on JWT `exp`
Gateway->>Redis: Store new session
else Session Found
Redis-->>Gateway: Return existing session
Gateway->>Gateway: Verify it's a claims-only session
end
Gateway->>Gateway: Process request
Gateway-->>Client: 200 OK
Scope Discovery & Context ExpansionThe changes are well-contained within the gateway's JWT handling, but the modification to The introduction of the References
Metadata
Powered by Visor from Probelabs Last updated: 2026-11-26T15:45:54.471Z | Triggered by: pr_updated | Commit: 2ef37e7 💡 TIP: You can chat with Visor using |
🎯 Recommended Merge TargetsBased on JIRA ticket TT-14451: JWT Auth with claims based or custom authorisation Fix Version: Tyk 5.17.0
Required:
📋 Workflow
|
✅ Security Check PassedNo security issues found – changes LGTM. ✅ Performance Check PassedNo performance issues found – changes LGTM. ✅ Security Check PassedNo security issues found – changes LGTM. \n\n \n\n✅ Performance Check PassedNo performance issues found – changes LGTM. \n\n✅ Quality Check PassedNo quality issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2026-11-26T15:44:58.754Z | Triggered by: pr_updated | Commit: 2ef37e7 💡 TIP: You can chat with Visor using |
|
|
|
API Changes --- prev.txt 2026-11-26 15:44:23.703810037 +0000
+++ current.txt 2026-11-26 15:44:18.510714151 +0000
@@ -11752,7 +11752,8 @@
func (t *BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string, r *http.Request) (user.SessionState, bool)
CheckSessionAndIdentityForValidKey will check first the Session store for a
valid key, if not found, it will try the Auth Handler, if not found it will
- fail
+ fail. A JWT claims-only session is never valid here: only the JWT middleware
+ may use it, after the token's claims passed validation.
func (t *BaseMiddleware) Config() (interface{}, error)
|
- errcheck: check the type assertion of the claims-only session marker. - revive: the private session lookup does not use the request. - staticcheck QF1008: drop the embedded openapi3.T from the test selectors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
SentinelOne CNS Hardcoded Secret Detector SentinelOne CNS is a cloud-agnostic, agentless CSPM & CWPP solution that continuously detects and prevents vulnerabilities that have the highest probability of being exploited in Azure, AWS, Google Cloud, and Kubernetes. |
|



Description
Adds claims-only mode for Tyk OAS JWT APIs. When every policy field is empty (
basePolicyClaims,defaultPolicies,scopes.claims/claimName, the effective scope-to-policy mapping incl. a Client IdP Registry binding, andclientBaseField) and at least one custom claim rule is blocking, of typeexact_matchorcontains, with a non-empty allowed value, the claim rules alone decide access. Tyk Classic APIs and every policy-based configuration behave as before.JWTMiddleware.claimsOnlyModeruns per request. Arequired-only ornonBlockingrule does not count.generateToken(org, sha256(apiID + "\x00" + identity)). They never share or overwrite theorg + md5(identity)session that policy-based JWT APIs use, and theirAccessRightshold this API only. Both the new-session and the existing-session paths accept them.tyk_jwt_claims_only: truein their metadata, andCheckSessionAndIdentityForValidKeytreats such a session as not found. So the derivable key does not work as an auth token, basic auth, OAuth or HMAC credential, or through a plugin ID extractor, also on multi-auth APIs. The marker travels with the session to other Gateways and MDCB Data Planes.exp. Withoutexpit lives for the API'ssession_lifetime, or 3600 s by default.containsfix: for numeric and boolean claims,customClaimsContainsMatchcompared only against the last allowed value (tier: 1against[1, 2]was rejected). It now returns on the first match.Related Issue
https://tyktech.atlassian.net/browse/TT-14451 (API Designer: TT-18820; Dashboard API tests: TykTechnologies/tyk-analytics, branch
TT-14451-claims-only-jwt)Motivation and Context
Customers using claim-based authorisation had to attach a dummy shared policy to every JWT API. A session with empty
AccessRightsgrants every API, and the shared session key is computable from the org ID and the identity. Making the policy fields optional therefore needed per-API sessions scoped to the API, which must not be usable as credentials.How This Has Been Tested
gateway/mw_jwt_claims_only_test.gocovers AC2–AC8, the scope-claim-name case, the session key refused by other auth methods, the bounded session lifetime and thecontainsfix. They fail on master and pass here. The existing JWT, claim, scope, session, auth, OAuth, HMAC, basic, multi-auth and OpenID suites pass.exp.oas_api_jwt_claims_only_test.py, MongoDB): 8 of 8 pass.Types of changes
Checklist
Upgrade note: Tyk OAS JWT APIs that match the claims-only rule return 403 on older Gateways. After the upgrade they authorise by their claim rules, without being re-saved.
🤖 Generated with Claude Code
Ticket Details
TT-14451
Generated at: 2026-11-26 15:43:08