Security skill · Find and fix
SSRF: find and fix.
Find server-side request forgery where an application fetches a URL, host, or file influenced by a user, confirm it safely, and fix it with destination allowlists, private-range and metadata-endpoint blocking, DNS pinning, redirect control, and network egress limits. Use when reviewing webhooks, URL previews, importers, image fetchers, PDF renderers, or LLM tools that fetch URLs (CWE-918).
Facts
- Category
- Find and fix
- License
- MIT
- Tags
- Code review
- Version
- 1.0.0
- Last updated
- 2026-12-02
- Folder
ssrf-find-and-fix/- MCP resource
skill://ssrf-find-and-fix/SKILL.md- Files
- SKILL.md
- LICENSE
- references/ssrf-defenses.md
- Standards
- A01:2025
- CWE-918
Original Saasment content. Saasment is in early access; this skill does not require joining it.
Install via MCP or as files
Connect your client to https://www.saasment.com/api/mcp (see client setup) and call get_skill:
{
"name": "get_skill",
"arguments": {
"slug": "ssrf-find-and-fix"
}
}Or download the .zip and unpack it into your agent's skills directory:
Terminal, from your project root (user-level: ~/.cursor/skills)
mkdir -p .cursor/skills
curl -fsSL https://www.saasment.com/ai-security/skills/ssrf-find-and-fix/download.zip -o /tmp/ssrf-find-and-fix.zip
unzip -o /tmp/ssrf-find-and-fix.zip -d .cursor/skills
# result: .cursor/skills/ssrf-find-and-fix/SKILL.mdReview SKILL.md before enabling a skill. Skills are instructions your agent will follow.
SKILL.md
--- name: ssrf-find-and-fix description: Find server-side request forgery where an application fetches a URL, host, or file influenced by a user, confirm it safely, and fix it with destination allowlists, private-range and metadata-endpoint blocking, DNS pinning, redirect control, and network egress limits. Use when reviewing webhooks, URL previews, importers, image fetchers, PDF renderers, or LLM tools that fetch URLs (CWE-918). license: MIT metadata: author: Saasment version: "1.0.0" category: both tags: "code-review" --- # SSRF: find and fix License: MIT. Copyright (c) 2026 Saasment. Source: https://www.saasment.com/ai-security/skills/ssrf-find-and-fix Server-side request forgery (SSRF) lets an attacker make your server send requests to places the attacker cannot reach directly: internal services, admin interfaces, and cloud metadata endpoints that hand out credentials. Any feature that fetches a remote resource on behalf of a user is a candidate. The strongest fix is to avoid fetching arbitrary URLs. When you must, combine an allowlist of destinations with network-level egress controls, since URL string checks alone are easy to bypass. ## When to use - A feature fetches a user-supplied URL: webhooks, link previews, avatar or image import, RSS or feed readers, PDF or screenshot rendering, OAuth or SSO metadata fetches, file importers, and server-side proxies. - An LLM agent has a browse, fetch, or HTTP tool. - You are reviewing cloud workloads where instance metadata services are reachable from application code. ## Safe by default - Only test applications you own or are authorized to test, in a non-production environment. - Probe with a listener you control (for example a local HTTP server or a test collaborator URL) and with loopback addresses on your own test host. Do not scan networks you do not own, and do not request a real cloud metadata endpoint on a shared or production account to read credentials. - Do not try to read or retrieve real credentials from any metadata service. A blocked-or-not response from a test environment proves the point. - Keep probe rates low to avoid disturbing internal services. ## Procedure 1. **Find fetch sites.** Search for HTTP clients and URL-taking APIs (patterns in `references/ssrf-defenses.md`). Include image processors, headless browsers, XML parsers with external entities, and libraries that follow URLs inside documents. 2. **Trace inputs.** Check whether any part of the destination (full URL, host, port, path, scheme, redirect target, or a URL inside fetched content) is influenced by users or other untrusted data. Note whether the response body, status, or timing is returned to the user (full, blind, or partial SSRF). 3. **Test safely.** In the test environment, give the feature a URL to a listener you control and confirm it makes the request. Then test whether it also accepts: loopback (`http://127.0.0.1:<port>/`), private ranges you own in the test network, alternate encodings of the same address (decimal, octal, hex, IPv6 forms), a hostname that resolves to a private address, and an allowed host that redirects to a blocked one. Record which are blocked. 4. **Choose the right fix per feature:** - Preferred: do not fetch user-supplied URLs. Accept an identifier or upload instead. - Known set of partners: strict allowlist of hostnames and ports, `https` only. - Arbitrary public URLs (previews, webhooks): validate and then connect safely, as below. 5. **Implement safe fetching for arbitrary public URLs:** - Parse the URL with a real parser. Allow only `http` and `https`. Reject credentials in the URL and unexpected ports. - Resolve the hostname yourself, then reject any address in a blocked range (loopback, private, link-local including `169.254.0.0/16`, carrier-grade NAT, multicast, unspecified, and the IPv6 equivalents including IPv4-mapped addresses). - Connect to the validated IP address and pin it for the request (send the original `Host` header and TLS server name), so a second DNS lookup cannot return a different address (DNS rebinding). - Disable automatic redirects, or follow them manually and re-run validation at each hop with a small hop limit. - Set timeouts, a maximum response size, and a content-type allowlist. Do not return raw responses or error details to the user. 6. **Add network controls.** Run fetchers in an isolated network segment with an egress policy that denies internal ranges and metadata addresses. On AWS, require IMDSv2 and set the hop limit to 1 where containers do not need metadata access. On other clouds, restrict or disable metadata access for workloads that do not need it. Give workloads least-privilege cloud roles so a successful SSRF has little to reach. 7. **Add tests** for each blocked category from step 3, including redirects and hostnames resolving to private addresses (use a stubbed resolver in unit tests). ## Verification - Repeat every probe from step 3. Expected: the listener receives requests only from allowed flows, and every blocked probe is rejected before a connection is made. - Confirm from the application host that internal addresses are unreachable through the fetcher's network path (egress policy test with a harmless request to a test service you own). - Confirm the metadata service requirement (for example IMDSv2 required) in the cloud configuration. - Run the tests; verify they fail without the validation and pass with it. ## Reporting For each fetch site: location, attacker control, response visibility, tests performed, fix applied, residual risk. Mention any feature that was removed or replaced with an allowlist. ## References - CWE-918: https://cwe.mitre.org/data/definitions/918.html - OWASP Top 10 web 2025 folds SSRF into Broken Access Control; the 2021 list had it as a separate category: https://owasp.org/Top10/ - OWASP SSRF Prevention Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html - Companion skills: `iac-misconfig-review`, `insecure-output-handling-review`, `agent-tool-permission-review`.
Helper files
LICENSE
MIT License Copyright (c) 2026 Saasment Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
references/ssrf-defenses.md
# SSRF defenses reference
License: MIT. Copyright (c) 2026 Saasment.
## Search terms by language
```text
JavaScript/TypeScript: fetch(, axios., got(, node-fetch, http.request, https.get, undici, puppeteer.goto, page.goto
Python: requests., httpx., urllib.request.urlopen, aiohttp, pycurl, wkhtmltopdf, playwright goto
Java/Kotlin: HttpURLConnection, HttpClient, RestTemplate, WebClient, OkHttp, new URL(
Go: http.Get, http.Client, http.NewRequest
PHP: file_get_contents, curl_init, fopen with URL, SoapClient
Ruby: Net::HTTP, open-uri, Faraday, HTTParty
.NET: HttpClient, WebRequest, WebClient
Other: ImageMagick/ffmpeg with remote inputs, XML parsers with external entities enabled, SVG renderers
```
## Address ranges to block (IPv4 and IPv6)
| Range | Meaning |
| --- | --- |
| `0.0.0.0/8` | "This network", unspecified |
| `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` | Private networks |
| `100.64.0.0/10` | Carrier-grade NAT |
| `127.0.0.0/8` | Loopback |
| `169.254.0.0/16` | Link-local, includes common cloud metadata address `169.254.169.254` |
| `192.0.0.0/24`, `192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24` | Special use and documentation |
| `198.18.0.0/15` | Benchmarking |
| `224.0.0.0/4`, `240.0.0.0/4` | Multicast and reserved |
| `::1/128`, `::/128` | IPv6 loopback and unspecified |
| `fc00::/7` | IPv6 unique local |
| `fe80::/10` | IPv6 link-local |
| `::ffff:0:0/96` | IPv4-mapped IPv6 (re-check the embedded IPv4 address) |
| `fd00:ec2::254` | IPv6 metadata address on AWS (covered by `fc00::/7`) |
Prefer a library that classifies addresses (for example Python `ipaddress` with `is_global`, or an equivalent) over hand-written range checks.
## Safe fetch outline (Python, illustrative)
```python
import ipaddress, socket
from urllib.parse import urlsplit
def resolve_public(host: str, port: int):
infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
addresses = []
for family, _, _, _, sockaddr in infos:
ip = ipaddress.ip_address(sockaddr[0])
if ip.is_ipv6 and ip.ipv4_mapped:
ip = ip.ipv4_mapped
if not ip.is_global:
raise ValueError("destination not allowed")
addresses.append(str(ip))
return addresses
def validate(url: str):
parts = urlsplit(url)
if parts.scheme not in ("http", "https"):
raise ValueError("scheme not allowed")
if parts.username or parts.password:
raise ValueError("credentials not allowed")
if not parts.hostname:
raise ValueError("missing host")
port = parts.port or (443 if parts.scheme == "https" else 80)
return parts.hostname, port, resolve_public(parts.hostname, port)
# Then connect to one of the returned addresses (pinning), send the original Host header,
# disable redirects or re-validate each hop, and enforce timeout and size limits.
```
This outline checks addresses at resolution time. The connection must use the validated address, otherwise a second DNS lookup can return a different one.
## Cloud metadata notes
- AWS: require IMDSv2 (`HttpTokens=required`) and set `HttpPutResponseHopLimit` to 1 when containers do not need metadata.
- GCP and Azure: metadata requires specific request headers (`Metadata-Flavor: Google`, `Metadata: true`). That helps against simple SSRF but is not a substitute for blocking the address.
- Give workloads narrow roles so credentials obtained by an attacker have little reach.
## Test cases (test environment, listener you control)
1. Plain external URL to your listener (expected allowed if the feature is meant to fetch URLs).
2. `http://127.0.0.1:<test-port>/` and `http://localhost:<test-port>/` (expected blocked).
3. `http://[::1]:<test-port>/` and an IPv4-mapped form (expected blocked).
4. Decimal or hex encodings of the loopback address (expected blocked after normalization).
5. A hostname you control that resolves to `127.0.0.1` (expected blocked after resolution).
6. An allowed URL that redirects to a private address (expected blocked at the redirect hop).
7. Non-HTTP schemes such as `file:` and `gopher:` (expected rejected).
8. Very large or slow responses (expected cut off by size and time limits).
Related
Companion skills
Questions
How do I install the SSRF: find and fix skill?
Download https://www.saasment.com/ai-security/skills/ssrf-find-and-fix/download.zip and unzip it into your agent's skills directory (for example .cursor/skills, .claude/skills, .agents/skills, or .github/skills) so that ssrf-find-and-fix/SKILL.md exists. Or connect to https://www.saasment.com/api/mcp and call the get_skill tool with the slug ssrf-find-and-fix.
What license is the SSRF: find and fix skill under?
It is original Saasment content under the MIT license, stated in the SKILL.md frontmatter and in the LICENSE file in the skill folder.
Is it safe to run this skill?
A skill is a set of instructions your agent follows, so read SKILL.md first. It tells the agent to test only systems you own or are authorized to test, to use test environments and synthetic data, and to avoid destructive probes. Downloading it does not run any code on your machine.