Skip to content

feat(#301): redact sensitive env values from surfaced adapter stderr - #305

Merged
jflowers merged 7 commits into
unbound-force:mainfrom
jflowers:opsx/redact-env-values-from-adapter-stderr
Oct 31, 2026
Merged

jflowers merged 7 commits into
unbound-force:mainfrom
jflowers:opsx/redact-env-values-from-adapter-stderr

Conversation

@jflowers

Copy link
Copy Markdown
Collaborator

Summary

Defense-in-depth secret redaction for AI-adapter stderr (issue #301, follow-up
from PR #300 review of the config-as-secret pattern).

runSubprocess — the single choke point shared by all three subprocess AI
adapters (claude, gemini, opencode) — now scrubs surfaced child stderr against
sensitive inherited env-var values before embedding them in error messages:

  • A value is scrubbed when its env-var name contains KEY, TOKEN, SECRET,
    or CONFIG_CONTENT (case-insensitive) or reaches 32 bytes regardless of name
  • Values under 4 bytes are never replaced (garble guard); identical values
    dedupe first-name-wins
  • Replacement runs longest-value-first; environ entries split at the first =
    so JSON/base64 values redact whole
  • Scrubbed values become [REDACTED:<VAR>] markers that name the variable,
    keeping errors diagnosable
  • Redaction precedes the 512-byte stderr truncation on every path, so a secret
    straddling the boundary cannot leak a prefix
  • Both surfacing paths (non-zero-exit error embed and empty-output stderr
    suffix) carry scrubbed content; the environment remains pure passthrough

New internal/aireport/redact.go (pure helper) with table-driven unit tests
(redact_test.go) and subprocess integration tests (subprocess_test.go, via
t.Setenv + child echo, including the truncation-boundary straddle case).

Docs: "Secret hygiene and stderr redaction" subsection in
docs/guides/ci-integration.md (second-secret masking pattern, single-line
strict-JSON secret guidance) plus a redaction note in the ai-reports
troubleshooting bullet.

Review gates (from /uf.unleash): spec review APPROVE WITH ADVISORIES
(5/5 reviewers); code review APPROVE WITH ADVISORIES (0 CRITICAL,
0 HIGH; 2 MEDIUM + 7 LOW advisory-grade findings — the 2 MEDIUM items are
carried in Known Issues below as non-blocking advisories).

Closes #301

How to Test

  1. go test -race -count=1 -short ./internal/aireport/... — runs the
    table-driven redactEnvValues unit tests and the three subprocess
    integration tests: TestRunSubprocess_NonZeroExitRedactsSensitiveEnvValue,
    TestRunSubprocess_EmptyStdoutSurfacesRedactedStderr, and
    TestRunSubprocess_RedactsSecretStraddlingTruncationBoundary
    (the scrub-before-truncation invariant).
  2. CI parity: go build ./..., golangci-lint run, full
    go test -race -count=1 -short -timeout 15m -coverprofile=coverage.out ./...,
    and openspec validate redact-env-values-from-adapter-stderr (expected:
    only the originating_issue metadata advisory).
  3. Manual behavioral check: with a *KEY*-named env var holding an obviously
    fake secret, run gaze report --ai=opencode against a failing or
    empty-output adapter invocation — the surfaced error contains
    [REDACTED:<VAR>] markers instead of the value, while surrounding
    diagnostic text survives.
  4. Read the new "Secret hygiene and stderr redaction" subsection in
    docs/guides/ci-integration.md (Reusable Workflow section) for the
    second-secret masking pattern and single-line strict-JSON secret guidance.

How to Demo

# with a deliberately fake secret in a *KEY*-named env var, point the
# report at a failing/empty-output adapter invocation:
MY_API_KEY="obviously-fake-secret" gaze report --ai=opencode
# surfaced error shows [REDACTED:MY_API_KEY] instead of the value;
# surrounding diagnostic text survives untouched

The test suite in How to Test step 1 is the verifiable demo of the invariant.

Key Files Changed

Area Files
Core redaction internal/aireport/redact.go (new, +126), internal/aireport/adapter.go (+33)
Tests internal/aireport/redact_test.go (new, +211), internal/aireport/subprocess_test.go (+107)
Docs docs/guides/ci-integration.md (+55), docs/guides/ai-reports.md, AGENTS.md
OpenSpec change openspec/changes/redact-env-values-from-adapter-stderr/ (proposal, design, spec, tasks, .openspec.yaml)
Retrospective .uf/dewey/learnings/ (14 learning files), .gitignore (+3)

26 files changed, +1201 / −4.

Known Issues

Non-blocking advisories from code review (both documentation-precision
items, suited to this PR or a follow-up):

  • MEDIUM — design.md Non-Goals should record the deliberate
    stdout-not-scrubbed decision with rationale
  • MEDIUM — docs/architecture/extending.md helper-contract bullets
    predate the redaction behavior

Website docs tracked at unbound-force/website#346.

This PR was generated by /uf.finale (AI-assisted).

@jflowers jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Council Verdict: APPROVE WITH ADVISORIES

6 of 7 dispatched Divisor reviews completed successfully; 1 (divisor-gaze-testing) failed with a retryable infrastructure error (child_prompt_failed) and cast no vote — test-quality coverage was provided by the host-fallback divisor-testing reviewer (APPROVE). Among the completed reviews: 4 APPROVE WITH ADVISORIES, 2 APPROVE, 0 REQUEST CHANGES.

Consolidated findings: 0 CRITICAL / 0 HIGH / 2 MEDIUM / 3 LOW (5 unique after deduplicating 10 raw findings). All are documentation and process items — no code changes requested. Both MEDIUM findings concur with advisories already acknowledged in the PR description under "Known Issues".

Finding not on the diff

  • [MEDIUM] docs/architecture/extending.md:300-301 — the "Key helpers available" contract bullets for runSubprocess ("stdout/stderr capture, output size limiting, and error formatting") and formatStderrSuffix ("truncation at 512 bytes") still describe pre-redaction behavior. Extension authors reading this contract won't learn that surfaced stderr is now scrubbed of sensitive inherited env-var values (redactEnvValues, [REDACTED:<VAR>] markers) before truncation, on both surfacing paths. Recommend updating the two bullets to include env-value redaction. (Found by adversary, architect, curator, and guard; concurs with advisory (b) in the PR body.)

Inline findings

Four advisory findings are posted inline on the diff:

Severity Location Summary
MEDIUM openspec/changes/redact-env-values-from-adapter-stderr/design.md:40 Deliberate stdout-not-scrubbed exclusion unrecorded in Non-Goals
LOW openspec/changes/redact-env-values-from-adapter-stderr/tasks.md:16 [P] marker on a compile-dependent task
LOW .gitleaksignore:1 Gitleaks suppression rationale missing from proposal Impact list
LOW .gitignore:41 Opportunistic housekeeping outside the change's scope

This review was generated by /uf.review-pr (AI-assisted).

- Document consumer-side masking mitigations in the CI integration
guide (second bare-key secret, single-line strict-JSON secret shape)

### Non-Goals

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Non-Goals: the stdout-not-scrubbed exclusion is unrecorded (adversary, architect, guard)

The Non-Goals section records the ollama HTTP-path exclusion but not the deliberate decision to leave child stdout unscrubbed. Stdout from runSubprocess flows into the AI report, and from there to CLI stdout and $GITHUB_STEP_SUMMARY — which sits outside GitHub's job-log secret masking.

Not scrubbing stdout is the right engineering call here (verbatim-value replacement would corrupt legitimate report content — workspace paths and long identifiers exceed the 32-byte threshold), but as written the exclusion is indistinguishable from an oversight, and the ci-integration.md known-limits text doesn't scope the scrub to stderr.

Recommendation: add a Non-Goal bullet recording the stdout exclusion with its rationale, plus one known-limits sentence in docs/guides/ci-integration.md noting the scrub covers the two stderr surfacing paths only. Concurs with advisory (a) in the PR body.

(first name in environ order wins), and replacing longest values
first. Include the GoDoc note on the post-`Wait()` env-snapshot
assumption (design D4).
- [x] 1.2 [P] Add table-driven unit tests for `redactEnvValues` in

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Task 1.2 shouldn't carry the [P] marker (architect)

Task 1.2 (redact_test.go unit tests) compile-depends on task 1.1, which defines redactEnvValues and the threshold constants in redact.go. Per the [P] convention — parallel tasks must touch distinct files and share only already-completed prerequisites — a test task that compile-depends on a preceding implementation task can't actually run in parallel. It's also the only [P] task in phase 1, so the marker is vacuous; task 2.1 (line 44) is likewise a lone [P] in phase 2.

No operational impact (tasks completed sequentially). Recommendation: drop the marker from tasks of this shape in future specs.

Comment thread .gitleaksignore
@@ -0,0 +1,2 @@
9c1b472b2bf79dc6c5ce8bae9ea81c2c8417696e:internal/aireport/subprocess_test.go:generic-api-key:107

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Lint-gate change absent from the proposal's Impact list (guard)

The suppression itself checks out as legitimate: both fingerprints target deliberately fake test constants (test-secret-api-key-xyz123, test-secret-straddling-the-truncation-boundary-…) that must be secret-shaped to exercise the redaction paths, and the entries are maximally narrow — commit-pinned, file/rule/line-scoped. This is not a gate weakening.

However, it is a lint-gate behavior change (AGENTS.md Gatekeeping Value Protection, category 4) that doesn't appear in the proposal's Impact list, which states "no CLI, workflow, protocol, or CI configuration changes". Recommendation: document the suppression rationale in the PR description — one sentence: the fake fixtures trigger generic-api-key, suppressed via commit-pinned entries.

Comment thread .gitignore
.opencode/package-lock.json
.opencode/bun.lock
.opencode/.gitignore
.opencode/opencode.json

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Opportunistic housekeeping outside the change's scope (guard)

The three new entries — .opencode/opencode.json (line 41), .uf/review-matrix.override.yaml and .uf/progress/ (lines 45-46) — extend existing sections coherently but serve no requirement of this change and aren't in the proposal's Impact list. No functional concern. Recommendation: note them in the PR description or split into a separate chore commit.

…apter stderr

Scrub inherited env-var values from every byte of child stderr gaze
surfaces. runSubprocess passes the complete stderr buffer through
redactEnvValues immediately after cmd.Wait() returns — the single
redaction choke point (design D1) — so both the non-zero-exit error
embed and the success-path returned bytes carry scrubbed content, and
the scrub precedes the 512-byte truncation so a value straddling the
boundary cannot survive.

A value is redacted when its env-var name contains KEY, TOKEN, SECRET,
or CONFIG_CONTENT (case-insensitive) or when its length reaches 32
regardless of name; values below 4 bytes are never replaced (garble
guard). Replacements use [REDACTED:<VAR>] markers, dedupe identical
values with first-name-wins, and run longest value first. Environ
entries split at the first '=' only so values with embedded '=' are
captured whole.

Implements openspec/changes/redact-env-values-from-adapter-stderr
tasks 1.1-1.4.
…ification

- docs/guides/ci-integration.md: "Secret hygiene and stderr redaction"
  subsection (task 2.1) — scrub triggers, [REDACTED:<VAR>] marker format,
  known limits, second-secret platform masking pattern, single-line
  strict-JSON secret guidance
- docs/guides/ai-reports.md: troubleshooting bullet notes stderr redaction
  for local adapter runs (task 3.3)
- AGENTS.md: Recent Changes entry for the change (task 3.3); website
  documentation issue filed (unbound-force/website#346)
- tasks.md: verification tasks 3.1-3.4 checked — openspec validate passes
  (expected originating_issue advisory only), full CI parity passes
  locally (build, -short suite w/ coverprofile, e2e TestRunSelfCheck,
  module-major validation, golangci-lint, gaze threshold 23/38, 6/6, 42/8),
  docs impact assessed, constitution alignment re-verified
@jflowers
jflowers force-pushed the opsx/redact-env-values-from-adapter-stderr branch from eb39984 to fa0dd78 Compare October 30, 2026 23:19
@jflowers
jflowers merged commit fa87795 into unbound-force:main Oct 31, 2026
5 of 6 checks passed
jflowers added a commit to jflowers/gaze that referenced this pull request Nov 1, 2026
…tch (issue unbound-force#301)

Second retrospective batch (2026-10-30 22:01) from the code-review
dispatch on the redact-env-values-from-adapter-stderr change:

- content-pipeline: curator doc-gate verification loops (acknowledged
  advisories vs. formal findings; website-issue gate closure)
- gatekeeping: gitleaksignore suppressions are gate modifications
  needing a paper trail in the proposal/PR
- secret-redaction: record security-control scope decisions in spec
  artifacts, not just PR-body acknowledgments
- structural-entropy: fork clones break divisor base resolution —
  verify the caller-provided base_sha instead of trusting local refs
- test-quality: isolate independently-firing classifier rules in
  redaction unit tests
jflowers added a commit that referenced this pull request Nov 1, 2026
Second retrospective batch (2026-10-30 22:01) from the code-review
dispatch on the redact-env-values-from-adapter-stderr change:

- content-pipeline: curator doc-gate verification loops (acknowledged
  advisories vs. formal findings; website-issue gate closure)
- gatekeeping: gitleaksignore suppressions are gate modifications
  needing a paper trail in the proposal/PR
- secret-redaction: record security-control scope decisions in spec
  artifacts, not just PR-body acknowledgments
- structural-entropy: fork clones break divisor base resolution —
  verify the caller-provided base_sha instead of trusting local refs
- test-quality: isolate independently-firing classifier rules in
  redaction unit tests
@jflowers
jflowers deleted the opsx/redact-env-values-from-adapter-stderr branch November 15, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: redact sensitive env values from surfaced adapter stderr (defense-in-depth for config-as-secret pattern)

1 participant