Rack: `Rack::Directory` lists directories outside the root when `..` follows a symbolic linkGHSA-mhj6-xc86-54m8
MEDIUMFix: rack/rack@42af7a7GHSA-mhj6-xc86-54m8 is a medium-severity (CVSS 5.3) Path Traversal vulnerability in rack. A fix is available for rack — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- CISA assesses this as automatable — exploitation doesn’t require manual, per-target effort, which raises the odds of mass scanning and opportunistic attacks.
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-mhj6-xc86-54m8.
Real-World Exposure
rack💎rack💎rackReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects RubyGems packages — download data is not available via public APIs for these ecosystems.
Description
Summary
Rack::Directory#get decides whether a request path containing .. stays inside the root by expanding it lexically with File.expand_path, but then joins the original, unnormalized path onto the root and passes it to File.stat and Dir.foreach. The operating system resolves a symbolic link before applying a .. that follows it, so when a directory under the root is a symlink, a request such as /system/../ passes the check while the filesystem lists the parent of the link's target, and /system/../config/ lists a sibling of the target. Both are outside the root. This results in disclosure of file and directory names, sizes and modification times outside the served tree.
Details
The check and the filesystem access use different paths:
def get(env)
path_info = Utils.unescape_path(env[PATH_INFO])
if client_error_response = check_bad_request(path_info) || check_forbidden(path_info)
client_error_response
else
path = ::File.join(@root, path_info) # unnormalized
list_path(env, path, path_info, script_name) # File.stat, Dir.foreach
end
end
def check_forbidden(path_info)
return unless path_info.include? ".."
expanded_path = ::File.expand_path(::File.join(@root, path_info)) # lexical
return if expanded_path == @root || expanded_path.start_with?(@root_with_separator)
# 403
end
With public/system linked to shared/system, File.expand_path("public/system/../") is public, so the request is allowed, but Dir.foreach("public/system/../") is evaluated by the kernel as shared/system/.., which is shared. The climb is bounded to one level above each symlink target, but any further symlink discovered in a listing can be used to climb again. Percent-encoded forms such as %2E%2E behave the same way. The Rack::Files application that Rack::Directory delegates to for files normalizes the path with Utils.clean_path_info before touching the filesystem, so file contents outside the root are not readable through this path; only directory listings leak.
Rack::Directory documents that it follows symbolic links, meaning that the link's target is served. This issue goes further: the target's parent and siblings become browsable.
All supported versions since 2.2.0 are affected. Earlier versions rejected every path containing ...
Impact
Applications that mount Rack::Directory, directly or through rackup with a directory application, with any symbolic link to a directory under the root. The Capistrano convention of linking public/system, public/uploads or public/assets into a release-independent shared/ directory is the common case, and shared/ typically also holds config/database.yml, config/master.key, logs and PID files. An unauthenticated attacker obtains the names, sizes and modification times of those entries, and can walk further through any other symlinks found. No authentication, malformed HTTP, or large payload is required. File contents are not disclosed.
Mitigation
- Update to a patched version of Rack, in which
Rack::Directorynormalizes the request path withUtils.clean_path_infobefore accessing the filesystem, asRack::Filesalready does. - Avoid symbolic links to directories under a root served by
Rack::Directory, or avoid exposingRack::Directoryto untrusted clients. - At a reverse proxy, reject request paths containing
..or%2E%2Esegments.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 💎RubyGems | rack | ≥ 2.2.0&&< 2.2.26 | 2.2.26bundle update rack --conservative |
| 💎RubyGems | rack | ≥ 3.0.0&&< 3.1.24 | 3.1.24bundle update rack --conservative |
| 💎RubyGems | rack | ≥ 3.2.0&&< 3.2.9 | 3.2.9bundle update rack --conservative |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for rack, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update rack to 2.2.26 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-mhj6-xc86-54m8 is resolved across your whole dependency graph.
Workarounds
Resolve every user-supplied path to its canonical form and reject anything that escapes the intended directory, and run the component under an account that has no read or write access outside the directory it legitimately serves.
Frequently Asked Questions
Is GHSA-mhj6-xc86-54m8 in your dependencies?
Find it across RubyGems, including transitive dependencies.