Skip to content

[TT-18034] OAS Allow-List bypass via unstripped path evaluation and parameterized paths - #8810

Open
shults wants to merge 7 commits into
masterfrom
TT-18034-oas-allow-list-bypass-via-unstripped-path-evaluation-and-parameterized-paths
Open

shults wants to merge 7 commits into
masterfrom
TT-18034-oas-allow-list-bypass-via-unstripped-path-evaluation-and-parameterized-paths

Conversation

@shults

@shults shults commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

For Tyk OAS APIs, access control grants only the declared operation. Two changes to endpoint matching:

  1. Endpoint matching no longer falls back to the full request URL that still contains the listen path. Endpoints are matched against the path with the listen path stripped, i.e. the path that is proxied upstream, so what the allow list approves is what the backend receives.
  2. allow and ignoreAuthentication entries additionally require the request to be exactly the declared OAS operation: anchored path template match and, when the operation has no validateRequest, path parameter values that satisfy the parameter schemas (type, pattern, enum). With validateRequest enabled the parameter check stays with validateRequest, so its configured errorResponseCode is 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 option allow_unsafe_listen_path_matching (default false). Set to true it restores the previous matching behaviour for OAS APIs. The ticket's AC 5 named it apply_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 existing allow_unsafe_* options in the Gateway config.
  • gateway/model_apispec.go (endpointMatcher): the matching mode is a strategy chosen once per API in MakeSpec, from the API type and the Gateway config, and stored on APISpec. 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 if oasOperationMatches holds.
  • gateway/model_urlspec.go (oasExactPath): the OAS path template of an allow / ignoreAuthentication entry compiled once at API load, in generateRegex, 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 has validateRequest enabled, that is all the allow list checks and validateRequest reports invalid parameters as before. Otherwise the captured parameters must also pass pathParamsMatchOperation, 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 in getMatchPathAndMethod is 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_matching are 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/static and /employees/{id} with id: integer, allow and validateRequest on both):

Request Before After
GET /employees/employees/static 200, upstream gets /employees/static same
GET /employees/employees/123 200, upstream gets /employees/123 same
GET /employees/employees/abc 422 (validateRequest) same
GET /employees/static 200, upstream gets /static 403
GET /employees/hello_world 200, upstream gets /hello_world 403
GET /employees/foo/bar 200, upstream gets /foo/bar 403
GET /employees/anything/employees/static 200, upstream gets /anything/employees/static 403
GET /employees/employees/static/extra 200, upstream gets /employees/static/extra 403

In 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 allow enabled (no validateRequest), GET /employees/users/abc on /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):

  • OAS APIs that declare paths with the listen path repeated inside the path key, and whose clients send requests without the repeated prefix, start receiving 403.
  • Invalid path parameter values on an allow-listed operation without validateRequest are rejected by the allow list with 403 instead of being forwarded. Operations with validateRequest keep answering with its configured code (422 by default).
  • The removed fallback also served ignoreAuthentication: before this PR an unauthenticated GET /employees/static matched the ignored /employees/static entry and reached upstream /static; it now returns 401.
  • allow entries on OAS APIs no longer match by prefix or substring; an operation declared as /users no longer admits /users/123 unless the flag is set.

allow_unsafe_listen_path_matching: true restores all of the previous behaviour.

AC 3 of the ticket (strip_listen_path: false) is not implemented literally. With strip: false the 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 using strip: false with 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, for allow_unsafe_listen_path_matching: true, and for strip_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: false keeps 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.
  • The reviewer's independent proving tests (F1, F2, B1, B2, G1, G2) pass on this head.
  • Full gateway suite with CI=true: passes except TestResponseOverride/Python (fails on master) and Test_GW_setupLogger_sinks (sensitive to a TYK_LOGLEVEL variable in the local shell; passes in CI).
  • golangci-lint with .golangci.dev.yml against origin/master: no issues.
  • Manual check on a local Gateway with the reporter's API definition against a local httpbin, before and after the fix, with and without the flag.

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

🤖 Generated with Claude Code

Ticket Details

TT-18034
Status In Dev
Summary OAS Allow-List bypass via unstripped path evaluation and parameterized paths

Generated at: 2026-11-26 14:58:29

@shults
shults force-pushed the TT-18034-oas-allow-list-bypass-via-unstripped-path-evaluation-and-parameterized-paths branch from e304112 to a3b13d6 Compare October 19, 2026 13:46
dawidgoracl
dawidgoracl previously approved these changes Oct 20, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Recommended Merge Targets

Based on JIRA ticket TT-18034: OAS Allow-List bypass via unstripped path evaluation and parameterized paths

Fix Version: Tyk 5.13.9

Required:

  • release-5.13 - Minor version branch for 5.13.x patches - required for creating Tyk 5.13.9
  • master - Main development branch - ensures fix is in all future releases

Fix Version: Tyk 5.17.0

⚠️ Warning: Expected release branches not found in repository

Required:

  • master - No matching release branches found. Fix will be included in future releases.

📋 Workflow

  1. Merge this PR to master first

  2. Cherry-pick to release branches by commenting on the merged PR:

    • /release to release-5.13
  3. Automated backport - The bot will automatically create backport PRs to the specified release branches

MaciekMis
MaciekMis previously approved these changes Oct 27, 2026
@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@buger

buger commented Nov 19, 2026

Copy link
Copy Markdown
Member

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 allow_unsafe_listen_path_matching is enabled. Classic APIs keep the previous match. Internal protocol loop targets still match on their full path. The option is AllowUnsafeListenPathMatching in the gateway config and the linter schema, and it is absent from the example config.

In the gateway package, 1 more test fails only on the head. It is flaky and unrelated to this change.

Checks on this PR

drift / drift-check fails, unrelated to this change. The workflow file is generated and only calls the shared job. This diff leaves that workflow untouched. The job log was unavailable here. Unit Tests and Linting on this head passed.

s1_scanner / s1-shift-left-cli fails, unrelated to this change. The check is advisory. The pull request thread's scanner comment reports the code is safe.

sonar-cloud-analysis fails, unrelated to this change. The check is advisory. SonarCloud Code Analysis on this head passed.

Open points

@shults already notes that documentation for the new option is still needed.

What I'm asking

  • @shults: document allow_unsafe_listen_path_matching: the default, what enabling it restores, and that Classic APIs are not affected.

Test gaps:

  • MC/DC was not measured for 2 changed functions: the package's test run could not be instrumented.
  • MC/DC was not measured for 1 changed file: the measurement is not set up for this code yet.
  • 10 changed-decision mutants were not run: the package's tests already fail without the mutation.
  • 2 changed-decision mutants were not run: the two guards cannot be swapped without changing what the second one reads.
Intended behaviour on the head
  • 11 targeted cases confirm the intended behaviour on the head: all pass.
Blast radius

In this repository

What we tested

Tests we ran

  • Further tests (./gateway, base 2a25d1a169ad): 1319 passed, 7 failed, 21 skipped.
  • Selected tests (./gateway, head ef3575012904): 2 passed, 0 failed, 0 skipped.
  • Further tests (./gateway, head ef3575012904): 1320 passed, 8 failed, 21 skipped.

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
  • Trees: base 2a25d1a169ad, head ef3575012904.
  • Tests: 2641 passed, 15 failed, 42 skipped in 3 runs.

@shults
shults force-pushed the TT-18034-oas-allow-list-bypass-via-unstripped-path-evaluation-and-parameterized-paths branch from ef35750 to 308bca2 Compare November 19, 2026 18:14
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📚 Documentation preview

This PR changes generated documentation (component: gateway).

cc @TykTechnologies/pms — advisory review requested; this does not block merging.

Rendered docs diff
diff -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.

@probelabs

probelabs Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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, allow and ignoreAuthentication entries now require an exact match to the declared OAS operation, including path parameter schemas. A new configuration option, allow_unsafe_listen_path_matching, has been introduced (defaulting to false) to provide backward compatibility. The behavior for Tyk Classic APIs remains unchanged, which is confirmed by new tests.

Files Changed Analysis

  • config/config.go & cli/linter/schema.json: Introduce the new gateway configuration option allow_unsafe_listen_path_matching and add it to the linter's schema. This flag allows users to revert to the old, less secure matching behavior if needed.
  • gateway/model_apispec.go: Introduces an endpointMatcher interface with legacyEndpointMatcher and oasEndpointMatcher implementations. This provides a clean architectural separation between the matching logic for Tyk Classic and OAS APIs, with the latter enforcing the new, stricter rules.
  • gateway/model_urlspec.go: The previous matchesPath logic is refactored to use the new endpointMatcher. It also adds oasExactPath logic to compile OAS path templates into anchored regexes for precise matching on allow/ignore lists.
  • gateway/api_definition.go: Integrates the endpointMatcher selection during API loading and prepares the oasExactPath matcher for relevant endpoints.
  • gateway/mw_oas_listen_path_matching_test.go: A new, comprehensive test file is added to validate the fix, confirm the new flag works as expected, and ensure there are no regressions for Tyk Classic APIs.
  • Other test files: Numerous test files are updated to initialize the new endpointMatcher field in APISpec to maintain existing test behavior.

Architecture & Impact Assessment

  • What this PR accomplishes: It patches a security vulnerability that allowed for the bypass of per-endpoint middleware (e.g., allow-list, validation) on Tyk OAS APIs.
  • Key technical changes introduced:
    1. An endpointMatcher strategy pattern is introduced to differentiate between OAS and Classic API path matching.
    2. Endpoint matching for OAS APIs is made stricter by default, no longer falling back to using the unstripped request path.
    3. allow and ignoreAuthentication entries for OAS APIs now require an exact path match and validation of path parameter schemas.
    4. A new configuration flag, allow_unsafe_listen_path_matching, is added for backward compatibility.
  • Affected system components: The primary impact is on the Gateway's request routing and middleware execution pipeline for all OAS-defined APIs that use strip_listen_path. Tyk Classic APIs are not impacted.

Request Flow Comparison

sequenceDiagram
    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
Loading

Scope Discovery & Context Expansion

  • The vulnerability and its fix impact all per-endpoint middleware for OAS APIs, not just the allow-list. This includes request validation, mock responses, and authentication checks, as they all rely on the same endpoint resolution logic.
  • The changes are carefully scoped to affect only OAS APIs by checking api.IsOAS. This prevents regressions in Tyk Classic APIs, a fact explicitly verified by the new TestClassicAllowList_ListenPathInEndpointPathUnchanged test.
  • The introduction of the allow_unsafe_listen_path_matching flag demonstrates consideration for the operational impact of this breaking change, providing a necessary safety valve for users who might have been unintentionally relying on the flawed behavior.
Metadata
  • Review Effort: 3 / 5
  • Primary Label: bug

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 /visor ask <your question>

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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"`

@probelabs

probelabs Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Security Check Passed

No security issues found – changes LGTM.

\n\n

Architecture Issues (1)

Severity Location Issue
🟡 Warning gateway/model_apispec.go:490-506
The `matchesPath` methods for `legacyEndpointMatcher` and `oasEndpointMatcher` contain duplicated logic. The initial path stripping and the first two `if` blocks that match against the version-stripped and listen-path-stripped paths are identical in both implementations.
💡 SuggestionTo reduce duplication and improve maintainability, the common path matching logic could be extracted into a shared helper function. This function could be called at the beginning of both `matchesPath` implementations. While the amount of duplication is small and the current implementation is clear, a helper function could centralize the common matching steps.

Performance Issues (1)

Severity Location Issue
🟡 Warning gateway/model_apispec.go:172
The `pathParameters` function is called on the request path within `oasOperationMatches`. This function performs a parameter merge operation involving a slice allocation and a nested loop on every applicable request. This introduces unnecessary CPU and memory overhead in a performance-sensitive code path.
💡 SuggestionThe merged parameters for each OAS operation are static for a given API definition. Pre-compute the merged parameters for all operations when the API definition is loaded (e.g., in `MakeSpec`) and store them in a cache within the `APISpec`. The `oasOperationMatches` function should then retrieve the pre-computed parameter list from the cache instead of recalculating it.

✅ Quality Check Passed

No 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 /visor ask <your question>

@shults

shults commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@buger

The option is documented in the doc comment on AllowUnsafeListenPathMatching in config/config.go: default false, what enabling it restores, and that Classic APIs are unaffected.

The Gateway configuration reference in tyk-docs (snippets/gateway-config.mdx) is generated from these Go comments and synced automatically, the same way apply_strip_listen_path_to_url_rewrite got there. cli/linter/schema.json carries only type and default for every option, so there is nothing to add there. Let me know if you expect the option somewhere else.

@shults
shults force-pushed the TT-18034-oas-allow-list-bypass-via-unstripped-path-evaluation-and-parameterized-paths branch from f6d4983 to 9bd56d2 Compare November 26, 2026 07:26
…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-cnapp-eu1

Copy link
Copy Markdown

SentinelOne CNS Hardcoded Secret Detector
✅ Congratulations, your code is safe

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.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
89.7% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants