A headless browser inside your network is an SSRF risk
A screenshot feature, a link preview and an agent's browser tool all take an address from someone else and open it from a machine of yours. If that machine sits inside your network, the address can point inward. This is server-side request forgery (SSRF), and a browser makes it harder to stop than a plain HTTP client does.
- What the browser can reach
- Why checking the address is not enough
- Defend it yourself
- How Calotype handles it
- What none of this covers
- Sources
What the browser can reach
Anything the machine can reach, and the answer comes back to the attacker as pixels in the screenshot.
- Cloud metadata services. On AWS, Google Cloud and Azure, an instance can read facts about itself from a link-local address. All three document
169.254.169.254. On AWS, what it serves includes the security credentials of the instance's IAM role. AWS also documents the IPv6 addressfd00:ec2::254, and Google the namemetadata.google.internal. - Internal services. Admin panels, dashboards and anything else that trusts a request because it comes from inside, including services bound to
127.0.0.1on the machine itself. - Local files. In my test, a default Playwright page opened a
file://address and showed the file's contents.
The cloud providers put a hurdle in front of their metadata services. AWS's IMDSv2 needs a token fetched with a PUT request first. Google requires a Metadata-Flavor: Google header, and Azure requires Metadata: true. A browser that simply navigates to an address sends none of these, which stops the simplest attack. Do not rely on them alone: AWS's documentation says that by default an instance accepts both the old and the new version of its metadata service, and your internal admin panel asks for no such header.
Why checking the address is not enough
The obvious defence is to refuse private addresses before opening them. Each of these gets past it.
- Other spellings of an address. The URL standard's parser accepts IPv4 addresses written as one number, in hexadecimal or in octal. In my test, Chromium opened
http://2130706433/,http://0x7f.1/andhttp://0177.0.0.1/, and each one loaded a server listening on127.0.0.1. So did the IPv6 form[::ffff:127.0.0.1]. A check that compares strings misses all four. - Names. Anyone can point their own DNS name at
10.0.0.5. You have to resolve the name and check the answer. - DNS rebinding. You resolve the name, see a public address and approve it. The browser resolves it again a moment later and gets a private one.
- Redirects. A public page answers
302with an internal address, and the browser follows it. Playwright MCP's own README warns that its origin allow-list and block-list "does not affect redirects" and that the tool "is not a security boundary". - Everything after the first request. The page you approved is public. Its images, frames, scripts,
fetchcalls and WebSockets go wherever its author likes. - Other schemes.
file:reads from the disk, not the network, so a network rule never sees it. A check has to refuse every scheme it does not expect, not only the ones it knows to be bad. - Proxy bypass rules. A filtering proxy is a good idea with a trap in it. Chromium's documentation lists "implicit bypass rules": requests to
localhost,127.0.0.1/8,169.254/16and a few others are sent directly, not through the proxy, unless the bypass list contains<-loopback>. Playwright's source adds that rule for you when you give it a proxy, unless your own bypass list names a loopback host, and in my test its proxy did receive requests for127.0.0.1and169.254.169.254. If you start Chrome another way, add--proxy-bypass-list="<-loopback>"yourself.
Defend it yourself
Use layers, and put the strongest one outside the browser.
1. Check the address, and every request, in code
This sketch refuses non-web schemes, resolves each host and refuses any address that is not public. It turns off service workers, as Playwright's documentation recommends, because requests a service worker handles do not reach route.
import ipaddress
import socket
from urllib.parse import urlsplit
from playwright.sync_api import sync_playwright
def is_public(ip_text):
ip = ipaddress.ip_address(ip_text.split("%")[0])
if ip.version == 6 and ip.ipv4_mapped:
ip = ip.ipv4_mapped
return ip.is_global and not ip.is_multicast
def check_url(url):
"""Raise ValueError unless url is http(s) and every address it resolves to is public."""
parts = urlsplit(url)
if parts.scheme not in ("http", "https"):
raise ValueError("only http and https are allowed")
if not parts.hostname or parts.username or parts.password:
raise ValueError("no host, or credentials in the URL")
port = parts.port or (443 if parts.scheme == "https" else 80)
try:
infos = socket.getaddrinfo(parts.hostname, port, type=socket.SOCK_STREAM)
except OSError:
raise ValueError("the host does not resolve")
for info in infos:
if not is_public(info[4][0]):
raise ValueError("the host resolves to a non-public address")
def guard(route):
url = route.request.url
if url.startswith(("data:", "blob:")): # these never touch the network
return route.continue_()
try:
check_url(url)
except ValueError:
return route.abort("blockedbyclient")
route.continue_()
def capture(target, path):
check_url(target)
with sync_playwright() as p:
browser = p.chromium.launch()
context = browser.new_context(service_workers="block", accept_downloads=False)
context.route("**/*", guard)
page = context.new_page()
page.goto(target)
page.screenshot(path=path)
browser.close()
capture("https://example.com", "example.png")
In my run it refused 127.0.0.1, 2130706433, 169.254.169.254 and a file:// address, and stopped an internal image and fetch made from a public page. It has two gaps:
- It does not see redirects. In my test, a handler that allowed only one server was called once. That server answered
302to a forbidden one, and the browser loaded it without calling the handler again. - It does not stop DNS rebinding. The handler resolves the name, and then Chromium resolves it again for itself.
It is also short on purpose: it lets through the NAT64 prefix 64:ff9b::/96, for example, which can wrap a private IPv4 address. A complete list is longer; Calotype's is open source and you may copy it.
2. Make a checking proxy the browser's only way out
A forward proxy closes both gaps: the browser has to ask it for every connection, redirects included, and the proxy can connect to the very address it just checked. Point the browser context at it with Playwright's proxy option. You can write one (Calotype's is about 250 lines of Python) or run an existing one. Stripe's open-source Smokescreen describes itself as an HTTP CONNECT proxy that resolves each requested name and makes sure it is "a publicly routable IP address and not an internal IP address".
3. Put the browser where there is nothing to reach
Code has bugs. The layer that still holds when yours does is the network: run the browser on a machine, container or network namespace with a route to the internet and to nothing else. Give it no cloud role, so the metadata service has no credentials to hand out, and block the link-local range at the firewall. Then a bypass of every check above finds an empty room.
4. Limit what a capture can cost you
Use a fresh browser context for every capture, refuse downloads, and cap the time and bytes a page may use. Do not run Chromium as root: Playwright's Docker documentation says that disables the browser's sandbox.
How Calotype handles it
Calotype's browser runs on Calotype's servers, so your network is not there to be reached. Its own still is, and the code defends that. What follows is what the code in ssrf.py, egress.py and capture.py does, and nothing more.
- One rule, written as an allow-list. An address may be fetched only if it is public unicast. The code refuses a list of special ranges (private, loopback, link-local, carrier-grade NAT, multicast, reserved, and their IPv6 counterparts), then anything Python's
ipaddressmodule does not call global. IPv4-mapped and NAT64 addresses are unwrapped and checked as the IPv4 address inside. IPv6 addresses with a zone are refused. - The requested address is checked before a browser is involved. Only
httpandhttps, with no credentials, whitespace or backslashes, and at most 2,048 characters. Ports 80, 443, and 1024 and up. Number-only, hexadecimal and octal hosts are parsed as the browser parses them. Names such aslocalhostandmetadata.google.internal, and names ending in.internal,.local,.lanor.corp, are refused without a lookup. A name must contain a dot. Then the name is resolved, and if any one of its addresses is not public, the request is refused. - Each capture gets its own proxy. A small forward proxy starts on
127.0.0.1for that capture alone, and the browser context is pointed at it with the bypass rule<-loopback>. For every connection the browser opens, the proxy resolves the host itself, applies the same rule, and connects to the exact address it checked. That is what covers redirects, sub-requests, WebSockets and DNS rebinding. Plain HTTP requests are forwarded withConnection: close, so a connection is never reused for a host that was not checked. - A request handler is the cheap first filter. It aborts every scheme except
http,https,dataandblob, and any host that is plainly a private address or a refused name. - The browser is told not to go around the proxy. It starts with QUIC, DNS prefetch and background networking off, and WebRTC barred from UDP paths outside the proxy.
- After loading, the result is checked again. If the page itself or one of its redirects was refused, or the redirect chain or the final address has a scheme other than
httporhttps, the capture fails withblocked_targetand no image is returned. A refused sub-request, such as one image, is simply missing from the picture. - Each capture is isolated and capped. A fresh context, closed afterwards. Service workers blocked, downloads refused, invalid certificates not accepted. At most 50 MB downloaded and 30 seconds in total.
- No setting switches the rule off. The only exceptions are exact address-and-port pairs that tests set in code.
The tests for all of this are in the same repository, in calotype/tests/test_ssrf.py. If you find a way through, write to skewbald@agentmail.to rather than opening a public issue.
What none of this covers
- Prompt injection. If the screenshot goes to a model, the page's text goes with it. Keeping the browser out of your network protects the network, not the model.
- Private pages you need. A hosted browser cannot see your staging site, and should not. Run a browser inside for those, and give it only addresses you choose.
If the addresses you capture are public, a hosted call moves the browser out of your network in one step. A free Calotype key is 100 screenshots a month with no account: get a key, or read what Calotype will not fetch. If you run the browser yourself, the Playwright side is in Playwright screenshots in Python.
Sources
Read on 21 November 2026:
- AWS: Use the Instance Metadata Service and Access instance metadata (addresses, the IMDSv2 token, both versions on by default, role credentials)
- Google Cloud: View and query VM metadata (addresses, the
Metadata-Flavorheader) - Azure Instance Metadata Service (address, the
Metadataheader) - WHATWG URL standard (IPv4 addresses in hexadecimal and octal)
- Chromium: proxy support (implicit bypass rules,
<-loopback>) - Playwright source: chromium.ts (the bypass rule it adds)
- Playwright: page.route and Docker
- Playwright MCP README (the security note)
- Stripe Smokescreen README