← Back to Pull requests

fix: state-machine: validate the snapshot id before using it as a path #9

Closed
unknown closed this pull request without merging on Nov 03, 2026 03:37 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 16:12 UTC
Author

Finding

P2 — a peer-supplied snapshot_id is used as a file path without validation.

src/raft/store/statemachine.rs::create_snapshot_temp_file:

pub fn create_snapshot_temp_file(&self, snapshot_id: &str) -> Result<File, io::Error> {
    File::create(self.snapshot_dir.join(format!("{}_incomplete", snapshot_id)))
}

snapshot_id comes straight out of InstallSnapshotRequest.meta.snapshot_id,
i.e. from whichever peer is streaming the snapshot. Path::join discards the
base path when the right-hand side is absolute and resolves .. segments, so an
id of ../../../etc/passwd or /etc/cron.d/x writes the assembled snapshot
outside the snapshot directory — anywhere the process can write. The Raft port is
unauthenticated, so this is reachable by any peer that can open a connection, and
by a merely buggy peer.

How to reproduce

let sm = /* any RocksStateMachine */;
sm.create_snapshot_temp_file("../../../etc/passwd")?;   // before: Ok(file)

or, over gRPC, send an InstallSnapshot request whose
meta.snapshot_id = "../escape" and watch the file appear outside
<data_path>/snapshot/.

The fix

check_snapshot_id rejects anything that is not a plain file-name component
before the path is built:

  • empty, ., .., or longer than 255 bytes,

  • any character outside ASCII alphanumerics, -, _ and ..
  • The ids build_snapshot produces ({leader_id}-{index}-{timestamp}-{seq}, e.g.
    T3-N5-100-1234567890-1) all pass, so no existing snapshot becomes unreadable.

    Tests: test_check_snapshot_id_rejects_path_escapes (both sets) and
    test_create_snapshot_temp_file_rejects_escaping_id, which asserts that
    ../../../etc/passwd is refused with InvalidInput instead of reaching the
    filesystem.

    Diff: 219 lines (+164 / -55) across 2 files Reviewer: lichuang Review duration: 3564m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 219 lines diff across 2 files
    0.37
    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%
    60%
    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.323
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    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: 36.7% (MEDIUM) · Higher = larger blast radius
    36.7%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 14.5% · Safe to merge
    14.5%