11 KiB
Security audit: R5.5 upload tool, fix commits 56593af and fad85c0
- date: 2026-10-23 | branch
feature/rust-r5-pipeline-core| scopegit diff a481af5..fad85c0 - context read:
crates/core/src/bin/upload_sheet_assets/{main,storage}.rs,crates/core/src/curation/upload.rs,scripts/{upload-sheet-assets,sheet-assets-e2e,floor-clarification-check}.sh,crates/core/tests/upload_tool.rs, contract.claude/tasks/contracts/2026-10-23-rust-r5-upload.md - mode: audit (fresh, blind; no prior verdict used). Nothing was edited but this file.
- not run, by rule:
upload-sheet-assetsagainst any real stack,scripts/sheet-assets-e2e.sh, any service key, any transfer tool, any recursive delete.
What was measured
| Check | Result |
|---|---|
semgrep 1.168.0, p/security-audit + p/secrets + p/owasp-top-ten, 75 rules, 11 files (the 10 diff files + curation/upload.rs) |
0 findings, 0 errors |
guardrails scan.py --domain api,supabase |
0 FAIL, 1 WARN (SB-POLICY-NOT-OWNER, supabase/migrations/20261008110000_anatomical_sheets.sql:1177), outside the diff, dropped |
cargo test --locked -p faunosteo-core --features upload --test upload_tool (loopback stub, made-up key, built without SUPABASE_SERVICE_ROLE_KEY in the env) |
12 passed, 0 failed |
floor-guard.sh develop, then the script's three regexes applied to its output |
22 findings: 21 requalified (SUPPRESS in .claude/audits/*.md), 1 declared (STUB .claude/memory/evals.md:205), 0 remaining |
/proc/sys/net/ipv{4,6}/ip_nonlocal_bind |
0 and 0 |
UDP bind probe (no packet sent) on this host (enp89s0 192.168.1.100/24, brd 192.168.1.255) |
192.168.1.100 OK; 192.168.1.255 OK; 224.0.0.1 OK; 0.0.0.0 OK; 192.168.1.0, 192.168.1.101, 10.255.255.254 refused |
| TCP connect to 192.168.1.255:54321 | refused by the kernel, ENETUNREACH (no SYN leaves) |
new suppressions in added lines (nosemgrep, nosec, eslint-disable, @ts-ignore, noqa, #[allow, shellcheck disable, floor-guard: allow) |
none in code; the only hits are prose in .claude/audits/2026-10-23-rust-r5-upload-security.md |
| tracked env files | .env.example only |
Targeted review of the fixes
Error classification and retry (storage.rs:17, :73-87, :189-214). ATTEMPTS = 4 gives one try and three
retries, sleeps 1.0 s, 1.5 s, 2.0 s, so contract C6 "retried three times" holds. Retried: Io, Timeout,
HostNotFound, ConnectionFailed, Protocol, and a 5xx status. Every other ureq::Error is final.
BodyExceedsLimit maps to a final State refusal: the ureq 3.4.2 LimitReader raises it wrapped in an
io::Error, and From<io::Error> unwraps it back (ureq-3.4.2/src/error.rs:216-227), so the guard does fire. The
test upload_tool.rs:319 proves it, with exactly one object GET and no write. A retried POST stays safe, because
x-upsert: false turns a replay into a 409 handled as a duplicate and the object is then re-hashed. A retried
confirm is server-idempotent. Secret exposure: the final branch prints only a fixed text or the numeric limit. The
retried branch prints error.to_string(). For Io, Timeout and Protocol that text carries no header value:
ureq-proto's BadHeader holds the http::Error text, not the value, and BadAuthorizationHeader has no payload
(ureq-proto-0.6.4/src/error.rs:45-53). Request analysis also runs before the prelude is written
(client/sendreq.rs:42), so a refused key never reaches the wire. The fix is a strict improvement: before it,
Http, BadUri, TooManyRedirects and the rest were echoed and retried. One residual inaccuracy is listed as L1.
DEV-address ownership (main.rs:112-124). UdpSocket::bind((ip, 0)) sends nothing and is closed on drop. It
runs before the key is read, and check_destination still requires a private IPv4 equal to the DEV host
(upload.rs:190-200). Unspecified and multicast addresses bind but are not private, so they stay refused. The
directed broadcast of an attached private subnet passes, but the kernel refuses the TCP connection. The test
upload_tool.rs:342 discriminates: without the filter the run would reach the network (exit 3), not a
Destination refusal (exit 1). Residuals: L2.
Keys off every argv in the e2e script (sheet-assets-e2e.sh:18-32). The key reaches the binary only through a
prefix assignment inside the $(...) subshell (env, not argv). The leak check feeds the patterns to
grep -f <(printf ...): printf is a builtin, and grep's argv holds only /dev/fd/N. The keys come from the
status JSON on stdin; the python3 -c argv carries only the field name. env -u SUPABASE_SERVICE_ROLE_KEY cargo build puts the variable name on argv, never its value. Dropping env -i lets the binary inherit the caller's env.
This is no exposure: the tool reads only SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, FAUNOSTEO_DEV_HOST and
INIT_CWD (the last two are unset there), it uses proxy(None), and the crate has no logger. An empty key or
status field would put an empty pattern into -f, which matches every output. That fails the case: fail-safe.
Launcher (upload-sheet-assets.sh:15-16). Under set -euo pipefail, a failed build stops the script before
the exec. Cargo, build scripts and proc macros no longer see the key. Only the exec'd binary receives it, in its
environment, with the folder and --check as its only argv. Residual: L3.
FLOOR declared line (floor-clarification-check.sh:16, :23-27). DECLARED_RE is anchored and covers one
kind, one file and one line, with the dots escaped and a trailing space, so :2050 cannot match. On the branch it
matches exactly the one line the R5.4 contract names (2026-10-23-rust-r5-review.md:69). Nothing else is
requalified, requalified does not count it, and it is printed under DECLARED. The negative proof still fails
(real SUPPRESS in src/*.ts, src/*.rs and an active contract). Residual: L4.
Findings
No CRITICAL, no HIGH, no MEDIUM, no new ungated suppression.
- L1
storage.rs:196(with:200-202):Protocol(_)counts as transient. That bucket also holds deterministic local failures:BadAuthorizationHeaderfor a key with non-ASCII bytes (thehttpcrate accepts bytes 0x80 and up in a value, ureq-proto'sto_strrefuses them),OutputOverflowfor a huge key, andHttpParseFailfor a malformed answer. Each is retried three times and ends asNetwork, exit 3. Thefinal_errordoc comment says "a key a header refuses, a malformed answer" are final, which is only true for control characters (Http). This costs about 4.5 s and a wrong exit code, and nothing is sent or printed. Hint: makeProtocolfinal, or retry only its response-side variants, and correct the comment. - L2
main.rs:112-115: the bind probe also accepts the subnet broadcast (measured: 192.168.1.255). WithFAUNOSTEO_DEV_HOST=192.168.1.255andSUPABASE_URL=http://192.168.1.255:54321, the destination check passes, the kernel refuses the TCP connection (ENETUNREACH, measured), the key is never sent, and the run endsNetworkinstead ofDestination. The probe also degrades to "any private IPv4" on a host withip_nonlocal_bind=1(0 here). Hint: after the bind,connect((ip, port))the UDP socket (sends nothing; a broadcast gives EACCES, measured) and requirelocal_addr().ip() == ip, and document the sysctl dependency. - L3
upload-sheet-assets.sh:15-16andsheet-assets-e2e.sh:15,18: the binary pathtarget/release/...is hard-coded, but cargo honoursCARGO_TARGET_DIR,CARGO_BUILD_TARGETand a userbuild.target-dir. If any is set, the build lands elsewhere and the scriptexecs a stale binary, possibly pre-fix, with the service key in its environment (or a missing one). None is set on this machine (measured; no~/.cargo/config.toml, and the workspace.cargo/config.tomlhas no target dir). Hint:env -u CARGO_TARGET_DIR -u CARGO_BUILD_TARGETon the build, or take the path fromcargo build --message-format=json. - L4
floor-clarification-check.sh:16: the exemption is pinned by line number, not content. If a/prune-memoryrewrite puts another STUB onevals.md:205, that STUB is silently exempt, while the original finding fails loudly. The negative proof has noevals.md, so the regex's narrowness is proven only by reading. Since this change, the script prints OK while the finding waits for the owner's decision. That is a quality-gate question for the verifier and has no security effect. Hint: also match the snippet prefix (Anomalies: LOW report.rs), and add a proof case with a STUB on anotherevals.mdline. - L5
upload_tool.rs:346-347: the "not this machine" address 10.255.255.254 is the one WSL2 assigns tolo. On such a host the test would connect locally with the made-up key and fail with exit 3. This is a portability nit (fail-loud) with no exposure. Hint: use a TEST-NET address (192.0.2.1 is not private, so pick a private address checked to be non-local at run time).
Context only, outside the diff, not counted: supabase/config.toml sets no jwt_secret (only jwt_expiry at
:89). The local stack therefore likely signs with the CLI's public default secret, and port 54321 is open to the
LAN by design (CLAUDE.md "Environments and LAN access"). Anyone on the LAN who knows the public default
service_role JWT would then hold service_role on the local stack, which makes the tool's key secrecy moot there. I
did not verify this against the running stack. The diff's RUST.md text names the same point.
Verdict block
SECURITY — VERDICT: PASS
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
SCOPE: 11 files (10 in a481af5..fad85c0 + crates/core/src/curation/upload.rs read as context)
BLOCKING:
(none)
REPORTED (non-blocking):
- [LOW] retry-classification (Protocol treated as transient, doc comment overstates finality) — crates/core/src/bin/upload_sheet_assets/storage.rs:196
- [LOW] dev-address-probe (subnet broadcast binds; relies on ip_nonlocal_bind=0) — crates/core/src/bin/upload_sheet_assets/main.rs:112
- [LOW] stale-binary-exec (hard-coded target/release vs CARGO_TARGET_DIR) — scripts/upload-sheet-assets.sh:16, scripts/sheet-assets-e2e.sh:15
- [LOW] floor-declared-line (pinned by line number; no negative proof for DECLARED_RE) — scripts/floor-clarification-check.sh:16
- [LOW] test-portability (10.255.255.254 is lo on WSL2) — crates/core/tests/upload_tool.rs:346
PROOF: semgrep 75 rules on 11 files → 0 findings; checklist 9 checks (secrets, SQL concat, unsafe render, authz, error exposure, secret in log, tracked .env, guardrails, new suppressions) + 5 targeted fix reviews → 5 findings (all LOW); cargo test upload_tool 12/12 green; floor classification 22 → 21 requalified, 1 declared, 0 remaining