Repository navigation
op-devstack,op-acceptance-tests: cover the production proofs init path with backfill - #23429
einar-oplabs wants to merge 3 commits into
Conversation
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio. |
| logger := n.p.Logger().New("name", n.name, "chain", n.chainID, "running", n.sub != nil) | ||
| logger.Info("Running op-reth proofs init", "cmd", n.execPath, "args", args) | ||
| started := time.Now() | ||
| output, err := exec.CommandContext(n.p.Ctx(), n.execPath, args...).CombinedOutput() |
There was a problem hiding this comment.
OS Command Injection (CWE-78)
More Details
OS command injection is a critical vulnerability that allows an attacker to execute arbitrary commands on the system. This can lead to a full system compromise, as the attacker can potentially gain complete control over the application and the underlying system.
The vulnerability arises when user input is used to construct commands or command arguments that are then executed by the application. This can occur when user-supplied data is passed directly to functions that execute OS commands, such as exec.Command, exec.CommandContext, syscall.ForkExec, or syscall.StartProcess.
If an attacker can inject malicious code into these commands, they can potentially execute any command on the system, including installing malware, stealing data, or causing a denial of service. This vulnerability can have severe consequences, including data breaches, system compromise, and unauthorized access to sensitive information.
To avoid this vulnerability, user input should never be used directly in constructing commands or command arguments. Instead, the application should use a hardcoded set of arguments and validate any user input to ensure it does not contain malicious code.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
OS command injection is a critical vulnerability that allows an attacker to execute arbitrary commands on the system. This can lead to a full system compromise, as the attacker can potentially gain complete control over the application and the underlying system. The vulnerability arises when user input is used to construct commands or command arguments that are then executed by the application.
To fix this issue, user input should never be used directly in constructing commands or command arguments. Instead, the application should use a hardcoded set of arguments and validate any user input to ensure it does not contain malicious code. Additionally, it is recommended to use language-specific facilities for executing commands, which provide better input validation and sanitization.
Code examples
// VULNERABLE CODE - User input is directly used in constructing the command
userInput := getInput() // Assume this comes from user input
cmd := exec.Command("/bin/sh", "-c", userInput)
err := cmd.Run()// SECURE CODE - Command and arguments are hardcoded, and user input is validated
userInput := getInput() // Assume this comes from user input
if !isValidInput(userInput) {
// Handle invalid input
return
}
cmd := exec.Command("/bin/sh", "-c", "echo", userInput)
err := cmd.Run()Additional recommendations
- Follow the principle of least privilege and run the application with the minimum required permissions.
- Use input validation and sanitization techniques to ensure that user input does not contain malicious code.
- Implement secure coding practices and follow security standards such as OWASP Top 10 and CWE.
- Consider using language-specific facilities for executing commands, such as os/exec in Go, which provide better input validation and sanitization.
- Regularly update and patch the application and its dependencies to address known vulnerabilities.
- Implement logging and monitoring mechanisms to detect and respond to potential security incidents.
Rule ID: WS-I011-GO-00026
To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason
If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate
|
This pr has been automatically marked as stale and will be closed in 5 days if no updates |
…fill Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit 8e22ead) (cherry picked from commit dde6412af5e5d2ec17988d5cf4d7291421ccd1fb)
…rst persistence Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit c9576b8) (cherry picked from commit ce3a7c42a019dff799492ffbc051fd66c8edcb39)
…am and tests Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit a5c44cf) (cherry picked from commit 21eb4663e3b719779d601419af2fdec85a8c0e8a)
a5c44cf to
f4bf9f5
Compare
Why
Every production proofs-history store is created by
op-reth proofs initon a node that synced without proofs history, with a backward backfill through the snapshot path or through reth's changesets. Devstack only ever ranproofs initon a genesis datadir, so the backfill, the snapshot path and the init guards #23046 adds (ensure_source_state_trie_durable) had no end-to-end coverage.What
op-acceptance-tests/tests/proofs_history_init(sequencer without proofs history as theeth_getProofreference, follower started without proofs history, 1s L2 blocks, both op-reths with--engine.persistence-thresholdand--engine.memory-block-buffer-target=5passed explicitly, window W = 30):TestFollowerServesTheWholeWindowAfterProofsInitWithBackfill: the operator path. Alice and bob transfer back and forth and bob writes to a deployed contract until the chain is past W + 5 and the follower has imported it; the follower's CL and op-reth are stopped cleanly;op-reth proofs init --proofs-history.window=30runs against the datadir, with the default snapshot backfill or--proofs-history.use-snapshot=false; op-reth restarts with--proofs-history. Before the CL is back, so nothing extends or prunes the store, the store must report exactly[tip - W, tip]for reth's datadir tip andVerifyHistoricalProofsMatchsweeps every block of it for the four accounts against the sequencer. The CL then comes back, traffic runs the chain W + 5 past the anchor,WaitForProofsStorePrunedPast(anchor)requires pruning to have moved the earliest block past the init's anchor, and a second sweep covers the window the store serves then, which is entirely live-indexed. Matrix: threshold {7, 50} x proofs path {index, execute} x backfill {snapshot, plain}, eight cells.TestProofsInitSeedsAConsistentStoreFromAKilledNodeDatadir: the follower's op-reth is killed (StopUngracefully) once the chain is past a window, so its datadir trails the head by the blocks reth held in memory (the test requires that gap);proofs initmust succeed, the restarted node must serve exactly[persisted tip - W, persisted tip]and that window must verify before the CL is back; after the CL re-feeds the lost blocks and ten more blocks of traffic, a second sweep covers the live window.TestProofsInitAgainstARunningNodeLeavesAStoreThatMatchesTheChain:proofs initruns against the datadir while the follower is running and persisting. The test accepts two outcomes: exit 0, or a refusal whose message carriesreth database tip moved(rust!: update reth to v2.6.0 #23046'sInitializeSourceTipMoved); any other failure fails the test. After a clean stop (and a second init if the first was refused) the restarted node's store must catch up with the datadir tip and every proof of the window it serves must verify and match the sequencer, before and after the CL is back.op-devstackseam (general; #23390 reuses the window field and the init action):stack.ProofsHistoryInit{PlainBackfill, Window}(zero value = the operator's plain invocation, snapshot backfill and the node's configured window),stack.ProofsHistoryInitReport{Duration, Output}andstack.ProofsHistoryInitializer(op-devstack/stack/proofs_history.go).sysgo.OpReth.InitProofsHistory(init): runsop-reth proofs init --chain --datadir --proofs-history.storage-path --proofs-history.window=W [--proofs-history.use-snapshot=false]against the node's datadir whether or not the node is running (the running case is what the guard test is about), returns the duration and output, and on success makes the nextStartpass the proofs-history flags with that window.Windowzero keeps the node's configured window (OpRethWithProofsHistoryWindowor the runtime's 10000).OpRethnow keeps itsnodearguments without the proofs-history flags and appends them inStartwhile proofs history is enabled;buildMixedOpRethNodeseeds the genesis store through the same method, so the default path is unchanged except that it now passes the node's window explicitly (a no-op at genesis).OpRethWithoutProofsHistoryis the way to build a node whose store a test seeds later.l2ELFrontend; DSLL2ELNode.InitProofsHistory(opts...)(requires a stopped node, fails the test on error, returns the report),InitProofsHistoryRaw(opts...)(runs whether or not the node is running and returns the outcome) andWaitForProofsStorePrunedPast(block, timeout).TestProofsHistoryNodeArgs,TestProofsHistoryInitArgs,TestOpRethNodeArgsCarryProofsHistoryOnlyOnceEnabled,TestInitProofsHistoryEnablesProofsHistoryOnSuccessOnly(fakeop-rethscript).Findings
proofs initagainst a running node's datadir exits 0 in every run (4 of 4 cells,refused=false): the command opens reth's MDBX read-only, anchors the store at reth's Finish checkpoint and copies the hashed-state and trie tables in a second read transaction. The copy matched the anchor every time, and after the restart the store caught up from the anchor to the datadir tip ([15, 45]at threshold 7,[55, 85]at 50) and every proof verified. Whether that copy can describe another block than the anchor depends on a persistence commit landing between the two read transactions, a few milliseconds apart, which is the same window rust!: update reth to v2.6.0 #23046'sensure_source_state_trie_durablecloses withInitializeSourceTipMoved. So the issue's "on the bump the running-node case must fail with the tip-moved error" is a race on the bump too (its unit tests cover it with a hand-moved checkpoint); this test accepts the refusal when it happens, retries on the stopped node, and asserts the end-to-end property, which is what an operator needs. The retry is sound on the bump becauseensure_source_state_trie_durableruns beforeset_initial_state_anchor, so a refused store holds no anchor.SIGINT) makes reth persist everything it held in memory: in all eight operator-path cells the datadir tip after the restart equaled the head at the stop, including the threshold-50 cells, where reth had persisted nothing before the stop. The guard tests, which kill the node, therefore drive the chain to threshold + W + 5 before the kill, so reth has persisted at least a window; a first version drove to W + 5 and at threshold 50 the kill left the datadir at genesis (store window [0, 0], the init anchored at block 0).[16, 46]and[9, 39]and the follower re-imported the rest from its CL and served all of it.rust/op-reth/tests/proofs/prune/(dormant: CI runsproofs/coreonly, and its hard-coded window of 200 never prunes against the runtime's 10000) is superseded by the prune step of the operator-path test. I was not permitted to delete it from this environment; it should be removed in this PR or right after.Local verification
Debug op-reth built from this branch, op-node:
DEVSTACK_ORCHESTRATOR=sysgo RUST_BINARY_PATH_OP_RETH=<debug op-reth> go test -count=1 -timeout 40m -parallel 2 -v ./op-acceptance-tests/tests/proofs_history_init/:Every sweep compared every block of its range for the four accounts (
pruned_during_sweep=0). The eight operator-path cells sum to about 11 minutes back to back and the four guard cells to about 5, so the package stays under 20 minutes with-parallel 1.kona-node (
DEVSTACK_L2CL_KIND=kona-node RUST_BINARY_PATH_KONA_NODE=<release kona-node built from develop today>, same command): all twelve cells pass,ok ... 578.047sat-parallel 2; the follower EL-syncs there, and the threshold-50 guard cells take about 125 s because the chain runs to block 85 before the kill or the init (killed node: head 87, datadir tip 46, seeded [16, 46]; running node: init exit 0 at head 87, store caught up to [57, 87]).After the review changes (option inversion,
exec.CommandContext, renames) one cell per test was run again under op-node on the final commit:threshold_7-index-backfill_plain(84.89s),TestProofsInitSeedsAConsistentStoreFromAKilledNodeDatadir/threshold_7-masking_0(78.00s),TestProofsInitAgainstARunningNodeLeavesAStoreThatMatchesTheChain/threshold_50-masking_0(123.70s),ok ... 163.987s.Skipped cells
masking_30guard cells: ethereum-optimism/protocol-team#457. On rust!: update reth to v2.6.0 #23046 with masking on, the init against a killed node must fail withInitializeSourceStateTrieLagginguntil a clean restart repairs the datadir; the skip message says so.Stacked on #23428, #23421 and #23418.
Closes #23389
🤖 Generated with Claude Code