Skip to content

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: operator for the application (viewer can 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/16
yaml
# 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, api and 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 version 1.0.0.1) is data and is never flagged.
  • Headers named under Headers checked as URLs (for example X-Callback-Url). Host cannot 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 after jar:, two levels deep.

Categories ​

CategoryDestinations
loopback127/8, ::1, localhost
private10/8, 172.16/12, 192.168/16, 100.64/10, fc00::/7
link_local169.254/16, fe80::/10
metadata169.254.169.254, 169.254.170.2, 100.100.100.200, fd00:ec2::254, metadata.google.internal
unspecified0.0.0.0/8, ::
internal_names*.internal, *.local, *.lan, single-label names, your internal domains
schemesa 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 async mode (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 sync mode, the request waits up to Lookup timeout. A timeout passes the request and logs ssrf.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=async
yaml
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/check

Read the events ​

RuleMeaning
ssrf.loopback, ssrf.private, ssrf.link_local, ssrf.unspecifiedThe value points at that category.
ssrf.metadataA cloud metadata address. Severity is CRITICAL.
ssrf.internal_nameAn internal host name.
ssrf.schemeA scheme outside the allowed list.
ssrf.userinfoTwo parsers read different hosts. The message names both.
ssrf.redirectorA name that embeds an address.
ssrf.resolves_internalThe name's DNS answer is internal.
ssrf.dns_timeoutA 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 ​

SettingWhat it doesDefaultAllowed valuesApplies in
SSRF guard (policy.ssrf.enabled)Runs the module.truetrue, falseall
Protection mode (policy.ssrf.mode)detect logs, block refuses.detectdetect, blockthe application's detect wins
Action (policy.ssrf.action)log: findings never refuse, whatever the mode.refuserefuse, logblock mode
Checked locations (where)Where values are read.all fivequery, form, json, xml, multipartall
Headers checked as URLs (headers)Headers checked as URLs.noneup to 16 names; not Hostall
URL parameter names (url_names)Names that mark a value as a URL.a built-in listup to 64all
Check bare hosts (bare_hosts)Check scheme-less hosts under URL names.truetrue, falseall
Categories (categories)Which destinations are flagged.allthe categories aboveall
Allowed schemes (schemes)URL schemes that pass.http, httpsup to 16all
Allowed internal networks (allow_networks)Internal addresses or CIDRs the application may fetch.noneup to 256all
Allowed internal hosts (allow_hosts)Internal host names it may fetch; *.domain for a domain.noneup to 256all
Internal domains (internal_domains)Your internal DNS domains.noneup to 64all
Decode address-embedding names (redirectors)Decode names such as 127.0.0.1.nip.io.truetrue, falseall

DNS checks ​

SettingWhat it doesDefaultAllowed valuesApplies in
Resolve host names (dns.enabled)Resolve names and flag internal answers.falsetrue, falseall
Lookup mode (dns.mode)Wait for the answer or look it up in the background.asyncasync, syncDNS checks on
Lookup timeout (dns.timeout)How long a sync lookup may hold a request.50ms5ms to 500msmode sync
Cache size (dns.cache_size)Names whose answers are kept per node.10000100 to 1000000DNS checks on
Cache lifetime (dns.cache_ttl)How long an answer or failed lookup is kept.60s1s to 1hDNS 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 ​

LimitValue
Candidate values checked per request64 (the rest pass)
Bytes read per valuethe first 4 KiB
URL nesting followed2 levels
Findings kept per request8
Concurrent DNS lookups64

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 is log.
  • Fix: set Protection mode to block and 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 Host as a checked header.
  • Fix: correct the value as the message says.