fix: state-machine: validate the snapshot id before using it as a path #9
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
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.323
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9"
general
weight: 0.35
lichuang
Finding
P2 — a peer-supplied
snapshot_idis used as a file path without validation.src/raft/store/statemachine.rs::create_snapshot_temp_file:snapshot_idcomes straight out ofInstallSnapshotRequest.meta.snapshot_id,i.e. from whichever peer is streaming the snapshot.
Path::joindiscards thebase path when the right-hand side is absolute and resolves
..segments, so anid of
../../../etc/passwdor/etc/cron.d/xwrites the assembled snapshotoutside 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
or, over gRPC, send an
InstallSnapshotrequest whosemeta.snapshot_id = "../escape"and watch the file appear outside<data_path>/snapshot/.The fix
check_snapshot_idrejects anything that is not a plain file-name componentbefore the path is built:
.,.., or longer than 255 bytes,-,_and..The ids
build_snapshotproduces ({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) andtest_create_snapshot_temp_file_rejects_escaping_id, which asserts that../../../etc/passwdis refused withInvalidInputinstead of reaching thefilesystem.