loopx icon indicating copy to clipboard operation
loopx copied to clipboard

[Bug]: public-safe-outbound scan reports a UTF-16 PowerShell log as clean, so private paths and credentials pass the pre-publication gate

Open JasonBuildAI opened this issue 1 month ago • 0 comments

Preflight

  • [x] I searched existing issues and discussions for this behavior.
  • [x] This report is not an unpatched security vulnerability.
  • [x] The report and attachments contain no credentials or private/internal material.

Issue origin

Reproduced in a real environment (native Windows 11, CPython 3.14.3).

LoopX version or commit

main at 2236b1473c56dab2a8670922dcb27e1fb140c757 (LoopX 2.1.0 line). The scanner has been unchanged since #7247.

Host or runtime surface

Not host-specific: the builtin public-safe-outbound capability and its loopx check --scan-path caller.

LoopX area

Capability or extension (providers, adapters, skills).

Problem

The public-safe-outbound scanner reads every candidate file as UTF-8 and reports a file whose bytes are not UTF-8 as clean. On Windows, Windows PowerShell 5.1 writes > and Out-File output as UTF-16LE with a BOM by default, so a captured log/transcript that contains a private home path and a Bearer token passes the pre-publication gate with ok=true and exit code 0.

This is the builtin capability's own file scanner (scanner.scan_paths, invoked through scan_cli), documented in the capability README and catalog entry. The separate loopx check --scan-path contract scanner fails closed on non-UTF-8 input and is not the affected path; it also does not decode UTF-16 to find hits. This scanner has already been hardened three times for adjacent silent-pass classes (#6428 unreadable content/config, #6476 unlistable directories, #7247 Windows private-path variants). A non-UTF-8 encoding is the same class: content the scan could not read is reported as content that is safe.

Minimal reproduction

From a source checkout on native Windows (PowerShell 5.1 is the default powershell.exe):

$repo = "D:\work\scan-repro"

New-Item -ItemType Directory -Force "$repo\logs" | Out-Null

$content = "private=C:\Users\example-user\.ssh\id_rsa`r`nAuthorization: Bearer abcdefghijklmnopqrstuvxyz`r`n"

# Windows PowerShell 5.1 defaults to UTF-16LE with a BOM:

[System.IO.File]::WriteAllText("$repo\logs\session.log", $content, [System.Text.Encoding]::Unicode)

# Same content as UTF-8, for the control:

[System.IO.File]::WriteAllText("$repo\logs\utf8-session.log", $content, (New-Object System.Text.UTF8Encoding($false)))



cd $repo

python -m loopx.capabilities.public_safe_outbound.scan_cli --scan-root .

Observed with both files present (before deleting the UTF-8 control):

{"hit_count": 2, "hits": [{"label": "sk-/Bearer secret", "line": 3, "location": "logs/utf8-session.log", "rule_id": "sk_bearer", "sample_masked": "***"}, {"label": "private absolute path", "line": 2, "location": "logs/utf8-session.log", "rule_id": "private_abs_path", "sample_masked": "***"}], "ok": false, ...}

Observed with only the UTF-16LE file:

{"hit_count": 0, "hits": [], "ok": true, "schema_version": "public_safe_outbound_scan_v0", "unscanned_count": 0, "unscanned_reasons": []}

Exit code 0. The same bytes decoded with the correct codec produce both hits:

utf16 file: {'ok': True, 'hit_count': 0, 'unscanned_count': 0}      # scan_paths()

utf8 text:  {'ok': False, 'hit_count': 2}                            # scan_texts() on the same content

Expected behavior

  • A BOM-marked UTF-16/UTF-32 candidate is decoded with its declared codec before the rules run, so its private paths and credentials are detected.
  • Any candidate whose bytes still cannot be confidently decoded as text is reported as unscanned and keeps ok=false, rather than reading as clean.

Actual behavior

scan_paths calls Path.read_text(encoding="utf-8", errors="replace") for every file. UTF-16LE content becomes NUL-interleaved mojibake, no rule matches, and the receipt is ok=true with an empty unscanned list — a silent false clean.

Who is harmed and how much

  • Every contributor who captures Windows PowerShell evidence (the default shell on supported Windows versions) and then runs the capability's documented scan_cli pre-publication scan: the scan certifies content it never actually read.
  • Scope limit: scan_cli is a shipped, default-enabled builtin capability, but the separate contributor loopx check --scan-path gate already fails closed on non-UTF-8 input. The affected path is a caller who chooses the capability scan; no external report of an actual leak exists yet.
  • Private home paths, internal links, Bearer/sk- credentials and API-key assignments in those captures can then be committed into a public repository or PR description. This is exactly the disclosure the capability exists to prevent, and the project treats public/private boundary violations as release-blocking.
  • The failure is deterministic for every UTF-16 input (not a sampling or timing edge): the receipt has unscanned_count: 0, so the caller has no signal that the file was not reviewed.
  • Affected versions: every release and main since the capability shipped (#3438); the scanner path is unchanged since #7247.

Additional context

  • scan_paths already fails closed for unreadable files (content_unreadable) and oversized files (content_too_large), and scan_cli fails closed for unwalkable roots. UTF-16 is not in that set.
  • BINARY_SUFFIXES does not exclude .log/.txt/.md/extensionless files, so --scan-root reaches them.
  • No other issue or PR covers the encoding gap; the nearest work is the private-path variant series #6223 → #7247.

AI disclosure: this report was prepared with AI assistance at the account owner's direction. The reproduction commands and outputs above were executed in this environment; the owner set the contribution constraints and will review any follow-up change.

JasonBuildAI avatar Oct 27 '26 08:10 JasonBuildAI