-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[TT-15359]: Added extra jwt validation #7269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🚀 Performance Snapshot
## Performance Impact AnalysisThis PR adds additional JWT validation capabilities to the Tyk Gateway for OAS APIs. The changes introduce validation for issuer, audience, JWT ID, and subject claims against configured values. These validations are performed during the JWT middleware's request processing flow, which is a critical path for authenticated API requests. The validation is conditionally executed only for OAS APIs and only when the corresponding validation options are configured, which limits the performance impact to specific use cases. ## Critical AreasThe JWT middleware's Each validation involves map lookups, string comparisons, and potentially array iterations when checking against lists of allowed values. The subject validation is particularly noteworthy as it calls ## Optimization Recommendations
## Summary
Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk API Gateway, specifically for APIs defined using the OpenAPI Specification (OAS). The changes introduce validation for four critical JWT claims: issuer (iss), audience (aud), JWT ID (jti), and subject. These validations help prevent token misuse by ensuring tokens contain expected values and required fields, significantly improving the security posture of JWT-protected APIs. ## Identified VulnerabilitiesNo vulnerabilities introduced. On the contrary, this PR addresses potential security weaknesses: High Severity (Mitigated):
Medium Severity (Mitigated):
## Security RecommendationsThe implementation is solid with comprehensive validation and error handling. Recommendations:
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet. ## Summary
Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS-based APIs. The changes introduce four new validation options:
These features are added to the OAS JWT security schema in the ## Required Updates
## Compatibility ConcernsThe changes are backward compatible since:
No breaking changes are introduced to existing APIs or authentication flows. ## Summary & Recommendations
Tip: Mention me again using |
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
2c94688
to
e59d030
Compare
Let's make that PR title a 💯 shall we? 💪 Your PR title and story title look slightly different. Just checking in to know if it was intentional!
Check out this guide to learn more about PR best-practices. |
This PR is too huge for one to review 💔
Consider breaking it down into multiple small PRs. Check out this guide to learn more about PR best-practices. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
API Changes --- prev.txt 2025-08-08 09:38:11.409043474 +0000
+++ current.txt 2025-08-08 09:38:01.769977316 +0000
@@ -3286,6 +3286,13 @@
}
JSVMEvent represents a JavaScript VM event configuration for event handlers.
+type JTIValidation struct {
+ // Enabled indicates whether JWT ID claim is required.
+ // When true, tokens must include a 'jti' claim.
+ Enabled bool `bson:"enabled" json:"enabled"`
+}
+ JTIValidation contains the configuration for the validation of the JWT ID.
+
type JWT struct {
// Enabled activates the basic authentication mode.
//
@@ -3314,6 +3321,10 @@
// Tyk classic API definition: `jwt_identity_base_field`
IdentityBaseField string `bson:"identityBaseField,omitempty" json:"identityBaseField,omitempty"`
+ // SubjectClaims specifies a list of claims that can be used to identity the subject of the JWT.
+ // The field is an OAS only field and is only used in OAS APIs.
+ SubjectClaims []string `bson:"subjectClaims,omitempty" json:"subjectClaims,omitempty"`
+
// SkipKid controls skipping using the `kid` claim from a JWT (default behaviour).
// When this is true, the field configured in IdentityBaseField is checked first.
//
@@ -3326,6 +3337,11 @@
// Tyk classic API definition: `jwt_policy_field_name`
PolicyFieldName string `bson:"policyFieldName,omitempty" json:"policyFieldName,omitempty"`
+ // BasePolicyClaims specifies a list of claims from which the base PolicyID is extracted.
+ // The policy is applied to the session as a base policy.
+ // The field is an OAS only field and is only used in OAS APIs.
+ BasePolicyClaims []string `bson:"basePolicyClaims,omitempty" json:"basePolicyClaims,omitempty"`
+
// ClientBaseField is used when PolicyFieldName is not provided. It will get
// a session key and use the policies from that. The field ensures that requests
// use the same session.
@@ -3356,6 +3372,21 @@
// Tyk classic API definition: `jwt_expires_at_validation_skew`.
ExpiresAtValidationSkew uint64 `bson:"expiresAtValidationSkew,omitempty" json:"expiresAtValidationSkew,omitempty"`
+ // AllowedIssuers contains a list of accepted issuers for JWT validation.
+ // When configured, the JWT's issuer claim must match one of these values.
+ AllowedIssuers []string `bson:"allowedIssuers,omitempty" json:"allowedIssuers,omitempty"`
+
+ // AllowedAudiences contains a list of accepted audiences for JWT validation.
+ // When configured, the JWT's audience claim must match one of these values.
+ AllowedAudiences []string `bson:"allowedAudiences,omitempty" json:"allowedAudiences,omitempty"`
+
+ // JTIValidation contains the configuration for the validation of the JWT ID.
+ JTIValidation JTIValidation `bson:"jtiValidation,omitempty" json:"jtiValidation,omitempty"`
+
+ // AllowedSubjects contains a list of accepted subjects for JWT validation.
+ // When configured, the subject from kid/identityBaseField/sub must match one of these values.
+ AllowedSubjects []string `bson:"allowedSubjects,omitempty" json:"allowedSubjects,omitempty"`
+
// IDPClientIDMappingDisabled prevents Tyk from automatically detecting the use of certain IDPs based on standard claims
// that they include in the JWT: `client_id`, `cid`, `clientId`. Setting this flag to `true` disables the mapping and avoids
// accidentally misidentifying the use of one of these IDPs if one of their standard values is configured in your JWT.
@@ -3580,6 +3611,8 @@
func (s *OAS) Fill(api apidef.APIDefinition)
Fill fills *OAS definition from apidef.APIDefinition.
+func (s *OAS) GetJWTConfiguration() *JWT
+
func (s *OAS) GetTykExtension() *XTykAPIGateway
GetTykExtension returns our OAS schema extension from inside *OAS.
@@ -4167,6 +4200,11 @@
// - For JWT: `scopes.jwt.scope_claim_name`
ClaimName string `bson:"claimName,omitempty" json:"claimName,omitempty"`
+ // Claims contains a list of claims that contains the claim name.
+ // The first match from the list of claims in the token is used.
+ // OAS only field applied to OAS apis.
+ Claims []string `bson:"claims,omitempty" json:"claims,omitempty"`
+
// ScopeToPolicyMapping contains the mappings of scopes to policy IDs.
//
// Tyk classic API definition:
@@ -8507,6 +8545,9 @@
HMACSign = "hmac"
RSASign = "rsa"
ECDSASign = "ecdsa"
+ ISS = "iss"
+ AUD = "aud"
+ JTI = "jti"
)
const (
ErrOAuthAuthorizationFieldMissing = "oauth.auth_field_missing"
@@ -8593,6 +8634,7 @@
var (
ErrNoSuitableUserIDClaimFound = errors.New("no suitable claims for user ID were found")
ErrEmptyUserIDInSubClaim = errors.New("found an empty user ID in sub claim")
+ ErrEmptyUserIDInClaim = errors.New("found an empty user ID in predefined base claim")
)
var (
ErrSyncResourceNotKnown = errors.New("unknown resource to sync") |
Performance Impact Review for PR #7269: Added extra JWT validationOverviewThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS APIs, specifically adding validation for issuer ( Performance AnalysisThe performance impact of these changes is likely to be minimal for most deployments, but could become noticeable in high-volume scenarios with many JWT validations. Key observations:
Optimization Recommendations
ConclusionThe PR adds valuable security features with minimal performance overhead for most use cases. The impact is limited to OAS APIs with specific JWT validation configurations. In high-volume scenarios with many JWT validations, the additional checks could add noticeable overhead, particularly the audience validation with its nested loops. Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS-based APIs. The changes introduce four new validation options:
These validations are implemented in the JWT middleware and only apply to OAS APIs when the corresponding validation options are configured. The changes are backward compatible as they're only activated when explicitly configured. ## Required Updates
## Compatibility ConcernsThe changes are backward compatible since:
No breaking changes are introduced to existing APIs or authentication flows. ## Summary & Recommendations
Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities for OAS-defined APIs in Tyk Gateway. The implementation adds validation for standard JWT registered claims: issuer (iss), audience (aud), JWT ID (jti), and subject validation. These validations are conditionally applied based on configuration and only for OAS APIs, making this a non-breaking change that improves security without disrupting existing setups. ## Identified VulnerabilitiesNo vulnerabilities introduced. On the contrary, this PR addresses potential security weaknesses: High Severity (Mitigated):
Medium Severity (Mitigated):
## Security RecommendationsThe implementation is solid with proper validation and error handling. Some minor recommendations:
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet, particularly the validation of registered claims. ## Summary
Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS-based APIs. The changes introduce four new validation options:
These features are added to the OAS JWT security schema in the ## Required Updates
## Compatibility ConcernsThe changes are backward compatible since:
No breaking changes are introduced to existing APIs or authentication flows. ## Summary & Recommendations
Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk API Gateway for OAS-defined APIs. The implementation introduces validation for four standard JWT claims: issuer (iss), audience (aud), JWT ID (jti), and subject. These validations are conditionally executed based on configuration and only apply to OAS APIs. The code properly handles different claim formats and provides clear error messages. This enhancement significantly improves security by allowing API administrators to enforce stricter token acceptance criteria, which helps prevent token misuse and unauthorized access. ## Identified VulnerabilitiesNo new vulnerabilities introduced. Instead, this PR mitigates several potential security issues: High Severity (Mitigated):
Medium Severity (Mitigated):
Low Severity (Potential):
## Security Recommendations
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet, including proper claim validation and type checking. ## Summary
Tip: Mention me again using |
JWT Core Registered Claims Validation PR AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OpenAPI Specification (OAS) APIs. The implementation adds validation for standard JWT registered claims as defined in RFC 7519:
The implementation includes:
These validations are only applied to OAS APIs and only when the corresponding validation options are configured, making this a non-breaking change. The PR also improves how JWT configuration is retrieved, using This enhancement follows JWT best practices and allows API administrators to implement stricter token acceptance criteria, improving security for JWT-authenticated APIs. Tip: Mention me again using |
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
JWT Claim Validation Enhancement AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for APIs defined using the OpenAPI Specification (OAS). The implementation adds support for validating four standard JWT claims:
The implementation includes:
This is a valuable security enhancement that follows JWT best practices by allowing API administrators to enforce stricter token acceptance criteria. The validation is only applied to OAS-defined APIs and only when the corresponding validation options are configured, ensuring backward compatibility with existing setups. The code is well-structured with proper error handling and logging, making it easy to diagnose validation failures. The test suite covers both positive and negative test cases for each validation type. Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk API Gateway for OAS-defined APIs. The implementation adds validation for four standard JWT registered claims: issuer (iss), audience (aud), JWT ID (jti), and subject validation. These validations are conditionally executed based on configuration and only apply to OAS APIs. The code properly handles different claim formats and provides clear error messages. This enhancement significantly improves security by allowing API administrators to enforce stricter token acceptance criteria. ## Identified VulnerabilitiesNo new vulnerabilities introduced. On the contrary, this PR mitigates several potential security issues: High Severity (Mitigated):
Medium Severity (Mitigated):
Low Severity (Potential):
## Security RecommendationsThe implementation is solid with proper validation and error handling. Some minor recommendations:
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet, including proper claim validation and type checking. ## Summary
Tip: Mention me again using |
🚀 Performance Snapshot
## Performance Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS APIs. The implementation adds validation for four standard JWT claims: issuer (iss), audience (aud), JWT ID (jti), and subject. These validations are performed during the JWT middleware's request processing flow, which is a critical path for authenticated API requests. The validations are conditionally executed only for OAS APIs and only when the corresponding validation options are configured, which limits the performance impact to specific use cases. However, in high-volume scenarios with many JWT validations, the additional checks could add noticeable overhead. ## Critical AreasThe JWT middleware's The audience validation is particularly performance-sensitive as it contains nested loops (iterating through token audiences and allowed audiences), which could be inefficient for large lists of allowed audiences. The subject validation also requires an additional call to ## Optimization Recommendations
## Summary
Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS-based APIs. The changes introduce four new validation options:
These features are added to the OAS JWT security schema in the ## Required Updates
## Compatibility ConcernsThe changes are backward compatible since:
No breaking changes are introduced to existing APIs or authentication flows. ## Summary & Recommendations
Tip: Mention me again using |
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
17d0bb7
to
ef3fb87
Compare
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
Analysis of PR #7269: Added extra JWT validationThis PR enhances the JWT validation capabilities in Tyk Gateway by adding support for validating four standard JWT registered claims as defined in RFC 7519:
Implementation DetailsThe implementation adds:
Key Aspects
This PR is a valuable addition that follows JWT best practices by allowing validation of standard registered claims, enhancing the security posture of JWT-authenticated APIs in Tyk Gateway. Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk API Gateway for OAS-defined APIs. The implementation adds validation for four standard JWT registered claims: issuer (iss), audience (aud), JWT ID (jti), and subject. These validations are conditionally executed based on configuration and only apply to OAS APIs. The code properly handles different claim formats and provides clear error messages. This enhancement significantly improves security by allowing API administrators to enforce stricter token acceptance criteria. ## Identified VulnerabilitiesNo new vulnerabilities introduced. On the contrary, this PR mitigates several potential security issues: High Severity (Mitigated):
Medium Severity (Mitigated):
Low Severity (Potential):
## Security RecommendationsThe implementation is solid with proper validation and error handling. Some minor recommendations:
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet, including proper claim validation and type checking. ## Summary
Tip: Mention me again using |
JWT Core Registered Claims Validation PR ReviewThis PR enhances Tyk Gateway's JWT authentication by adding validation for standard JWT registered claims as defined in RFC 7519. The implementation adds support for validating four key JWT claims:
Implementation DetailsThe PR adds:
Key Strengths
Technical Considerations
Impact on Downstream ProjectsThis PR will require updates to:
ConclusionThis PR is a valuable security enhancement that follows JWT best practices by allowing validation of standard registered claims. The implementation is well-structured with proper error handling and comprehensive test coverage. The changes only affect OAS APIs and are only activated when explicitly configured, ensuring backward compatibility with existing setups. Tip: Mention me again using |
Analysis of PR #7269: Added JWT Core Registered Claims ValidationThis PR enhances JWT authentication in Tyk Gateway by adding validation for standard JWT registered claims as defined in RFC 7519. The implementation adds four new validation capabilities for OAS-defined APIs: Key Changes
Implementation DetailsThe PR adds:
Notable Structural Changes
Security and Performance Considerations
This PR significantly improves security by preventing token misuse and unauthorized access through more comprehensive JWT validation. Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR adds enhanced JWT validation capabilities to the Tyk API Gateway for OAS-defined APIs. The implementation adds validation for four standard JWT registered claims: issuer (iss), audience (aud), JWT ID (jti), and subject validation. These validations are conditionally executed based on configuration and only apply to OAS APIs. The code properly handles different claim formats and provides clear error messages, significantly improving security by allowing API administrators to enforce stricter token acceptance criteria. ## Identified VulnerabilitiesNo new vulnerabilities introduced. On the contrary, this PR mitigates several potential security issues: High Severity (Mitigated):
Medium Severity (Mitigated):
Low Severity (Potential):
## Security RecommendationsThe implementation is solid with proper validation and error handling. Some minor recommendations:
## OWASP ComplianceThis PR strengthens compliance with several OWASP Top 10 categories:
The implementation follows security best practices for JWT validation as recommended by OWASP JWT Cheat Sheet, including proper claim validation and type checking. ## Summary
Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds enhanced JWT validation capabilities to the Tyk Gateway for OAS-based APIs. The implementation adds validation for four standard JWT registered claims:
The PR also changes the ## Required Updates
## Compatibility ConcernsThe JWT validation features are backward compatible since:
However, the change of
## Summary & Recommendations
Tip: Mention me again using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
740db61
to
d0e5ed1
Compare
|
TT-15359
Description
TT-15359
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist