Slide 16 of 28
Part 3 · Attack ScenariosSlide 16
Slide 16 · Scenario 3
Link preview. The link is file:///etc/passwd.
OWASP Scenario #3 — URL preview feature with no protocol restriction.
📄 OWASP API Security Top 10 · 2023 · API7 · Scenario 3
SETUP
A collaboration platform API that generates link previews.

A collaboration tool allows users to paste links into messages. The API generates a preview: POST /api/preview { "url": "https://news.example.com/article/123" }. The server fetches the URL, extracts the title, description, and image, and returns them.

The API uses a URL-fetching library that supports http://, https://, and file:// protocols. The developer only intended HTTPS links — but never restricted which protocols are allowed.

The exploit: Attacker sends: POST /api/preview { "url": "file:///etc/passwd" }. The server’s URL-fetching library reads the local file /etc/passwd and returns its contents as the “preview” response. The attacker now has the server’s user list. They follow up with: file:///etc/environment (environment variables), file:///app/.env (application secrets), file:///home/ubuntu/.ssh/id_rsa (SSH private key). Each returns the file contents as a “preview.”
The protocol allowlist fix

The correct fix is a protocol allowlist: only permit https:// URLs (and http:// if specifically required). Block file://, dict://, gopher://, ftp://, and any other protocol the feature doesn’t need. This is one line in most URL-fetching library configurations — but it has to be explicitly set.

← Back The common pattern →