fix: disable token-based auth for dynamic mTLS APIs by default#7671
fix: disable token-based auth for dynamic mTLS APIs by default#7671
Conversation
Add a new gateway-level configuration flag `security.allow_dynamic_mtls_token_auth` (default: false) that controls whether token-based authentication is allowed for APIs using dynamic client mTLS. Previously, APIs with dynamic mTLS enabled would accept authentication via either a client certificate OR a token. The token is constructed from the organization ID and SHA256 hash of the certificate - information that is publicly available. This allowed attackers to bypass mTLS by constructing tokens without possessing the actual private key. With this change: - Default behavior: Token-only authentication is rejected for dynamic mTLS APIs. Clients must present a valid certificate during the TLS handshake. - Legacy behavior: Set `security.allow_dynamic_mtls_token_auth: true` in gateway config to restore the previous behavior of allowing either certificate or token. This is a security enhancement that enforces the principle that mTLS should require possession of the private key, not just knowledge of the certificate hash. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
This PR addresses a security vulnerability by disabling token-based authentication for dynamic mTLS-enabled APIs by default, requiring clients to present a valid certificate instead. Files Changed Analysis
Architecture & Impact Assessment
Request Flow VisualizationsequenceDiagram
participant Client
participant TykGateway as Tyk Gateway
participant Upstream
alt Request with Auth Token only (Default Behavior)
Client->>+TykGateway: Request with Auth Token
Note over TykGateway: API has `use_certificate: true`
Note over TykGateway: `allow_dynamic_mtls_token_auth` is false
TykGateway-->>Client: 403 Forbidden ("Client certificate required")
TykGateway--xUpstream: Request Blocked
end
alt Request with Client Certificate
Client->>+TykGateway: Request with Client Certificate
Note over TykGateway: API has `use_certificate: true`
TykGateway->>TykGateway: Validate Certificate & Authenticate
TykGateway->>+Upstream: Forward Request
Upstream-->>-TykGateway: Response
TykGateway-->>-Client: Response
end
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-01-15T11:15:18.948Z | Triggered by: pr_updated | Commit: 53b84c0 💡 TIP: You can chat with Visor using |
|
API Changes --- prev.txt 2026-01-15 11:14:57.879505110 +0000
+++ current.txt 2026-01-15 11:14:48.110500983 +0000
@@ -7181,6 +7181,14 @@
// CertificateExpiryMonitor configures the certificate expiry monitoring and notification feature
CertificateExpiryMonitor CertificateExpiryMonitorConfig `json:"certificate_expiry_monitor"`
+
+ // AllowDynamicMTLSTokenAuth controls whether token-based authentication is allowed for APIs
+ // using dynamic client mTLS. When set to false (the default), requests to APIs with dynamic
+ // mTLS enabled must present a valid client certificate - token-only authentication will be
+ // rejected. This prevents bypassing mTLS by constructing tokens from publicly available
+ // certificate information. Set to true to restore the legacy behavior of allowing either
+ // certificate or token authentication.
+ AllowDynamicMTLSTokenAuth bool `json:"allow_dynamic_mtls_token_auth"`
}
type ServiceConfig struct {
@@ -8981,10 +8989,12 @@
ErrAuthCertNotFound = "auth.cert_not_found"
ErrAuthCertExpired = "auth.cert_expired"
ErrAuthKeyIsInvalid = "auth.key_is_invalid"
+ ErrAuthCertRequired = "auth.cert_required"
- 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."
+ MsgInvalidKey = "Attempted access with invalid key."
+ MsgCertificateRequired = "Client certificate required for this API."
)
const (
KID = "kid" |
Security Issues (1)
Architecture Issues (1)
✅ Performance Check PassedNo performance issues found – changes LGTM. Quality Issues (1)
Powered by Visor from Probelabs Last updated: 2026-01-15T11:15:24.124Z | Triggered by: pr_updated | Commit: 53b84c0 💡 TIP: You can chat with Visor using |
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
Summary
security.allow_dynamic_mtls_token_auth(default: false)Problem
APIs with dynamic mTLS (use_certificate=true) could be accessed by constructing authentication tokens from:
This allowed attackers to bypass mTLS by constructing valid tokens without possessing the actual private key.
Solution
By default, the gateway now requires a valid client certificate to be presented during the TLS handshake for dynamic mTLS APIs. Token-only authentication is rejected.
For backward compatibility, operators can set
security.allow_dynamic_mtls_token_auth: trueto restore the legacy behavior.Test plan
🤖 Generated with Claude Code