← Back to Pull requests

Security: stage c1z replacements exclusively and never widen the output's mode (C1Z-SEC-011) #1167

Closed
unknown closed this pull request without merging on Oct 04, 2026 17:32 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 15:00 UTC
Author

Summary

C1Z-SEC-011. Every c1z publish path wrote the complete artifact, PII plus the access graph, to a fixed sibling <out>.tmp opened with O_CREATE|O_TRUNC, mode 0644, and then renamed it over <out>. The paths were pebbleStore.save, saveC1z (v1/SQLite), and cloneSync (CloneSync/CopyIsolateSync). The compactor's cross-device fallback in cpFile wrote os.Create(dest) directly.

That exposes the artifact to another account that can create entries in the output directory:

  • Blocking or capturing the save. Planting a directory at <out>.tmp fails every save. Where fs.protected_regular is off, planting a writable file there receives the artifact's bytes.

  • Republishing it world-readable. The hosted runner saves into an os.CreateTemp placeholder, which is 0600, in a shared temp directory. The save replaced it with a 0644 file.
  • Change

    internal/atomicfile replaces a file by writing a staged sibling and renaming it over the target:

  • The staged name is random and created exclusively. It is <base>.tmp-<crypto/rand.Text()>, opened with O_EXCL, so another account can neither pre-create it nor learn it in advance.

  • Replacing a file never widens its mode. The staged file gets the existing target's permissions when the target is a regular file, and 0644 otherwise, both narrowed by the umask. A 0600 placeholder therefore stays 0600. A new output gets the same mode as before (0644 under the umask), so CLI and container users reading the artifact as another UID see no change.

  • Interface: Create(target), CloseAtomicallyReplace() (sync, close, rename), and Cleanup(), 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 the cpFile copy fallback. That fallback is now atomic as well.

    No exported API changes; the package is internal.

    Unchanged:

  • rename-over-output semantics;

  • the ErrArtifactUnusable verdict on a failed save;

  • the pebble store's fix-the-condition-and-Close-again recovery;

  • convert-open's .pebble-convert.tmp sibling, because ToPebble requires its output not to exist.
  • Tests that injected a save failure by squatting <out>.tmp now 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_SaveIntoPrivatePlaceholder runs on both engines. It saves into a 0600 os.CreateTemp placeholder 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_TRUNC staging 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>.tmp alone;
    - when the rename fails because a non-empty directory is at the target, Cleanup leaves nothing but that directory.
  • golangci-lint v2.13.2 (the CI pin): 0 issues. go test -short -tags=baton_lambda_support ./...: passes.

  • go test -race passes on internal/atomicfile, pkg/synccompactor/... and the save tests in pkg/dotc1z. A full race run of pkg/dotc1z still trips the existing TestC1ZConcurrentClose race (validateDb reads c.db unlocked), which is on main and untouched here.
  • Diff: 429 lines (+321 / -108) across 5 files Reviewer: pquerna Review duration: 152m
    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
    0.68
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68.3% (HIGH) · Higher = larger blast radius
    68.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.7% · Safe to merge
    28.7%