Repository navigation
[TT-18034] OAS Allow-List bypass via unstripped path evaluation and parameterized paths - #8810
Conversation
e304112 to
a3b13d6
Compare
🎯 Recommended Merge TargetsBased on JIRA ticket TT-18034: OAS Allow-List bypass via unstripped path evaluation and parameterized paths Fix Version: Tyk 5.13.9Required:
Fix Version: Tyk 5.17.0
Required:
📋 Workflow
|
|
TL;DR: The change addresses the reported issue, and targeted tests confirm the intended behaviour on the head. Merge after the new gateway option is documented. Recommendation: merge after the changes below OAS endpoint matching follows the proxied path unless In the gateway package, 1 more test fails only on the head. It is flaky and unrelated to this change. Checks on this PR
Open points@shults already notes that documentation for the new option is still needed. What I'm asking
Test gaps:
Intended behaviour on the head
Blast radiusIn this repository What we testedTests we ran
MC/DC of the changed decisions: not measured for 2 changed functions and 1 changed file (Test gaps says why). Mutants of the changed decisions: 12 generated: 0 killed, 0 survived, and 12 were not run (skipped). How this was run
|
ef35750 to
308bca2
Compare
📚 Documentation previewThis PR changes generated documentation (component: cc @TykTechnologies/pms — advisory review requested; this does not block merging. Rendered docs diffdiff -ruN out-base/gateway-config.mdx out-head/gateway-config.mdx
--- out-base/gateway-config.mdx 2026-11-26 14:58:46.874173193 +0000
+++ out-head/gateway-config.mdx 2026-11-26 14:58:48.189483331 +0000
@@ -1229,6 +1229,17 @@
Defaults to false, which proxies rewritten paths unchanged.
Enable it only if your APIs rely on the legacy behavior.
+### allow_unsafe_listen_path_matching
+ENV: <b>TYK_GW_ALLOWUNSAFELISTENPATHMATCHING</b><br />
+Type: `bool`<br />
+
+AllowUnsafeListenPathMatching restores the previous behavior, where endpoint
+matching for Tyk OAS APIs also accepted the full request URL including the
+listen path. With strip_listen_path enabled this could approve a request for
+one endpoint and proxy a different, undeclared path upstream.
+Defaults to false, which matches OAS endpoints only against the path that
+is proxied upstream. Tyk Classic APIs are not affected by this setting.
+
### uptime_tests
Tyk nodes can provide uptime awareness, uptime testing and analytics for your underlying APIs uptime and availability.
Tyk can also notify you when a service goes down.
|
|
This PR addresses a security vulnerability (TT-18034) in Tyk OAS APIs where per-endpoint middleware, such as the allow-list, could be bypassed. The issue stemmed from endpoint matching logic that would fall back to using the full request URL (including the listen path). This allowed a request to be approved based on the full path, while a different, undeclared path was proxied to the upstream service. The fix ensures that for OAS APIs, endpoint matching is performed strictly against the path that will be proxied upstream. Additionally, Files Changed Analysis
Architecture & Impact Assessment
Request Flow ComparisonsequenceDiagram
participant Client
participant Gateway
participant Upstream
Note over Client, Gateway: Old Behavior (Vulnerable)
Client->>Gateway: GET /employees/static
Gateway->>Gateway: 1. Match stripped path "/static" (fails)
Gateway->>Gateway: 2. Fallback: Match full path "/employees/static" (succeeds on allow-list)
Gateway->>Upstream: Proxy stripped path "/static" (undeclared path)
Upstream-->>Gateway: 200 OK
Gateway-->>Client: 200 OK (Middleware Bypassed)
Note over Client, Gateway: New Behavior (Fixed, Default)
Client->>Gateway: GET /employees/static
Gateway->>Gateway: 1. Match stripped path "/static" (fails)
Gateway->>Gateway: 2. No fallback for OAS APIs. Match fails.
Gateway-->>Client: 403 Forbidden
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-11-26T15:01:17.435Z | Triggered by: pr_updated | Commit: 9d5053a 💡 TIP: You can chat with Visor using |
|
API Changes --- prev.txt 2026-11-26 14:59:34.366212871 +0000
+++ current.txt 2026-11-26 14:59:28.819107364 +0000
@@ -7943,6 +7943,14 @@
// Enable it only if your APIs rely on the legacy behavior.
ApplyStripListenPathToURLRewrite bool `json:"apply_strip_listen_path_to_url_rewrite"`
+ // AllowUnsafeListenPathMatching restores the previous behavior, where endpoint
+ // matching for Tyk OAS APIs also accepted the full request URL including the
+ // listen path. With strip_listen_path enabled this could approve a request for
+ // one endpoint and proxy a different, undeclared path upstream.
+ // Defaults to false, which matches OAS endpoints only against the path that
+ // is proxied upstream. Tyk Classic APIs are not affected by this setting.
+ AllowUnsafeListenPathMatching bool `json:"allow_unsafe_listen_path_matching"`
+
// Tyk nodes can provide uptime awareness, uptime testing and analytics for your underlying APIs uptime and availability.
// Tyk can also notify you when a service goes down.
UptimeTests UptimeTestsConfig `json:"uptime_tests"` |
✅ Security Check PassedNo security issues found – changes LGTM. ✅ Security Check PassedNo security issues found – changes LGTM. \n\nArchitecture Issues (1)
Performance Issues (1)
✅ Quality Check PassedNo quality issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2026-11-26T14:59:58.104Z | Triggered by: pr_updated | Commit: 9d5053a 💡 TIP: You can chat with Visor using |
|
The option is documented in the doc comment on The Gateway configuration reference in tyk-docs ( |
f6d4983 to
9bd56d2
Compare
…dcard) Block entries keep matching the full URL: narrowing a denial is not safe. Allow-list parameter check reads path item parameters as well. The exact template is matched against the escaped path, so %2F stays inside one value. Mux wildcards in OAS path keys are kept.
|
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
For Tyk OAS APIs, access control grants only the declared operation. Two changes to endpoint matching:
allowandignoreAuthenticationentries additionally require the request to be exactly the declared OAS operation: anchored path template match and, when the operation has novalidateRequest, path parameter values that satisfy the parameter schemas (type,pattern,enum). WithvalidateRequestenabled the parameter check stays with validateRequest, so its configurederrorResponseCodeis unchanged. Block list and all other middleware keep plain regex matching; narrowing a grant is safe, narrowing a denial is not.Changes:
config/config.go,cli/linter/schema.json: new Gateway optionallow_unsafe_listen_path_matching(defaultfalse). Set totrueit restores the previous matching behaviour for OAS APIs. The ticket's AC 5 named itapply_legacy_oas_path_matching; the name was changed after discussion with the ticket owner, as the option only controls whether OAS endpoints may also match with the listen path in place, and it now follows the existingallow_unsafe_*options in the Gateway config.gateway/model_apispec.go(endpointMatcher): the matching mode is a strategy chosen once per API inMakeSpec, from the API type and the Gateway config, and stored onAPISpec. No per-request code consults the flag. Two implementations:legacyEndpointMatcher: the pre-existing matching, moved verbatim. Listen path stripped before matching, regex tried against the path with listen path and version stripped, with the listen path stripped, and against the full URL. Every allow / ignoreAuthentication entry it matches applies. Used by Tyk Classic APIs and by OAS APIs with the flag set.oasEndpointMatcher: no pre-strip, the full URL is never tried. Internal VEM paths used by JSON-RPC / MCP routing (/mcp-tool:,/mcp-resource:,/mcp-prompt:,/json-rpc-method:) are the exception, because they are looping targets without a listen path and the full URL is their only form. An allow / ignoreAuthentication entry applies only ifoasOperationMatchesholds.gateway/model_urlspec.go(oasExactPath): the OAS path template of an allow / ignoreAuthentication entry compiled once at API load, ingenerateRegex, to an anchored regex with one capture group per path parameter. A template that fails to compile is logged at load and never matches.gateway/model_apispec.go(oasOperationMatches,validateRequestEnabled): at request time the stripped path must match the template exactly. If the operation hasvalidateRequestenabled, that is all the allow list checks and validateRequest reports invalid parameters as before. Otherwise the captured parameters must also passpathParamsMatchOperation, the same schema pre-check validateRequest uses for candidate disambiguation (TT-16890). Entries not declared in the OAS document (e.g. internal VEM paths) keep the regex verdict.gateway/model_urlspec.go(URLSpec.matchesPath),gateway/model_apispec.go(getMatchPathAndMethod),gateway/api_definition.go(URLAllowedAndIgnored): delegate to the API's matcher. The pre-strip ingetMatchPathAndMethodis part of the legacy matcher because stripping twice removed a listen path that is also a prefix of the endpoint path (/employees+/employees/{id}), which the full URL fallback used to mask.gateway/mcp_pairing.go: the synthetic MCP adapter spec copies the matcher along with the Gateway config.gateway/mw_oas_listen_path_matching_test.go: the reported scenario with both flag values, exact-operation cases,strip_listen_path: false, ignoreAuthentication, and a test freezing the Tyk Classic behaviour.Tyk Classic APIs and OAS APIs with the flag enabled go through
legacyEndpointMatcher, the old code moved without changes, so the old path cannot drift when the new one is edited. Version stripping is unaffected.Related Issue
https://tyktech.atlassian.net/browse/TT-18034
Motivation and Context
Every per-endpoint middleware (allow list, block list, ignore, validateRequest, mock response, version check) resolves the request through
URLSpec.matchesPath, which tried the request path in three forms: listen path and version stripped, listen path stripped, and the full URL. The third form exists for Classic APIs, where customers declare endpoint paths that include the listen path. OAS path keys are by definition relative to the listen path, so for OAS APIs that form only lets through requests that do not match after stripping.On top of that, endpoint regexes are unanchored unless
enable_path_prefix_matching/enable_path_suffix_matchingare set, and{id}compiles to([^/]+)regardless of the parameter schema. The allow list therefore also accepted undeclared paths that merely contain a declared one, and parameter values that violate the declared type, whenever validateRequest was not enabled on the operation.With the reporter's API (listen path
/employees,strip_listen_path: true, OAS paths/employees/staticand/employees/{id}withid: integer,allowandvalidateRequeston both):GET /employees/employees/static/employees/staticGET /employees/employees/123/employees/123GET /employees/employees/abcGET /employees/static/staticGET /employees/hello_world/hello_worldGET /employees/foo/bar/foo/barGET /employees/anything/employees/static/anything/employees/staticGET /employees/employees/static/extra/employees/static/extraIn the bold rows the allow list approved a path the operation was never declared for, and validateRequest, which evaluates the stripped path, found no operation and skipped validation. With only
allowenabled (no validateRequest),GET /employees/users/abcon/users/{id}(id: integer) was forwarded as well; it is now rejected with 403.Behaviour changes to call out in the release notes (5.13.9 LTS and 5.17.0):
403.validateRequestare rejected by the allow list with403instead of being forwarded. Operations withvalidateRequestkeep answering with its configured code (422by default).ignoreAuthentication: before this PR an unauthenticatedGET /employees/staticmatched the ignored/employees/staticentry and reached upstream/static; it now returns401.allowentries on OAS APIs no longer match by prefix or substring; an operation declared as/usersno longer admits/users/123unless the flag is set.allow_unsafe_listen_path_matching: truerestores all of the previous behaviour.AC 3 of the ticket (
strip_listen_path: false) is not implemented literally. Withstrip: falsethe upstream always receives the listen path while OAS paths stay relative to it, which is the documented OAS semantics rather than a divergence. Matching against the stripped path already satisfies "the path the upstream route represents"; a literal reading would break every OAS API usingstrip: falsewith relative paths. To be confirmed with Product.Out of scope, raised as follow-ups from the code review: middleware matched inside the reverse proxy after
SanitizeProxyPaths(hard timeout, circuit breaker, header transforms, response handlers) strips the listen path twice and never matches when the listen path prefixes the endpoint path, a pre-existing bug; and a per-API override for the global flag.How This Has Been Tested
TestOASAllowList_ListenPathPrefixOfEndpoints: the table above for the default mode, forallow_unsafe_listen_path_matching: true, and forstrip_listen_path: false, asserting both the status and the path received by the test upstream.TestOASAllowList_DeclaredOperationOnly: allow list alone enforces path parameter schemas; paths relative to the listen path;strip_listen_path: falsekeeps the listen path upstream.TestOASIgnoreAuthentication_ListenPathPrefixOfEndpoints: the unauthenticated bypass via ignoreAuthentication is closed.TestClassicAllowList_ListenPathInEndpointPathUnchanged: a Classic API with listen-path-prefixed endpoint paths keeps matching the full URL for both flag values.gatewaysuite withCI=true: passes exceptTestResponseOverride/Python(fails onmaster) andTest_GW_setupLogger_sinks(sensitive to aTYK_LOGLEVELvariable in the local shell; passes in CI).golangci-lintwith.golangci.dev.ymlagainstorigin/master: no issues.The new option is documented in its doc comment in
config/config.go, which is the source of the Gateway configuration reference in tyk-docs.Screenshots (if appropriate)
Types of changes
Checklist
🤖 Generated with Claude Code
Ticket Details
TT-18034
Generated at: 2026-11-26 14:58:29