|
| 1 | +--- |
| 2 | +gem: rack |
| 3 | +cve: 2026-25500 |
| 4 | +ghsa: whrj-4476-wvmp |
| 5 | +url: https://github.com/rack/rack/security/advisories/GHSA-whrj-4476-wvmp |
| 6 | +title: 'Stored XSS in Rack::Directory via javascript: filenames rendered into anchor |
| 7 | + href' |
| 8 | +date: 2026-02-17 |
| 9 | +description: |- |
| 10 | + ## Summary |
| 11 | +
|
| 12 | + `Rack::Directory` generates an HTML directory index where each file entry is rendered as a clickable link. If a file exists on disk whose basename begins with the `javascript:` scheme (e.g. `javascript:alert(1)`), the generated index includes an anchor whose `href` attribute is exactly `javascript:alert(1)`. Clicking this entry executes arbitrary JavaScript in the context of the hosting application. |
| 13 | +
|
| 14 | + This results in a client-side XSS condition in directory listings generated by `Rack::Directory`. |
| 15 | +
|
| 16 | + ## Details |
| 17 | +
|
| 18 | + `Rack::Directory` renders directory entries using an HTML row template similar to: |
| 19 | +
|
| 20 | + ```html |
| 21 | + <a href='%s'>%s</a> |
| 22 | + ``` |
| 23 | +
|
| 24 | + The `%s` placeholder is populated directly with the file’s basename. If the basename begins with `javascript:`, the resulting HTML contains an executable JavaScript URL: |
| 25 | +
|
| 26 | + ```html |
| 27 | + <a href='javascript:alert(1)'>javascript:alert(1)</a> |
| 28 | + ``` |
| 29 | +
|
| 30 | + Because the value is inserted directly into the `href` attribute without scheme validation or normalization, browsers interpret it as a JavaScript URI. When a user clicks the link, the JavaScript executes in the origin of the Rack application. |
| 31 | +
|
| 32 | + ## Impact |
| 33 | +
|
| 34 | + If `Rack::Directory` is used to expose filesystem contents over HTTP, an attacker who can create or upload files within that directory may introduce a malicious filename beginning with `javascript:`. |
| 35 | +
|
| 36 | + When a user visits the directory listing and clicks the entry, arbitrary JavaScript executes in the application's origin. Exploitation requires user interaction (clicking the malicious entry). |
| 37 | +
|
| 38 | + ## Mitigation |
| 39 | +
|
| 40 | + * Update to a patched version of Rack in which `Rack::Directory` prefixes generated anchors with a relative path indicator (e.g. `./filename`). |
| 41 | + * Avoid exposing user-controlled directories via `Rack::Directory`. |
| 42 | + * Apply a strict Content Security Policy (CSP) to reduce impact of potential client-side execution issues. |
| 43 | + * Where feasible, restrict or sanitize uploaded filenames to disallow dangerous URI scheme prefixes. |
| 44 | +cvss_v3: 5.4 |
| 45 | +patched_versions: |
| 46 | + - "~> 2.2.22" |
| 47 | + - "~> 3.1.20" |
| 48 | + - ">= 3.2.5" |
| 49 | +related: |
| 50 | + url: |
| 51 | + - https://github.com/rack/rack/security/advisories/GHSA-whrj-4476-wvmp |
| 52 | + - https://github.com/rack/rack/commit/f2f225f297b99fbee3d9f51255d41f601fc40aff |
| 53 | + - https://github.com/advisories/GHSA-whrj-4476-wvmp |
0 commit comments