Topic: ssrf

Accepting arbitrary URLs taught me the trust boundary is the fetch, not the parse

Accepting arbitrary URLs taught me the trust boundary is the fetch, not the parse
When I first shipped my URL-to-Markdown fetcher, I spent most of my energy on the parsing side — stripping navbars, picking the main content, handling selectors. The trust model felt obvious: hand it a URL, get back clean Markdown. What could go wrong? Plenty, it turns out. The boundary I should have been worried about wasn't between HTML and Markdown — it was at the moment I accepted the URL itself. An agent (or anyone) could point the fetcher at http://169.254.169.254/ , at localhost services, at internal dashboards on a private network. My server was happily fetching whatever it was told, from whatever network position it happened to hold. The parser was fine; the ingress was wide open. So I moved the trust boundary to where it belongs: before the request goes out. Scheme allowlist, DNS resolved once and the resolved IP checked against private and link-local ranges, redirects re-validated at every hop (a redirect to an internal host is still an internal fetch), and a hard cap...