GHSA-35wr-x7v6-9fv2: Dalfox Server Mode has an Unauthenticated Arbitrary File Read with Out-of-Band Exfiltration via `custom-payload-file`
SummaryWhen dalfox is run in REST API server mode, the `custom-payload-file` field in `model.Options` is JSON-tagged and deserialized directly from the attacker's request body, then propagated unchanged through `dalfox.Initialize` into the scan engine. The engine passes the value to `voltFile.ReadLinesOrLiteral`, which reads lines from any file path accessible to the dalfox process and embeds each line as an XSS payload in outbound HTTP requests directed at the attacker-controlled target URL. Because the server has no API key by default, an unauthenticated network attacker can exfiltrate the contents of arbitrary files on the dalfox host by reading them line-by-line through scan traffic.Severity**High** (CVSS 3.1: 7.5)`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N`**Attack Vector:** Network — server binds to `0.0.0.0:6664` by default; reachable by any network peer.**Attack Complexity:** Low — no preconditions beyond network access; `skip-discovery` and `param` are both attacker-supplied, so the code path is fully under attacker control.**Privileges Required:** None — `--api-key` defaults to `""`, so the auth middleware is not registered.**User Interaction:** None.**Scope:** Unchanged — the file read and the outbound HTTP exfiltration request both originate from the same dalfox process authority.**Confidentiality Impact:** High — the attacker can read any file the dalfox process can open: private keys, configuration files containing database credentials, environment files, `/etc/passwd`, etc.**Integrity Impact:** None — this path is read-only.**Availability Impact:** None.Affected Component`cmd/server.go` — `init()` (line 51): `--api-key` defaults to `""` — no auth by default`pkg/server/server.go` — `setupEchoServer()` (line 68): auth middleware only registered when `APIKey != ""``pkg/server/server.go` — `postScanHandler()` (lines 173–191): `rq.Options` (including `CustomPayloadFile`) passed to `ScanFromAPI` without sanitization`lib/func.go` — `Initialize()` (line 117): `CustomPayloadFile` explicitly propagated from caller options`pkg/scanning/scan.go` — anonymous block (lines 341–368): `voltFile.ReadLinesOrLiteral(options.CustomPayloadFile)` reads file; contents injected into outbound requestsCWE**CWE-306**: Missing Authentication for Critical Function**CWE-73**: External Control of File Name or Path**CWE-552**: Files or Directories Accessible to External PartiesDescription`custom-payload-file` Is Fully Attacker-Controlled`model.Options` exposes `CustomPayloadFile` with a JSON tag:`postScanHandler` binds the entire `Req.Options` from the JSON body and passes it directly to `ScanFromAPI`:`ScanFromAPI` passes `rqOptions` as `target.Options` to `dalfox.Initialize`:`Initialize` explicitly copies `CustomPayloadFile` into `newOptions` with no filtering:File Read and Exfiltration PathIn `pkg/scanning/scan.go`, when the scan engine reaches the custom payload phase, it reads the attacker-specified file path:Each line of the file becomes a payload value embedded in a query parameter of an HTTP request sent to the attacker-controlled target URL. `performScanning` then dispatches every entry in the `query` map via `SendReq`, delivering the file's contents to the attacker's server as the value of the nominated parameter (e.g., `?q=<file-line>`).Condition Is Trivially SatisfiableThe condition `options.SkipDiscovery || utils.IsAllowType(policy["Content-Type"])` is satisfied by setting `skip-discovery: true` in the JSON request body — a field the attacker fully controls. When `SkipDiscovery` is true, the engine also requires at least one parameter via `UniqParam` (the `-p` flag), which the attacker supplies as `param: ["q"]`. The code then hardcodes `policy["Content-Type"] = "text/html"` and populates `params["q"]` automatically:Both conditions are fully attacker-controlled through the JSON request body.No Defense at Any LayerThe same opt-in API key guard from the first finding applies identically here:With the default empty API key, no middleware is installed and every endpoint is unauthenticated. There is no path sanitization, no allowlist, and no `IsAPI` guard around the `CustomPayloadFile` read.Proof of ConceptNo `X-API-KEY` header is required. Replace `/etc/hostname` with any file path accessible to the dalfox process (e.g., `~/.ssh/id_rsa`, `/run/secrets/db_password`, `/proc/self/environ`).Impact**Arbitrary file read** on the dalfox host: any file readable by the dalfox process (SSH private keys, TLS certificates, `.env` files, cloud credential files, `/proc/self/environ`) can be exfiltrated one line at a time.**No authentication required** under the default configuration.The exfiltration channel is the dalfox host's own outbound HTTP scan traffic — no inbound connection from the attacker to the dalfox host is needed beyond the initial REST API call.Combined with the `found-action` RCE finding (separate issue), an attacker could first read `/proc/self/environ` to harvest secrets, then execute commands.Recommended RemediationOption 1: Strip filesystem-dangerous fields from API-sourced requests (preferred)Apply a denylist of fields that should never be accepted from the REST API, regardless of auth state. This protects authenticated deployments against credential-theft or privilege escalation by external API consumers:Option 2: Require `--api-key` at server startupMake authentication mandatory and refuse to start without it:Both options should be applied together. Option 2 prevents unauthenticated access to the API entirely; Option 1 ensures that even trusted API callers cannot leverage the server to read files from the host filesystem.##CreditEmmanuel DavidGithub:- https://github.com/drmingler
CVSS v3.1: 7.5