Appearance
SSRF guard Since v0.2
Server-side request forgery (SSRF) makes the application fetch a destination the attacker chooses: the cloud metadata service and its credentials, an admin port on loopback, a database on the private network. The SSRF module reads request values the application is likely to fetch and flags those that point at internal destinations, however they are written. It runs before the signatures.
The module runs on every application, in detect. Findings are logged and nothing is refused until you set the module to block. The application's own detect mode still wins. To also control what the application fetches on its own, see Outbound proxy.
Before you begin
- Role:
operatorfor the application (viewercan read). - Review the events for a while before you block. A value the application is meant to fetch internally belongs in Allowed internal networks or Allowed internal hosts.
Turn on blocking
text
1. Open Applications > All applications, and select the application.
2. Open Request checks > SSRF and outbound, tab Request guard.
3. Set Protection mode to block.
4. Add what the application may fetch internally under Allowed internal networks and hosts.
5. Select Preview changes, add a comment and select Apply.sh
waap ssrf get -app shop
waap ssrf set -app shop -m "block SSRF" mode=block allow_networks=10.20.0.0/16yaml
# applications[].policy.ssrf
ssrf:
mode: block
allow_networks: [10.20.0.0/16] # the image service the app fetches from
internal_domains: [corp.example]
headers: [X-Callback-Url]What is checked
- URL-like parameters. Parameters whose name suggests a URL (URL parameter names:
url,callback,webhook,redirect,image,avatar,endpoint,apiand more). A name matches when it equals an entry or one of its words does (avatar_url,callbackUrl,profile.image,mechanic_api). An entry ending in*matches a prefix. Their values are checked when they begin as a URL (http://,//host,\\host,http:host) or, with Check bare hosts, as a host or address (10.0.0.5,db.internal:5432). URLs inside free text are not read. - Every other parameter is checked only for dangerous schemes at its start (
file:,gopher:,dict:,ldap:,jar:,php:,expect:and similar). An address in an ordinary field (ip=10.0.0.1, a version1.0.0.1) is data and is never flagged. - Headers named under Headers checked as URLs (for example
X-Callback-Url).Hostcannot be listed. - Locations under Checked locations: query, form, json, xml, multipart (all by default).
How values are read
The parser is lenient on purpose, like the HTTP libraries applications use. It checks every reading a library could take and keeps the worst.
- Userinfo and fragment tricks (
http://good.com@127.0.0.1,http://127.0.0.1#@good.com), backslashes, percent-encoding (also of the whole value), full-width and other Unicode digits and dots, trailing dots, brackets and zone IDs. - Addresses in decimal (
2130706433), octal (0177.0.0.1), hex (0x7f.1), short (127.1) and mixed forms, and IPv6 forms that carry an IPv4 address (mapped::ffff:7f00:1, compatible, NAT64, 6to4, Teredo). - Names that embed an address (
127.0.0.1.nip.io,10-0-0-1.sslip.io,localtest.me), decoded when Decode address-embedding names is on. - A URL inside a URL's query (
?next=http://...) or afterjar:, two levels deep.
Categories
| Category | Destinations |
|---|---|
loopback | 127/8, ::1, localhost |
private | 10/8, 172.16/12, 192.168/16, 100.64/10, fc00::/7 |
link_local | 169.254/16, fe80::/10 |
metadata | 169.254.169.254, 169.254.170.2, 100.100.100.200, fd00:ec2::254, metadata.google.internal |
unspecified | 0.0.0.0/8, :: |
internal_names | *.internal, *.local, *.lan, single-label names, your internal domains |
schemes | a URL scheme outside the allowed schemes (default http and https) |
Check host names with DNS (optional)
With Resolve host names on, the inspection node resolves host names and flags names whose answer is internal (ssrf.resolves_internal).
- In
asyncmode (the default), a name seen for the first time is looked up in the background and the request passes. Later requests use the cached answer. - In
syncmode, the request waits up to Lookup timeout. A timeout passes the request and logsssrf.dns_timeout. - Answers, and failed lookups, are kept for the cache lifetime in a cache per application. At most 64 lookups run at once.
DNS checks cannot stop rebinding
A check cannot stop DNS rebinding between our lookup and the application's own. For that, use the outbound proxy.
text
1. Open Request checks > SSRF and outbound, tab DNS checks.
2. Turn on Resolve host names and choose the Lookup mode.
3. Select Preview changes, then Apply.sh
waap ssrf set -app shop -m "resolve names" dns.enabled=true dns.mode=asyncyaml
ssrf:
dns: { enabled: true, mode: async, timeout: 50ms, cache_ttl: 60s }Check a URL
The Check a URL tab answers how a client library could read a value, whether it is flagged, the rule and category, and with this application's mode, whether the request would be refused or only logged. Nothing is sent.
text
1. Open Request checks > SSRF and outbound, tab Check a URL.
2. Enter the Value and the Parameter name it arrives under, and run the check.sh
waap ssrf check -app shop -name url -value http://0x7f.1/text
POST /v1/api/ssrf/checkRead the events
| Rule | Meaning |
|---|---|
ssrf.loopback, ssrf.private, ssrf.link_local, ssrf.unspecified | The value points at that category. |
ssrf.metadata | A cloud metadata address. Severity is CRITICAL. |
ssrf.internal_name | An internal host name. |
ssrf.scheme | A scheme outside the allowed list. |
ssrf.userinfo | Two parsers read different hosts. The message names both. |
ssrf.redirector | A name that embeds an address. |
ssrf.resolves_internal | The name's DNS answer is internal. |
ssrf.dns_timeout | A synchronous lookup timed out. Log only. |
Each event names the parameter (ARGS, json, xml or REQUEST_HEADERS and its name), the value as sent, and the decoded destination with how it was written ("octal 0177.0.0.1 = 127.0.0.1"). Exceptions accept ssrf.* and single rules, for the whole request or one field (arg:url, header:X-Callback-Url, param:json.profile.image).
Settings reference
Request guard
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
SSRF guard (policy.ssrf.enabled) | Runs the module. | true | true, false | all |
Protection mode (policy.ssrf.mode) | detect logs, block refuses. | detect | detect, block | the application's detect wins |
Action (policy.ssrf.action) | log: findings never refuse, whatever the mode. | refuse | refuse, log | block mode |
Checked locations (where) | Where values are read. | all five | query, form, json, xml, multipart | all |
Headers checked as URLs (headers) | Headers checked as URLs. | none | up to 16 names; not Host | all |
URL parameter names (url_names) | Names that mark a value as a URL. | a built-in list | up to 64 | all |
Check bare hosts (bare_hosts) | Check scheme-less hosts under URL names. | true | true, false | all |
Categories (categories) | Which destinations are flagged. | all | the categories above | all |
Allowed schemes (schemes) | URL schemes that pass. | http, https | up to 16 | all |
Allowed internal networks (allow_networks) | Internal addresses or CIDRs the application may fetch. | none | up to 256 | all |
Allowed internal hosts (allow_hosts) | Internal host names it may fetch; *.domain for a domain. | none | up to 256 | all |
Internal domains (internal_domains) | Your internal DNS domains. | none | up to 64 | all |
Decode address-embedding names (redirectors) | Decode names such as 127.0.0.1.nip.io. | true | true, false | all |
DNS checks
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Resolve host names (dns.enabled) | Resolve names and flag internal answers. | false | true, false | all |
Lookup mode (dns.mode) | Wait for the answer or look it up in the background. | async | async, sync | DNS checks on |
Lookup timeout (dns.timeout) | How long a sync lookup may hold a request. | 50ms | 5ms to 500ms | mode sync |
Cache size (dns.cache_size) | Names whose answers are kept per node. | 10000 | 100 to 1000000 | DNS checks on |
Cache lifetime (dns.cache_ttl) | How long an answer or failed lookup is kept. | 60s | 1s to 1h | DNS checks on |
Examples
Block SSRF, allow the internal image service, and also check a callback header:
yaml
policy:
ssrf:
mode: block
allow_networks: [10.20.0.0/16]
internal_domains: [corp.example]
headers: [X-Callback-Url]Limits
| Limit | Value |
|---|---|
| Candidate values checked per request | 64 (the rest pass) |
| Bytes read per value | the first 4 KiB |
| URL nesting followed | 2 levels |
| Findings kept per request | 8 |
| Concurrent DNS lookups | 64 |
The check on a name already in the cache takes about 1 µs.
Troubleshooting
The application's own internal fetch is flagged
- Cause: the value points at an internal destination the application is meant to fetch.
- Check: the event names the category and the decoded destination.
- Fix: add the network or host to Allowed internal networks or Allowed internal hosts.
Nothing is refused
- Cause: the module or the application is in
detect, or Action islog. - Fix: set Protection mode to
blockand check the application's mode.
Preview refuses a setting with 422
- Cause: a proxy address that is not loopback, a port out of range, or
Hostas a checked header. - Fix: correct the value as the message says.