{"success":true,"name":"fetching-a-user-provided-url-your-server-is-about-to-visit-i","description":"Server code downloads or calls a URL that a user typed or submitted","category":"ai-brimind","path":"ai-brimind/fetching-a-user-provided-url-your-server-is-about-to-visit-i/SKILL.md","file":"SKILL.md","content":"---\nname: fetching-a-user-provided-url-your-server-is-about-to-visit-i\ndescription: \"Server code downloads or calls a URL that a user typed or submitted\"\n---\n\n# Fetching a User-Provided URL? Your Server Is About to Visit It\n\n## When to use\nYou are writing server-side code that fetches a URL coming from user input — link previews, imports, image-by-URL, 'test my webhook' features.\n\n## Example request\nA 'preview this link' feature fetches any URL → users point it at http://localhost/admin or internal services, and your server obeys because the request comes from inside (SSRF). Fetching cloud metadata addresses like [IP] → on cloud servers this endpoint hands out credentials; internal and metadata IPs must be blocked (metadata protection). Only checking the hostname once → a domain can resolve to an internal IP, or redirect there after the check; validate the final destination and limit redirects (DNS/redirect tricks). Downloading whatever size the URL serves → a huge or endless response hangs the server; enforce timeouts and size caps (resource limits).\n\n## Instructions\nAct like a developer who realizes that fetching a user's URL means letting a stranger steer your server's own network access — a position attackers call SSRF. Before implementing, decide the narrowest possible policy: if the feature can work with a whitelist of known hosts, use the whitelist and be done. If arbitrary URLs are truly required, enforce guards in the fetch path: allow only http/https schemes, resolve the hostname and reject private, loopback, link-local, and cloud-metadata address ranges, re-validate after each redirect (or disable redirects), and apply strict timeouts and response-size limits. Check whether a maintained library for safe outbound fetching exists in your ecosystem and prefer it over hand-written IP math, which is easy to get wrong. Run the fetch with the least network access the platform allows, and never attach internal credentials or headers to these outbound requests. Test like an attacker: submit localhost URLs, internal IPs, and a redirecting link, and confirm each is refused. Only ship once the fetcher provably cannot reach your internal world, and explain how the guards break the SSRF path rather than just fetching the happy-path link.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #546\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}