- Notifications
You must be signed in to change notification settings - Fork 1.1k
[TT-15640] feature request auth token enforce token certificate binding #7556
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
base: master
Are you sure you want to change the base?
[TT-15640] feature request auth token enforce token certificate binding #7556
Conversation
🎯 Recommended Merge TargetsBased on JIRA ticket TT-15640: Feature Request: [AuthToken] Enforce Token–Certificate binding Fix Version: Tyk 5.11.0
Required:
📋 Workflow
|
| API Changes --- prev.txt 2025-11-26 10:19:12.414011167 +0000 +++ current.txt 2025-11-26 10:19:02.484038497 +0000 @@ -7157,6 +7157,13 @@ // CertificateExpiryMonitor configures the certificate expiry monitoring and notification feature CertificateExpiryMonitor CertificateExpiryMonitorConfig `json:"certificate_expiry_monitor"` + +// DisableCertificateTokenBinding enables certificate-token binding for static mTLS authentication. +// When enabled, access tokens will be linked (bound) to one or more client certificates during creation or update. +// Any subsequent request with that token must present one of the bound certificates, otherwise the request will be rejected. +// This provides protection against token theft and misuse in mTLS environments. +// Environment variable: TYK_GW_SECURITY_ENABLECERTIFICATETOKENBINDING +DisableCertificateTokenBinding bool `json:"disable_certificate_token_binding"` } type ServiceConfig struct { @@ -8956,11 +8963,13 @@ ErrAuthKeyNotFound = "auth.key_not_found" ErrAuthCertNotFound = "auth.cert_not_found" ErrAuthCertExpired = "auth.cert_expired" +ErrAuthCertMismatch = "auth.cert_mismatch" ErrAuthKeyIsInvalid = "auth.key_is_invalid" -MsgNonExistentKey = "Attempted access with non-existent key." -MsgNonExistentCert = "Attempted access with non-existent cert." -MsgInvalidKey = "Attempted access with invalid key." +MsgNonExistentKey = "Attempted access with non-existent key." +MsgNonExistentCert = "Attempted access with non-existent cert." +MsgCertificateMismatch = "Attempted access with incorrect certificate." +MsgInvalidKey = "Attempted access with invalid key." ) const ( KID = "kid" @@ -14823,6 +14832,7 @@ OauthClientID string `json:"oauth_client_id" msg:"oauth_client_id"` OauthKeys map[string]string `json:"oauth_keys" msg:"oauth_keys"` Certificate string `json:"certificate" msg:"certificate"` +MtlsStaticCertificateBindings []string `json:"mtls_static_certificate_bindings" msg:"mtls_static_certificate_bindings"` BasicAuthData BasicAuthData `json:"basic_auth_data" msg:"basic_auth_data"` JWTData JWTData `json:"jwt_data" msg:"jwt_data"` HMACEnabled bool `json:"hmac_enabled" msg:"hmac_enabled"` |
…e-token-certificate-binding
| This PR introduces Token-Certificate Binding for mTLS, a security feature that cryptographically links an authentication token to a specific client certificate. When enabled, the gateway enforces that any request using a bound token must also present the corresponding client certificate. This mitigates the risk of a compromised token being used without the associated certificate, as requests with a missing or mismatched certificate are rejected. Files Changed AnalysisThe changes are centered around implementing the token-binding logic in the gateway's authentication middleware.
Architecture & Impact Assessment
Request Flow with Certificate BindingsequenceDiagram participant Client participant Tyk Gateway participant CertificateCheckMW participant AuthKeyMW participant SessionStore Client->>Tyk Gateway: Request with mTLS Cert + Auth Token Tyk Gateway->>CertificateCheckMW: Process Request activate CertificateCheckMW CertificateCheckMW->>CertificateCheckMW: 1. Is Cert in static whitelist? alt No (Not in whitelist) CertificateCheckMW->>SessionStore: 2. (New) Get Session for Token SessionStore-->>CertificateCheckMW: Session Data CertificateCheckMW->>CertificateCheckMW: 3. Compare presented Cert with bound Certs in Session alt Match CertificateCheckMW-->>Tyk Gateway: Validation OK else Mismatch deactivate CertificateCheckMW CertificateCheckMW-->>Client: 403 Forbidden (Certificate not allowed) end else Yes (In whitelist) CertificateCheckMW-->>Tyk Gateway: Validation OK end deactivate CertificateCheckMW Tyk Gateway->>AuthKeyMW: Process Request activate AuthKeyMW AuthKeyMW->>SessionStore: 4. Get Session from Token SessionStore-->>AuthKeyMW: Session Data alt Feature Enabled AND Session has Bindings AuthKeyMW->>AuthKeyMW: 5. (New) Compare presented Cert with bound Certs in Session alt Match AuthKeyMW-->>Tyk Gateway: Authentication OK else Mismatch deactivate AuthKeyMW AuthKeyMW-->>Client: 403 Forbidden (Certificate Mismatch) end else Legacy mTLS or No Bindings AuthKeyMW->>AuthKeyMW: Perform legacy validation AuthKeyMW-->>Tyk Gateway: Authentication OK end deactivate AuthKeyMW Tyk Gateway->>Upstream API: Proxy Request Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2025-11-26T10:25:18.060Z | Triggered by: pr_updated | Commit: 6a65caf 💡 TIP: You can chat with Visor using |
Security Issues (4)
Architecture Issues (3)
Performance Issues (1)
Quality Issues (3)
Powered by Visor from Probelabs Last updated: 2025-11-26T10:25:21.472Z | Triggered by: pr_updated | Commit: 6a65caf 💡 TIP: You can chat with Visor using |
andyo-tyk left a comment
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.
Observations and suggestions on docs content
config/config.go Outdated
| // CertificateExpiryMonitor configures the certificate expiry monitoring and notification feature | ||
| CertificateExpiryMonitor CertificateExpiryMonitorConfig `json:"certificate_expiry_monitor"` | ||
| | ||
| // EnableCertificateBinding enables certificate-token binding for static mTLS authentication. |
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.
| // EnableCertificateBinding enables certificate-token binding for static mTLS authentication. | |
| // Used to enable certificate-token binding for static mTLS authentication. |
The configuration name is enable_certificate_token_binding / TYK_GW_SECURITY_ENABLECERTIFICATETOKENBINDING - so should we use plain text rather than concatenating the name (EnableCertificateTokenBinding), given that this is targeting the docs?
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.
it's a required standard for godocs
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.
Why don't we have this for all the other configs that are generated from godocs and appear here? https://tyk.io/docs/tyk-oss-gateway/configuration
| See my comment on tyk-analytics repo. But basically why not to leverage Key metadata with some reserved keywords for this? It will significantly simplify dependencies and overall surface of those changes, including portal (which already writes a bunch of metadata fields now). |
Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com>
Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com>
…e-token-certificate-binding
|



Description
This PR introduces certificate-token binding for static mTLS authentication, providing protection against token theft and misuse in mTLS environments. When enabled via the new Security.EnableCertificateBinding configuration option, access tokens become linked to the client certificate used during authentication, and subsequent requests must present the same certificate or be rejected with a 403 Forbidden error. The implementation adds a new MtlsStaticCertificateBindings field to SessionState to store bound certificate hashes, refactors the AuthKey middleware's certificate validation logic into modular functions that handle both the new binding mode and legacy dynamic mTLS behavior for backward compatibility, and extends CertificateCheckMW to validate certificates against token bindings when they're not in the static whitelist. Comprehensive tests cover success cases with correct certificates, rejection of mismatched or missing certificates, and verification that binding is only enforced when both globally enabled and the session has bindings configured.
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-15640
Generated at: 2025-11-26 10:18:52