Outbound Requests and Internal Network Authority
Follow an avatar URL into a server connection and separate contacting an internal service from exposing its response.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
A user asks an app to fetch a profile image from a URL. The server downloads it and stores the bytes. Now the user supplies a URL pointing at a service the server can reach but the user cannot.
The important change is who makes the connection. Server-side request forgery, or SSRF, uses the server's network access to reach an unintended destination.
We'll follow one avatar import: the supplied URL, the connection the HTTP client makes, and the information the app returns. Contacting an internal service and reading its response are separate observations.
Identify what the server lends to the caller
The server may reach private addresses, local services, cloud metadata endpoints, trusted network peers, or authenticated upstreams that the external user cannot reach directly. The exact reachable set depends on routing, firewall rules, DNS, proxies, credentials, and deployment. Do not assume a cloud platform or metadata protocol absent from the evidence.
# Unsafe original teaching outline.
url = request.json['avatarUrl']
response = requests.get(url, timeout=5)
body = response.content[:MAX_AVATAR_BYTES]
path = save_imported_avatar(body)
return {'path': path, 'bytes': len(body), 'source': url}
The timeout is useful but does not authorize the destination. The slice happens after requests has acquired the response content, so it does not establish a bounded download. Redirects may change the destination before content is saved. The next lecture examines that validation-to-connection gap in depth.
Keep network contact, stored bytes, and caller visibility separate.
Input. The user supplies an outbound target, not just a display label.
{"avatarUrl":"https://fixture.example.test/image"}
Connect. The HTTP client uses server routing, DNS, proxy, and credential context.
response = requests.get(url, timeout=5)
Return. The shown response exposes metadata; saved-body access requires another trace.
return {"path": saved_path, "bytes": saved_size}
Review question: Prove the connection and the response channel independently before describing impact.