/

CVE-2026-34785

Severity:

HIGH RISK

(7.5)

Improper Input Validation / Path Matching in Rack::Static

CVE-2026-34785

Modified

Vulnerability type

Category:

Improper Input Validation / Path Matching

CWE:

CWE-187, CWE-200, CWE-552

Impact:

Information Disclosure via Unintended Static File Exposure

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Rack::Static uses a simple string prefix check to decide which requests should be handled as static assets, causing it to match any path that merely starts with a configured prefix like "/css".

When sensitive files under the static root share that prefix in their filenames (e.g., "css-config.env"), they may be served unintentionally, leading to information disclosure under certain configurations.

Affected context

This vulnerability affects Ruby applications that:

  • Use Rack as their web server interface, and
  • Configure Rack::Static with short, generic URL prefixes such as "/css", "/js", or "/img", and
  • Store additional files under the static root whose names begin with these prefixes but are not meant to be publicly accessible (for example, backups, configuration, or environment files).

The issue manifests when the static middleware is allowed to serve any file under the static root based solely on the URL path starting with the configured prefix, without verifying intended file types or exact path boundaries.

Exploit preconditions

  • Attack surface: Public HTTP endpoints served through Rack with Rack::Static enabled.
  • Required access: Network access to the affected application's HTTP interface (no authentication is inherently required by the flaw itself).
  • Trigger point: An HTTP request crafted so the path starts with a configured static prefix (e.g., /css-confidential.env, /js-backup.sql) that maps to an unintended file under the static root.
  • Why exploitation is possible: Rack::Static relies on a naive string prefix comparison (e.g., path.start_with?(prefix)) rather than matching complete path segments or validated asset patterns. As a result, any file whose name begins with the prefix may be considered a valid static asset, even if it was never meant to be exposed.

Why this happens

The underlying issue is an improper input validation and inadequate path matching strategy in Rack::Static. Instead of enforcing a boundary-aware match (e.g., requiring /css/ followed by a file path within a known asset directory), the middleware uses a simple prefix check on the request path.

This behavior aligns with CWE-187: Partial String Comparison, where logic based on incomplete or naive string checks leads to incorrect security decisions. When combined with the presence of sensitive files residing under the static root and sharing the same starting prefix, the result is CWE-200: Information Exposure, because these non-asset files can be unintentionally served to clients.

Conceptually, the bug can be summarized as:

  • Treating "starts with this prefix" as equivalent to "is within this safe static namespace".
  • Not constraining exposure by file extension, directory level, or explicit asset allowlists.

Potential impact

  • Exposure of configuration files (e.g., .env, .yml, .json) that happen to share a static prefix in their filename.
  • Disclosure of backup or snapshot data stored under the static root (e.g., SQL dumps, old asset bundles, or log files).
  • Leakage of credentials, API keys, or secrets embedded in inadvertently exposed configuration or environment files.
  • Disclosure of application internals or deployment metadata that may aid further attacks such as lateral movement, credential stuffing, or privilege escalation.

General mitigation guidance

Effective mitigation focuses on tightening how static assets are matched and restricting what can be served:

  • Prefer path-segment-aware matching instead of simple string prefixes, ensuring that configured prefixes represent directories (e.g., /css/) and that only files within those directories are considered for serving.
  • Use explicit allowlists for static content (e.g., only specific directories and file extensions) rather than relying solely on loosely defined prefixes.
  • Separate public static assets from non-public files at the filesystem level:
  • Store sensitive files (backups, configuration, environment files) outside the static root directories.
  • Adopt a convention that no secrets or configuration data reside anywhere under directories that might be used as static roots.
  • Apply defense in depth at the web server or reverse proxy layer:
  • Configure the front-end server to deny access to known sensitive patterns (e.g., *.env, *.sql, *.bak, config*) in static directories.
  • Default application templates and documentation to secure-by-default static layouts, where only a minimal, clearly defined set of paths are exposed to the internet.

How teams detect issues like this

Organizations can discover and monitor this class of issue through a combination of configuration review, static analysis, and dynamic testing:

  • Configuration review:
  • Examine Rack middleware configuration for Rack::Static instances using overly generic prefixes (e.g., /css, /js, /img) without trailing slashes or clear directory boundaries.
  • Inspect static root directories for files that share these prefixes but are not intended for public access (backup, config, or environment files).
  • Static analysis and code scanning:
  • Define rules or custom linters that flag use of static-serving middleware configured with ambiguous or prefix-only matches.
  • Integrate checks into CI pipelines to prevent deployments when new static prefixes or roots include directories that also hold configuration or secret material.
  • Dynamic and black-box testing:
  • Use HTTP scanners or automated tests to probe static prefixes with suffix variations (e.g., /css-config.env, /js-backup.sql) and observe whether non-intended files are returned.
  • Implement security tests in QA that validate static exposure boundaries, ensuring only known asset files are accessible.
  • Runtime monitoring:
  • Analyze access logs for unusual requests under static prefixes that target extensions associated with secrets or backups (e.g., .env, .sql, .log, .bak).

Sources

SourceLink
github.comgithub.com/rack/rack/security/advisories/GHSA-h2jq-g4cq-5ppq
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-34785
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2454486
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-34785.json

Frequently asked

questions

Yes. If an application exposes Rack::Static to the internet and the static root contains unintended files whose names begin with configured prefixes, an external attacker with network access can request those paths and potentially retrieve sensitive content.

Not inherently. The vulnerability stems from how static paths are matched, which typically occurs before any application-level authentication logic. If the impacted static endpoints are publicly reachable, no credentials or special privileges are required.

The most robust pattern is to adopt strict, boundary-aware static routing combined with filesystem separation:

  • Restrict static serving to well-defined asset directories.
  • Use exact path segment matches or explicit asset patterns rather than simple prefixes.
  • Ensure sensitive files are never placed within directories that are configured as static roots.

Developers can:

  • Treat static-serving middleware as a security-sensitive component and review its configuration with the same rigor as authentication or access control.
  • Design deployment layouts so that secrets, backups, and configuration files are physically separate from public asset directories.
  • Introduce automated checks in CI/CD pipelines to detect risky static root configurations and to block changes that introduce generic prefixes or mix sensitive files with static assets.
Find out what's already
exploitable in your codebase.