Skip to main content
Menu
Advisories

Operator credentials sent to attacker-controlled hosts when following redirects (--follow-redirects)

GHSA-69JP-6FH7-WJPMPublished Updated GitHub

Description

With --follow-redirects (-F), dalfox followed a redirect chain to any host, using reqwest's Policy::limited(10). Every request on that client carries the operator's -H headers, --cookies, and any Authorization/Cookie inherited from a raw-http or HAR import, attached unconditionally by apply_headers_ua_cookies_inner. A scan target that redirects off-origin could therefore collect the operator's credentials.

The transport's own protection is not enough for a scanner, and it fails in two distinct ways.

1. Custom credential headers are never stripped. reqwest removes only Authorization, Cookie, cookie2, Proxy-Authorization and WWW-Authenticate when a hop changes host. A custom credential header — -H "X-Api-Key: ...", -H "X-Auth-Token: ..." — survives the very first hop off-target. dalfox's own generated config template suggests -H as the authentication channel.

2. The strip does not persist past one hop. Each redirected request is rebuilt from the original header map, and the scrub compares the next URL against the immediately preceding hop only — not against the URL that started the chain. So a target answering 302 -> https://attacker.example/a, with /a answering 302 -> https://attacker.example/b, restores the operator's full Cookie and Authorization on that second, same-host hop. 307 and 308 replay the request body along the same chain, so a -d or HAR-imported body carrying a CSRF or API token goes too.

Nothing else constrained the destination: --out-of-scope and --exclude-url are applied to the input target list and to external-JS URLs, never to a redirect. Under -F, the entire scan — payload requests included — could be steered onto a host the operator never named.

Affected component

Target::build_client in src/target_parser/mod.rs:

if self.follow_redirects {
    client_builder = client_builder.redirect(Policy::limited(10));  // follows anywhere
} else {
    client_builder = client_builder.redirect(Policy::none());
}

Impact

An attacker who controls the redirect behaviour of a scanned endpoint — their own site, a compromised one, or any open redirect on the target — obtains the credentials the operator configured for the scan. Two hops yield the session cookie and bearer token in full; one hop yields any non-standard authentication header. Because those credentials typically authenticate the operator against the target application, disclosure can lead to account or session takeover there.

Proof of concept

Target on :8765 answers 302 -> http://127.0.0.1:9988/first; the foreign host on :9988 answers 302 -> /second and logs what it receives.

dalfox url --url "http://127.0.0.1:8765/start?q=1" -F \
  --headers "Authorization: Bearer AUTHSECRET" \
  --headers "X-API-Key: APIKEYSECRET" \
  --cookies "session=COOKIESECRET"

What the foreign host recorded, before the fix:

HOP /first   cookie=None                  auth=None               apikey=APIKEYSECRET
HOP /second  cookie=session=COOKIESECRET  auth=Bearer AUTHSECRET  apikey=APIKEYSECRET

The first hop leaks the custom header; the second hop leaks everything. After the fix the foreign host records nothing.

Mitigating factors

--follow-redirects is opt-in and defaults to false on every surface (CLI, job spec, REST, MCP), so a default scan is unaffected. The leak needs that flag and credentials on the command line.

Patch

Fixed in commit a602ebb0 (PR #1460). The redirect policy now follows a hop only while the chain stays on the origin that started it, with one carve-out for the ubiquitous http://host/ -> https://host/ upgrade on default ports, which stays on the same host and moves the credentials onto TLS. An off-origin hop is stopped rather than raised as an error, so the caller simply sees the 3xx response.

The decision is anchored on the chain's first URL rather than on the scan target, because clients are cached under a key of (timeout, proxy, follow_redirects, insecure) and shared across every target in a scan — baking a target origin into the policy would leak one target's origin into another target's client.

Covered by an end-to-end regression test that asserts the foreign origin receives zero requests and zero credentials, with a same-origin redirect still followed as the control.

Credit

Found internally while auditing the surrounding code after a related report. No external reporter.

Affected versions

References

GitHub · hahwul/dalfox