Security: stage c1z replacements exclusively and never widen the output's mode (C1Z-SEC-011) #1167
All Vouch review confidence checks passed
Residual risk 0.29 = Change Risk (0.68) × (1 − Review Confidence (0.58)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.68 · 429 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.068
Real PR Conversation Timeline
1 comments
"Review active on #1167"
general
weight: 0.35
pquerna
Summary
C1Z-SEC-011. Every c1z publish path wrote the complete artifact, PII plus the access graph, to a fixed sibling
<out>.tmpopened withO_CREATE|O_TRUNC, mode 0644, and then renamed it over<out>. The paths werepebbleStore.save,saveC1z(v1/SQLite), andcloneSync(CloneSync/CopyIsolateSync). The compactor's cross-device fallback incpFilewroteos.Create(dest)directly.That exposes the artifact to another account that can create entries in the output directory:
<out>.tmpfails every save. Wherefs.protected_regularis off, planting a writable file there receives the artifact's bytes.os.CreateTempplaceholder, which is 0600, in a shared temp directory. The save replaced it with a 0644 file.Change
internal/atomicfilereplaces a file by writing a staged sibling and renaming it over the target:<base>.tmp-<crypto/rand.Text()>, opened withO_EXCL, so another account can neither pre-create it nor learn it in advance.Create(target),CloseAtomicallyReplace()(sync, close, rename), andCleanup(), which removes the staged file unless the replace succeeded and is safe to defer. The names follow google/renameio.It is used by
pebbleStore.save,saveC1z,cloneSync, and thecpFilecopy fallback. That fallback is now atomic as well.No exported API changes; the package is internal.
Unchanged:
ErrArtifactUnusableverdict on a failed save;.pebble-convert.tmpsibling, becauseToPebblerequires its output not to exist.Tests that injected a save failure by squatting
<out>.tmpnow squat the output path with a directory, which makes the rename fail on every platform. They pin the same verdict and recovery contracts.Tests
TestSecurity_SaveIntoPrivatePlaceholderruns on both engines. It saves into a 0600os.CreateTempplaceholder next to a directory planted at<out>.tmp:- the save succeeds;
- the planted directory is untouched;
- the published file is still 0600 (mode checked off Windows).
- With the old fixed
<out>.tmp,O_TRUNCstaging the save fails. With a fixed 0644 mode the published file is 0644.internal/atomicfile:- replacing a 0600 target keeps 0600 and leaves a planted
<target>.tmpalone;- when the rename fails because a non-empty directory is at the target,
Cleanupleaves nothing but that directory.golangci-lintv2.13.2 (the CI pin): 0 issues.go test -short -tags=baton_lambda_support ./...: passes.go test -racepasses oninternal/atomicfile,pkg/synccompactor/...and the save tests inpkg/dotc1z. A full race run ofpkg/dotc1zstill trips the existingTestC1ZConcurrentCloserace (validateDbreadsc.dbunlocked), which is on main and untouched here.