Skip to content

Commit a9e648f

Browse files
sepo-engopencodeclaude
authored
fix(config): reverse the readTarget raw-secret decision -- always redact (TKT-323, feedback anomalyco#191) (#32)
* fix(config): reverse the readTarget raw-secret decision -- always redact (TKT-323, feedback anomalyco#191) REVERSES a documented decision, not a routine leak patch. document.ts:88-89 (now rewritten) argued readTarget's raw text needed to stay byte-real for the direct-file-editing escape hatch, or a patch computed against a redacted view would corrupt a secret on write. That concern is refuted by the shipped write model: applyPatch never serializes text wholesale -- Patch is a typed, allowlisted field-op union applied against text the server re-reads itself, so an unedited field is simply absent from the patch and never written back. No consumer of readTarget's real secret values existed (enumerated in parallel with the fix). Confirmed live before any severity was assumed: a real secret (mcp.servers.*.environment.KEY) round-tripped verbatim through readTarget while the sibling effective() correctly redacted the identical value, same protocol group, same request shape. The rule now: every API read response is unconditionally redacted -- readTarget, effective, validatePatch's preview, every future *.catalog.list. There is no operation that reveals a real secret value over the API; the escape hatch is editing the config file on disk directly. Reversible by addition (a future explicit reveal-op), never by weakening the default -- see FORK.md's decision record. Corollary: applyPatch now rejects (RedactedValueRejectedError -> 400) a patch that would write the literal "[redacted]" sentinel over a secret field -- a read-then-write UI that never touched the real value must not silently overwrite it. Only safe to enforce now that readTarget never returns a real value to accidentally echo back. mcpSecretPaths is the one shared allowlist the object redactor, the raw-text redactor (via jsonc-parser's own modify/applyEdits, the same mechanism applyPatchToText already uses -- not a blind string search-replace), and the write-time rejection check all read, so a future secret-shaped field extends one list instead of three. Pinning test at document.test.ts (previously asserting the real values WERE present in readTarget, on purpose, per the now-reversed rationale) is inverted to assert them absent and placeholders present, with the reason recorded in its name and a comment. Build post's migration step 9 (the "escape hatch...always show the selected source document" line) is clarified in the same change: through the same redacted read API, not an unredacted response. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * fix(config): address Copilot review findings on #32 - readTarget: derive the mcp-secret paths for text redaction from jsonc-parser's own lenient parse, not parseAndDiagnose's diagnostics-gated `parsed`. An unrelated syntax error anywhere in the document was zeroing `parsed` entirely, which fell through to `mcp === undefined` and returned the raw, unredacted text -- the exact leak this PR exists to close, reachable through a second path. Added a regression test, confirmed red pre-fix / green post-fix. - config-document handler: InvalidRequestError.field was set to the target ID (a value), not a stable field name -- misleading for a client trying to locate the invalid input. Moved the ID to `kind` and set `field: "patch"`, matching the existing convention in handlers/session.ts. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * docs(fork): flip the "no automated review" section to the new truth Sean enabled a Copilot Review ruleset on this fork (id 20729187) the same session this PR was open. Its first real firing was on this PR -- two genuine findings, both fixed above -- which settles the question the old "No" section answered with evidence that has since gone stale. Retains the original finding as a collapsed historical record rather than deleting it, since the "assume no review runs" convention it backed was cited by name across every ticket in this tree. Adds the wrong-base caveat from the same process update: a branch cut from a branch (not from dev directly) silently inherits that branch as its PR base unless --base is passed explicitly, and a wrong-based PR gets no automated review. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * fix(config): fail closed on unparseable documents, per lead ruling Supersedes 78be611's lenient-parse fix for the same Copilot-flagged hole. A lenient recovery parse can itself silently DROP the secret-bearing branch when a malformed region swallows it -- the redactor would then see no secrets while the raw text still carries them byte-for-byte. A guarantee conditional on how badly the file is broken is not a guarantee. readTarget now withholds `text` entirely when the document has any parse diagnostic, returning a named RedactionWithheld({reason: "could-not-parse"}) citizen instead of a best-effort redaction -- same pattern as McpRuntime's truthful unavailable default (TKT-323 chunk 2), never an implicit fallback. The escape hatch for a broken config is editing it on disk directly, already the rule for every other read path; the diagnostics already returned are the fix-it information. Both regression tests flipped from asserting a redacted `text` to asserting a withheld one, and the pre-existing malformed-jsonc fixture gains a real secret so this leak class can never return silently again. Confirmed red against the reverted code, green against the fix. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * fix(config): redactParsed must not reshape an array-rooted document Copilot review finding on PR #32 (Suppressed comments section): the typeof/null guard alone lets an array through -- typeof [] === "object" and [] !== null -- so Object.fromEntries(Object.entries(...)) silently turned an array-rooted document into a plain object with numeric string keys, beyond the intended mcp redaction. Excludes arrays explicitly; `parsed` now mirrors the real document shape. Regression test confirmed red pre-fix, green post-fix. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * chore(client): regenerate after RedactionWithheld protocol change The check:generated CI guard caught this correctly on its first real protocol change since the last audit -- packages/client/src/generated was never regenerated after ReadTarget.text widened to string | RedactionWithheld in 97011af. Regenerated via bun run --cwd packages/client generate; the only diff is the expected type widening on ConfigDocumentTargetReadOutput.text. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 --------- Co-authored-by: opencode <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
1 parent d3710b1 commit a9e648f

8 files changed

Lines changed: 457 additions & 73 deletions

File tree

‎FORK.md‎

Lines changed: 122 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,63 @@ been reconciled, not just what is currently outstanding.
9999
script exits 0, no content ever gets written) rather than producing bad content, after 6+ resume
100100
rounds over ~2.5h. See feedback #182 for the full per-locale evidence and fix-forward.
101101

102+
## Decision reversal: `readTarget` is always redacted, no raw-secret escape hatch (TKT-323, feedback #191)
103+
104+
**Chunk 1 shipped `readTarget` (`GET /api/config/document/target/:targetID`) returning MCP secrets
105+
in the clear — `text` (raw file) and `parsed` (that raw text parsed), neither passing through the
106+
redactor `computeEffective` already used on the sibling `effective()` endpoint, same protocol
107+
group.** Confirmed live: a config with `mcp.servers.<name>.environment.<KEY> = <real secret>`
108+
returned that exact value verbatim from `readTarget`, and `[redacted]` from `effective()`, same
109+
request shape, same secret. Filed as feedback #191, verified before any severity was assumed
110+
(Henry's design note read the code; the live-request confirmation — real secret in, real secret
111+
out — is what turned the reading into a ruling).
112+
113+
**The original rationale, reversed.** `document.ts`'s own comment (pre-fix) argued the
114+
direct-file-editing escape hatch needed `readTarget`'s raw text to stay byte-real, or a patch
115+
computed against a redacted view would corrupt the file's real secret values on write. That
116+
concern does not hold against the shipped write model: `applyPatch` never serializes text
117+
wholesale — `ConfigDocument.Patch` is a typed, allowlisted union of field operations
118+
(`mcp.server.set`/`mcp.server.remove`), applied against text the **server re-reads itself**. A
119+
field the client did not edit is simply absent from the patch and is never written back. An editor
120+
working from a redacted display view cannot corrupt a secret it never saw, through any shipped
121+
endpoint. No consumer of `readTarget`'s real secret values existed at the time of the fix (Henry
122+
enumerated call sites in parallel with the verification).
123+
124+
**The rule now:** every API read response — `readTarget`, `effective`, `validatePatch`'s
125+
`preview`, every future `*.catalog.list` — is unconditionally redacted. There is no operation that
126+
reveals a real secret value over the API. **The escape hatch is editing the config file on disk
127+
directly**, not an API response; the build post's migration step 9 is clarified to say so
128+
explicitly, since "always show the selected source document" read ambiguously against "secret
129+
values are write-only and redacted in read responses" otherwise.
130+
131+
**Corollary shipped in the same fix:** `applyPatch` rejects (`RedactedValueRejectedError`, mapped
132+
to `InvalidRequestError`, 400) a patch that would write the literal sentinel `"[redacted]"` over a
133+
secret field. Without this, a UI that reads a redacted value, never touches it, and patches the
134+
field straight back would silently persist the sentinel as the real secret — indistinguishable
135+
from a successful save until the integration stops authenticating. Only meaningful now that
136+
`readTarget` never returns a real value for a client to accidentally echo back; it was unsafe to
137+
add before the leak was fixed (nothing prevented a real value from round-tripping correctly, so a
138+
sentinel check would have been the only thing rejecting a legitimate value that happened to equal
139+
the placeholder string by coincidence — vanishingly unlikely, but the ordering matters).
140+
141+
**Reveal-op path back, if one is ever explicitly authorised.** This reversal does not foreclose a
142+
future "reveal" capability — it is reversible by addition, not by weakening the default. A
143+
dedicated, explicitly-authorized operation (its own audit trail, its own authz check, never bundled
144+
into a general read path) could still return a real secret value on request. Nothing in this fix
145+
prevents adding one later; it only ensures no *existing* read path does it implicitly. If one is
146+
ever built, it must not reuse `readTarget`'s response shape for it — a field that is sometimes
147+
real and sometimes redacted, on the exact same endpoint, is the ambiguity this fix exists to
148+
remove.
149+
150+
**Mechanical mitigation for the next secret-shaped field** (chunk 3 adds plugin and profile config
151+
shapes): `mcpSecretPaths` in `document.ts` is the one enumeration every redaction path shares —
152+
the object redactor, the raw-text redactor, and the write-time sentinel check all read the same
153+
list rather than three independently maintained ones. A new secret field still requires someone to
154+
remember to extend it; the allowlist stays hand-written by design (chunk 1's own choice, to avoid
155+
a key-name scrubber that both misses fields like `client_secret` and over-redacts innocent ones),
156+
but at least a change to it now fixes read, preview, *and* write-rejection in one place instead of
157+
three.
158+
102159
## PR conventions
103160

104161
- **Vertical slices, package boundaries preserved.** Follow the dependency direction in the build
@@ -131,9 +188,12 @@ been reconciled, not just what is currently outstanding.
131188
- **Every PR carries its validation dossier** per the validation post: invariants touched,
132189
fixtures exercised, crash/differential/browser cases added as applicable, performance budget
133190
before/after where relevant, and compatibility paths retained plus their removal condition.
134-
- **No automated review runs on fork PRs** (see "Does automated review run on fork PRs?" below —
135-
confirmed, with evidence, as of TKT-305). Say so explicitly in every PR and report — local
136-
per-package tests are the gate, and an absence of review comments is not evidence of a clean diff.
191+
- **Automated (Copilot) review runs on fork PRs as of 2026-08-11** (see "Does automated review run
192+
on fork PRs?" below — ruleset `20729187`, first real firing on TKT-323/#191/PR #32 caught two
193+
genuine findings). Pass `--base dev` explicitly at PR-open — a wrong-based PR gets no review,
194+
silently — and confirm the review actually fired before treating its absence as a clean diff.
195+
It runs alongside peer review, not instead of it; local per-package tests remain the primary
196+
gate underneath both.
137197
- **LLM-generated source is checked like source, not trusted like data.** A `script/translate-app.ts`
138198
batch (TKT-314) wrote a syntax error into one locale file out of 63 — a smart quote opened a
139199
string, a plain ASCII quote closed it, breaking the literal — invisible on read, and it segfaulted
@@ -466,35 +526,70 @@ host is linux/aarch64, so `unit (windows)` and `e2e (windows)` are dropped from
466526
matrices rather than burning GitHub-hosted minutes for a platform this runner can't serve.
467527
Revisit when GH-hosted minutes reset or a Windows runner exists elsewhere.
468528

469-
## Does automated review run on fork PRs? — No.
470-
471-
Answer, with evidence, for the standing "assume no review runs" convention already baked into
472-
every ticket in this tree:
473-
474-
1. **Nothing runs automatically on PR open.** There is no branch protection (`GET
475-
.../branches/dev/protection` → 404) and no rulesets (`GET .../rulesets` → `[]`) on this repo —
476-
unlike the workspace repo's Copilot-review ruleset. `.github/workflows/review.yml` is the only
477-
review-shaped workflow, and it triggers on `issue_comment: [created]` gated to comments
478-
starting with `/review` from an `OWNER`/`MEMBER` author — never on `pull_request` itself.
529+
## Does automated review run on fork PRs? — Yes, as of 2026-08-11.
530+
531+
**Superseded 2026-08-11 (TKT-323, feedback #191, PR #32).** The "No" answer below stood on real
532+
evidence (no branch protection, no rulesets, `/review` non-functional) and misled nobody while it
533+
was true — but it went stale the moment Sean funded GH Actions and enabled a Copilot Review
534+
ruleset on this fork (id `20729187`, active, on the default branch), and it sat as a stale "No"
535+
for one night before this update, which is its own lesson: a "does X run" answer needs to be
536+
re-verified before being relied on, not just cited.
537+
538+
**Current state, confirmed by the mechanism's first real firing:** PR #32 (the readTarget
539+
redaction reversal — itself a security fix) triggered an automatic Copilot review with **two
540+
inline findings, both real, both fixed**:
541+
1. A second, independent leak path in the same redaction logic PR #32 was fixing — `readTarget`'s
542+
secret-path lookup keyed off a `parsed` value that gets discarded on *any* unrelated JSONC
543+
diagnostic, so a config file with a syntax error elsewhere but a real mcp secret still leaked
544+
the secret in raw text.
545+
2. `InvalidRequestError.field` set to a target ID (a value) instead of a stable field name,
546+
inconsistent with the convention used elsewhere in the handler layer.
547+
548+
Both were caught on the review's first live PR, before merge, on a security-sensitive diff our
549+
own process had already run through the full `/work` §6/§10 validation pass. **This retires the
550+
"treat review as absent" convention everywhere it was cited** (see "Not yet running…" note above,
551+
§ "No automated review runs on fork PRs").
552+
553+
**Review process now:** Copilot review (automatic, runs on PR open and on every push to an open
554+
PR) **plus** peer review, same as before — Copilot does not replace a human reviewer, it runs
555+
alongside one, per `/work` §6.
556+
557+
**Caveat — the wrong-base footgun:** a branch cut from another feature branch (rather than from
558+
`dev` directly) silently inherits that branch as its PR base unless `--base` is passed explicitly
559+
at PR-open. A PR opened against the wrong base gets **no automated review** — the ruleset is
560+
scoped to PRs targeting the default branch. Always pass `--base dev` explicitly when opening a PR
561+
here, and confirm the review actually fired (not just that CI ran) before treating its silence as
562+
a clean diff — an absent review on a wrong-based PR looks identical to an absent review on a
563+
genuinely quiet one.
564+
565+
---
566+
567+
<details>
568+
<summary>Original "No" finding, for the historical record (superseded above, evidence retained)</summary>
569+
570+
Answer, with evidence, for the (now superseded) "assume no review runs" convention:
571+
572+
1. **Nothing ran automatically on PR open**, as of this writing. There was no branch protection
573+
(`GET .../branches/dev/protection` → 404) and no rulesets (`GET .../rulesets` → `[]`) on this
574+
repo — unlike the workspace repo's Copilot-review ruleset. `.github/workflows/review.yml` was
575+
the only review-shaped workflow, and it triggered on `issue_comment: [created]` gated to
576+
comments starting with `/review` from an `OWNER`/`MEMBER` author — never on `pull_request`
577+
itself.
479578
2. **`pr-standards.yml` and `pr-management.yml` are compliance bots, not code review.** They check
480579
PR title format (conventional-commit prefix), template-section presence, linked-issue
481580
presence, and duplicate-PR detection — labels and comments only, no line-level code
482581
feedback.
483-
3. **Even the manual `/review` trigger is currently non-functional on this fork, for two
484-
independent reasons:**
485-
- Its job (`check-guidelines`) is `runs-on: blacksmith-4vcpu-ubuntu-2404` — same queued-forever
486-
problem as above. **Left un-retargeted deliberately**: fixing the runner alone would not
487-
make it work (see next point), and provisioning secrets is not a worker-level fix.
582+
3. **Even the manual `/review` trigger was non-functional on this fork, for two independent
583+
reasons:**
584+
- Its job (`check-guidelines`) was `runs-on: blacksmith-4vcpu-ubuntu-2404` — same
585+
queued-forever problem as above.
488586
- `OPENCODE_API_KEY` (the secret the review step needs to actually invoke the opencode agent)
489-
is not configured on this repo — `gh secret list --repo Draugur-AI/opencode` and `gh
490-
variable list --repo Draugur-AI/opencode` both return empty. The step would fail on
491-
missing credentials even if the runner picked it up.
492-
493-
**Conclusion: treat review as absent on every fork PR, full stop, exactly as the standing
494-
per-ticket convention already says.** Local per-package tests (the merge gate below) are
495-
the actual quality gate. If `/review` is ever wanted, it needs both a runner-label fix (same
496-
one-line pattern as `typecheck.yml`) *and* an operator-provisioned `OPENCODE_API_KEY` secret —
497-
neither is done here.
587+
was not configured on this repo.
588+
589+
Local per-package tests (the merge gate below) remain the primary quality gate; Copilot review is
590+
now an additional layer on top, not a replacement for them.
591+
592+
</details>
498593

499594
## PR hygiene: the compliance bot and the 2-hour auto-close
500595

‎packages/client/src/generated/client.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ export function make(options: ClientOptions) {
13341334
query: { location: input["location"] },
13351335
body: { expectedHash: input["expectedHash"], patch: input["patch"] },
13361336
successStatus: 200,
1337-
declaredStatuses: [404, 409, 401, 400],
1337+
declaredStatuses: [404, 409, 400, 401],
13381338
empty: false,
13391339
},
13401340
requestOptions,

‎packages/client/src/generated/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3952,7 +3952,7 @@ export type ConfigDocumentTargetReadOutput = {
39523952
readonly path: string
39533953
readonly exists: boolean
39543954
}
3955-
readonly text: string
3955+
readonly text: string | { readonly reason: "could-not-parse" }
39563956
readonly hash: string
39573957
readonly parsed: JsonValue
39583958
readonly diagnostics: ReadonlyArray<{

0 commit comments

Comments
 (0)