Skip to content

Commit 69374ef

Browse files
committed
fix(harness): exempt UID:GID explicitly, not by absence of letters
Corrects a credential leak introduced by the previous commit's redaction change, caught on re-review. Exempting a colon-shaped --user value whenever it had no alphabetic character before the colon was wrong in the leaking direction: `tool --user 1234:secret` is a numeric username with a real password, and it stopped being redacted. Verified against the built predicate before and after. The exemption is now exactly what it was meant to be — an all-numeric UID:GID pair (`^\\d+:\\d+$`). `docker run --user 1000:1000` is still preserved as a task detail; `1234:secret` and `alice:secret` both redact. Also corrects the comment above the curl-context fix, which overclaimed. That fix redacts the value ATTACHED to -u; a password passed as a separate following token is not covered, is not specific to the .exe spelling, and the obvious widening would eat the URL operand in the already-tested `curl -u alice https://example.com`. Left open for a human call.
1 parent 7f5385a commit 69374ef

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎packages/opencode/src/session/compaction.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,23 @@ export namespace SessionCompaction {
610610
const rawValue = (separatedValue ?? attachedValue ?? "").replace(/^["']|["']$/g, "")
611611
// Windows invokes curl as `curl.exe`, and either platform may reach it
612612
// through a path such as /usr/bin/curl or a Windows System32 path.
613-
// Missing those spellings left `-u user password` unredacted.
613+
// Missing those spellings left the `-u` VALUE unredacted. Note this
614+
// redacts the value attached to the flag only; a password passed as a
615+
// separate following token is not covered here (see the open review
616+
// thread on this line) and is not specific to the .exe spelling.
614617
const curlContext = /(?:^|[\s/\\])curl(?:\.exe)?(?=\s|$)/i.test(
615618
shellSegmentBefore(whole, offset + lead.length),
616619
)
617-
// Require an alphabetic character before the colon so that genuinely
618-
// non-credential `x:y` literals survive outside a curl context — most
619-
// importantly `docker run --user 1000:1000`, whose UID:GID is exactly
620-
// the kind of task detail the ledger exists to preserve.
621-
const credentialShaped = /^(?=[^:/\s]*[A-Za-z])[^:/\s]+:[^/\s]+$/.test(rawValue)
620+
// Outside a curl context a colon-shaped value is treated as
621+
// user:password. The ONE exemption is an explicitly recognized
622+
// all-numeric UID:GID pair (`docker run --user 1000:1000`), which is a
623+
// task detail the ledger exists to preserve. Exempting by "no
624+
// alphabetic character before the colon" instead would be wrong in the
625+
// leaking direction: a numeric username with a real password
626+
// (`--user 1234:secret`) is a credential and must still redact.
627+
const colonShaped = /^[^:/\s]+:[^/\s]+$/.test(rawValue)
628+
const uidGidPair = /^\d+:\d+$/.test(rawValue)
629+
const credentialShaped = colonShaped && !uidGidPair
622630
if (!curlContext && !credentialShaped) return match
623631
return `${lead}${flag}${separator ?? ""}<redacted>`
624632
},

‎packages/opencode/test/session/compaction-ledger.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,13 @@ describe("SessionCompaction.renderLedger", () => {
434434
expect(credential).not.toContain("dummy-password")
435435
expect(credential).not.toContain("alice")
436436

437+
// A NUMERIC username with a real password is still a credential. Exempting
438+
// by "no alphabetic character before the colon" would leak this, so the
439+
// exemption is specifically an all-numeric UID:GID pair.
440+
for (const command of ["tool --user 1234:dummy-password", "tool -u 007:dummy-password"]) {
441+
expect(SessionCompaction.redactLedgerDetail(command)).not.toContain("dummy-password")
442+
}
443+
437444
// ...and inside a curl context the numeric shape is still redacted,
438445
// because curl's own `-u` is unambiguously authentication.
439446
expect(SessionCompaction.redactLedgerDetail("curl -u 1000:1000 https://example.com")).not.toContain("1000:1000")

0 commit comments

Comments
 (0)