{"success":true,"name":"fetch-user-given-urls-without-exposing-your-insides","description":"Server code fetches a URL that a user typed or submitted.","category":"ai-brimind","path":"ai-brimind/fetch-user-given-urls-without-exposing-your-insides/SKILL.md","file":"SKILL.md","content":"---\nname: fetch-user-given-urls-without-exposing-your-insides\ndescription: \"Server code fetches a URL that a user typed or submitted.\"\n---\n\n# Fetch User-Given URLs Without Exposing Your Insides\n\n## When to use\nThe backend downloads, previews, or imports from URLs provided by users, and nothing restricts where those requests can go.\n\n## Example request\nLink-preview feature fetches any URL → user submits http://[IP] and reads the cloud server's credentials; this is SSRF, the server browsing on the attacker's behalf. 'Import from URL' allowed to hit localhost → internal admin APIs that were 'not public' answer happily; the server sits inside the network attackers can't normally reach. Validating the URL string but following redirects blindly → an innocent URL 302-redirects to an internal address; the check must apply to the final resolved target. Fetch response echoed raw to the user → internal error pages and service banners leak; only the expected content type comes back.\n\n## Instructions\nYou are a server-side fetch gatekeeper who remembers that your backend stands INSIDE the walls — so letting users steer its requests is letting them walk around inside. Whenever server code fetches a user-influenced URL: 1) Classify the need first: if you only ever fetch from a few known services, use a whitelist of allowed hosts and be done — the tightest fix is not needing arbitrary URLs at all. 2) If arbitrary URLs are truly required: allow only http/https schemes, resolve the hostname and BLOCK private and internal ranges (localhost, 127.x, 10.x, 172.16-31.x, 192.168.x, 169.254.x, and cloud metadata addresses), and re-check after every redirect, since redirects are the classic bypass. 3) Prefer an existing hardened library or an outbound proxy that implements these blocks — teams get the IP math wrong hand-rolling it. 4) Contain the response: enforce a timeout and size limit, accept only the content types you expect, and never relay raw response bodies or errors to the user. 5) Verify by attacking yourself: submit localhost, a private IP, a metadata address, and a redirecting URL — each must be refused. Explain the protection by naming the flaw, server-side request forgery, and stating what the attacker could have reached without it.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #464\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}