TT-17508: Add restriction to absolute paths when base_path is provided#8322
Conversation
…th is set but key is abs path
…orced on file kv resolution level
…ver different responsibilities
🎯 Recommended Merge TargetsBased on JIRA ticket TT-17508: [security] Arbitrary File Read vulnerability in file:// reference Fix Version: Tyk 5.14.0
Required:
📋 Workflow
|
|
This PR addresses a critical security vulnerability (TT-17508) by enforcing that The core of the fix is centralizing all path validation logic into the
This change removes redundant and incomplete validation logic from callers like the URL Rewrite middleware, ensuring the security policy is applied consistently across all features that use the file KV store. Files Changed Analysis
Architecture & Impact Assessment
System Flow Diagramgraph TD
subgraph Callers
A[API Definition Loading]
B[URL Rewrite Middleware]
C[Config Loading]
end
subgraph "Centralized KV Logic (kv_file.go)"
D{ResolveFileKV}
E[resolveKeyPath]
F[confined]
end
subgraph Configuration
G["kv.file.base_path"]
end
A -- "file://key" --> D
B -- "file://key" --> D
C -- "file://key" --> D
G --|Informs policy|--> E
D --|Delegates validation|--> E
E --|Boundary check|--> F
subgraph "Policy Enforcement in resolveKeyPath"
H{"base_path set?"}
I{"Path absolute?"}
J{"Path confined?"}
K[Reject Request]
L["Allow and Read File"]
end
E --> H
H -- No --> K
H -- Yes --> I
I -- Yes --> K
I -- No --> J
J -- No --> K
J -- Yes --> L
Scope Discovery & Context ExpansionThe changes are correctly focused on the file-based KV store implementation in
By fixing the vulnerability at its source, this PR provides a robust and comprehensive solution that protects all current and future uses of the Metadata
Powered by Visor from Probelabs Last updated: 2026-06-18T13:53:41.087Z | Triggered by: pr_updated | Commit: 62bc30c 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. ✅ Architecture Check PassedNo architecture issues found – changes LGTM. Performance Issues (1)
✅ Quality Check PassedNo quality issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2026-06-18T13:53:19.366Z | Triggered by: pr_updated | Commit: 62bc30c 💡 TIP: You can chat with Visor using |
…ction and forcing base_path configuration
… that on this step basePath is not empty
|
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. |
🚨 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. |
|



Description
Ticket: Link
file://KV references are now restricted to relative paths confined within a configuredkv.file.base_path, andbase_pathis required:base_pathnot set →file://references are disabled; every key (absolute orrelative) is rejected and no file contents are read.
base_pathset → only relative keys resolve; they are joined tobase_pathandconfined within it. Absolute paths and
..traversal are rejected.base_pathis the security boundary that pins allfile://lookups to a single directory.Previously it was optional and absolute keys bypassed it entirely, so the boundary wasn't
actually enforced. This change makes it mandatory and authoritative: no
base_path, nofile://; withbase_path, only relative, confined paths are allowed.The
file://KV option is not yet released, so makingbase_pathmandatory carries nobackward-compatibility impact.
Related Issue
https://tyktech.atlassian.net/browse/TT-17508
Motivation and Context
The
file://KV option allowed absolute paths to bypassbase_path. In a multi-tenantsetup, an untrusted API designer could inject
file:///etc/passwdinto an API definition(e.g. a mock body or custom header) and have the gateway read that file and inject its
contents back — arbitrary file disclosure.
The root cause was that
ResolveFileKVtreated absolute keys as an escape hatch and leftboundary enforcement to each caller. One caller (
mw_url_rewrite) did it; two others(
replaceFileSecrets,kvStore) did not — so the boundary was enforced by convention andsilently missed in two places.
The fix moves enforcement into a single chokepoint (
ResolveFileKV) and goes further thanjust rejecting absolute keys: it requires
base_pathto be configured forfile://to workat all. With the policy centralized, all three callers are covered automatically and the
boundary can no longer be silently bypassed.
How This Has Been Tested
Demo
When base_path is not set, the file:// references are restricted; absolute paths are restricted no matter what
Screen.Recording.2026-06-18.at.13.31.09.mov
Types of changes
Checklist