Repository navigation
fix: prepare non-writable files for custom secret masking - #66160
Conversation
Replace readable non-writable logs atomically before custom redaction, including files without built-in secret matches. Handle disappearing sources and remove unsanitized artifacts on processing failures. Co-authored-by: Copilot App <[email protected]>
|
🔎 PR Code Quality Reviewer is reviewing code quality for this pull request... |
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. No ADR enforcement needed: PR #66160 does not have the 'implementation' label (has_implementation_label=false) and has 0 new lines in business logic directories (default_business_additions=0, threshold=100, 4 files changed, no custom .design-gate.yml).
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Failed cleanup can leave unsanitized files uploadable, and one scanning race remains unhandled.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Improves secret-redaction reliability for non-writable and disappearing artifact files.
Changes:
- Atomically replaces non-writable files with private writable copies.
- Handles disappearing files and adds regression coverage.
- Documents custom masking requirements and records a patch changeset.
| File | Description |
|---|---|
actions/setup/js/redact_secrets.cjs |
Adds replacement and cleanup handling. |
actions/setup/js/redact_secrets.test.cjs |
Adds reliability regression tests. |
docs/src/content/docs/reference/imports.md |
Documents custom masking hooks. |
.changeset/patch-secret-redaction-file-reliability.md |
Records the patch release. |
| if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { | ||
| core.warning(`Skipping directory that disappeared during secret redaction: ${currentDir}`); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Fixed the symlink-removal race by treating ENOENT as a vanished entry; the existing artifact cleanup path already tolerated missing files. Added regression coverage. Commit fa741ce.
|
@copilot run pr-finisher skill |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /codebase-design — this is a solid, well-tested reliability fix; only minor non-blocking suggestions.
📋 Key Themes & Highlights
Key Themes
- Repeated error-guard boilerplate: the
"code" in error && error.code === Xpattern appears 5 times across the file; a smallisErrnoCode()helper would reduce duplication risk (/codebase-design). - Scope of ENOENT tolerance: the mask-collection loop's
ENOENThandling (flagged earlier by the security bot) is correctly scoped toagent-stdio.logonly and does not weaken the fail-closed path for other files — a short inline comment would make that reasoning self-evident rather than relying on the PR description (/diagnosing-bugs).
Positive Highlights
- ✅ Root cause properly addressed: the atomic-replace via
mkdtempSync/writeFileSync(..., { flag: "wx" })/renameSynccorrectly handles container-owned readable-but-non-writable logs without sudo or recursive chmod. - ✅ Strong regression coverage: new tests exercise EACCES/EPERM replacement, blocked replacement cleanup, disappearing files mid-scan, mid-mask-collection, and mid-processing — closely mirroring the real failure investigated.
- ✅ Fail-closed behavior preserved: any non-ENOENT/EACCES/EPERM error, or a blocked replacement, still removes the unsanitized artifact and calls
core.setFailed. - ✅ Docs updated (
imports.md) to set clear expectations for custom hook authors (writable parent dir requirement, no bypass of locks/inaccessible dirs, ENOENT tolerance).
Note: this is a 305-line diff, well within the truncation cap, so the full change was reviewed.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 72.3 AIC · ⌖ 14.7 AIC · ⊞ 10.2K
Comment /matt to run again
| } | ||
| return; | ||
| } catch (error) { | ||
| if (!(error && typeof error === "object" && "code" in error && (error.code === "EACCES" || error.code === "EPERM"))) { |
There was a problem hiding this comment.
[/codebase-design] Five call sites repeat error && typeof error === "object" && "code" in error && error.code === "X" (lines 36, 40, 290, 344, 419). Extracting a small isErrnoCode(error, ...codes) helper would make each guard a one-liner and remove the risk of a typo silently breaking one of the fail-closed checks.
💡 Suggested helper
function isErrnoCode(error, ...codes) {
return !!(error && typeof error === "object" && "code" in error && codes.includes(error.code));
}Then each guard becomes e.g. isErrnoCode(error, "ENOENT") or isErrnoCode(error, "EACCES", "EPERM"). This is a /codebase-design deepening: the repeated conditional is boilerplate that obscures the actual branching logic (ENOENT vs permission vs other), and a shared predicate makes the module's error-handling vocabulary explicit and easier to audit for correctness.
@copilot please address this.
There was a problem hiding this comment.
Added a shared isErrnoCode helper and applied it across the file’s errno checks. Commit fa741ce.
| for (const value of collectAddMaskedValues(fs.readFileSync(file, "utf8"))) masks.add(value); | ||
| } catch (error) { | ||
| for (const source of files) fs.unlinkSync(source); | ||
| if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { |
There was a problem hiding this comment.
[/diagnosing-bugs] This ENOENT tolerance only covers agent-stdio.log disappearing between the glob scan and the read in this loop — it does not weaken the fail-closed guarantee for other files, since the existing catch branch (which removes every artifact and throws) still fires for any other error code. The flagged security-bot concern looks addressed by scope, but it'd help future readers if the comment made that narrowing explicit.
💡 Suggested comment
// Only agent-stdio.log is optional here: its disappearance means no runtime
// masks were ever emitted, not that redaction failed. Any other error still
// removes all artifact sources below.
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {Root-cause framing per /diagnosing-bugs: the fix narrows a fail-open-looking branch to a single known-optional file, but the "why is this safe" reasoning currently only lives in your PR description, not in the code.
@copilot please address this.
There was a problem hiding this comment.
The agent-stdio.log ENOENT exception has been removed. A missing runtime-mask source now removes the artifact sources and fails redaction, so the optional-file comment no longer applies. Commit fa741ce.
Co-authored-by: pelikhan <[email protected]>
|
@copilot update instructions to deter agents to try to create issues directly / use secrets in post-steps / secret-scanning steps |
Co-authored-by: pelikhan <[email protected]>
Updated |
|
🎉 This pull request is included in a new release. Release: |

Summary
secret-masking.steps, even when built-in redaction finds no matching secrets. Atomically replace them with runner-owned, owner-only read/write copies without sudo or recursive permission changes.Failure investigated
githubnext/gh-aw-rai failing job, step 43 failed with
EACCESfromfs.writeFileSync('/tmp/gh-aw/mcp-logs/safeoutputs/server.log')in its custom RAI redactor. Built-in redaction had scanned 314 files and reported no matching secrets, so it never attempted a write to that file. The logs establish a write-permission failure, not an OS-level lock; readable, non-writable logs reproduce the failure.Validation
Passed:
make build, executed by the final validation target.ENOENT, fatal removal errors, and malformed HTML fail-closed behavior.agent-stdio.logdoes not abort redaction of other artifacts.node --check actions/setup/js/redact_secrets.cjs, Prettier formatting, andgit diff --check.Blocked:
PATH="/opt/homebrew/bin:$PATH" make agent-report-progressbuilt successfully but could not complete JavaScript lint/typecheck/tests becausetscis unavailable.vitest-5.0.3.tgz, and the approved 1ES feed reported no[email protected]. A public-registry retry did not complete and was stopped. Dependency manifests and lockfiles are unchanged.Boundaries
Replacement requires a writable parent directory. It does not bypass OS locks, reclaim inaccessible directories, or prepare files outside the built-in scan. Custom hooks must handle those cases explicitly, tolerate absent optional sources, and stop log writers before sanitization.