{"answers":{"affected":"2 open source packages ship an affected version, including zaino-state.","exploited":"There is no known exploitation of GHSA-3whf-vgf2-9w6g in the wild and no public exploit code.","fix":"Upgrade zaino-state to 0.4.1 or later.","what":"GHSA-3whf-vgf2-9w6g is a denial of service vulnerability in zaino-state, published on 31 Jul 2026. An attacker can exploit it over the internet without logging in, with no action from the victim."},"fix_prompt":"Check this codebase for GHSA-3whf-vgf2-9w6g and fix it if it is affected.\n\nWhat it is: GHSA-3whf-vgf2-9w6g is a denial of service vulnerability in zaino-state, published on 31 Jul 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.\nExploitation: There is no known exploitation of GHSA-3whf-vgf2-9w6g in the wild and no public exploit code.\n\nAffected packages and fixed versions:\n- zaino-state (crates.io): affected all versions; fixed in 0.4.1\n- zaino-state (crates.io): affected all versions; fixed in 0.4.1\n\nTask:\n1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.\n2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.\n3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.\n4. Run the tests and summarise what changed and why.\n5. If nothing in the project is affected, say so and change nothing.\n\nReference: https://insights.sbomify.com/GHSA-3whf-vgf2-9w6g/ (Markdown: https://insights.sbomify.com/GHSA-3whf-vgf2-9w6g/index.md)","id":"GHSA-3whf-vgf2-9w6g","markdown":"https://insights.sbomify.com/GHSA-3whf-vgf2-9w6g/index.md","name":"GHSA-3whf-vgf2-9w6g","record":{"aliases":[],"analysis":{"component_type":"library","fix_type":"patch","impacts":["denial_of_service"],"network_reachable":"yes","non_default_config":false,"product_category":"Zaino state library","requires_auth":"none","summary":"A malicious validator can cause infinite recursion and CPU exhaustion in the Zaino state library by serving cyclic block data, leading to denial of service.","user_interaction":"not_required","vuln_class":"denial_of_service"},"analysis_generated_by":"qwen3.8-flash-next","assigner":null,"cpe":[],"cvss":{"score":null,"severity":null,"source":null,"vector":null,"version":null},"cwes":[],"description":"### Summary\n`NonFinalizedState::handle_reorg` is a recursive, unbounded async function that traverses parent blocks until it finds a common ancestor on the main chain. It has **no recursion depth limit** and **no cycle detection**. A malicious or buggy validator can serve a block whose `previous_block_hash` points back to itself (or forms a cycle with other blocks), causing `handle_reorg` to infinite-loop, consuming 100% CPU and never making sync progress. Additionally, `update()` contains an `.expect(\"empty snapshot impossible\")` that panics if the non-finalized snapshot becomes empty after trimming finalized blocks.\n\n### Details\n\n**Location:** `packages/zaino-state/src/chain_index/non_finalised_state.rs:443-489`\n\n```rust\nasync fn handle_reorg(\n    \u0026self,\n    working_snapshot: \u0026mut NonfinalizedBlockCacheSnapshot,\n    block: \u0026impl Block,\n) -\u003e Result\u003cIndexedBlock, SyncError\u003e {\n    let prev_block = match working_snapshot\n        .get_block_by_hash_bytes_in_serialized_order(block.prev_hash_bytes_serialized_order())\n        .cloned()\n    {\n        Some(prev_block) =\u003e {\n            if !working_snapshot\n                .heights_to_hashes\n                .values()\n                .any(|hash| hash == prev_block.hash())\n            {\n                Box::pin(self.handle_reorg(working_snapshot, \u0026prev_block)).await?  // \u003c-- LINE 459\n            } else {\n                prev_block\n            }\n        }\n        None =\u003e {\n            let prev_block = self\n                .source\n                .get_block(HashOrHeight::Hash(\n                    zebra_chain::block::Hash::from_bytes_in_serialized_order(\n                        block.prev_hash_bytes_serialized_order(),\n                    ),\n                ))\n                .await\n                .map_err(|e| { ... })?\n                .ok_or(SyncError::ValidatorConnectionError(...))?;\n            Box::pin(self.handle_reorg(working_snapshot, \u0026*prev_block)).await?  // \u003c-- LINE 483\n        }\n    };\n    let indexed_block = block.to_indexed_block(\u0026prev_block, self).await?;\n    working_snapshot.add_block_new_chaintip(indexed_block.clone());\n    Ok(indexed_block)\n}\n```\n\n**Infinite loop via self-referencing block:**\n1. A compromised validator serves a block `B` where `B.prev_hash == B.hash`.\n2. `handle_reorg` is called with `B`.\n3. `get_block_by_hash_bytes_in_serialized_order(B.prev_hash)` finds `B` itself in `working_snapshot.blocks`.\n4. Check: is `B.hash` in `working_snapshot.heights_to_hashes`? If `B` is a new chaintip not yet on the main chain, **no**.\n5. Recurse with `prev_block` = `B` (the exact same block).\n6. This repeats forever. The async recursion builds a new `Box::pin` future each iteration, consuming heap memory and CPU.\n\n**Stack exhaustion via deep reorg:**\nA deep reorg of \u003e1000 blocks would recurse \u003e1000 times. Each async recursion creates a new `Box::pin` future on the heap. While this won't exhaust the native stack immediately, it will allocate unbounded heap memory and CPU time, effectively DoS-ing the sync task.\n\n**`.expect(\"empty snapshot impossible\")` panic:**\n\n**Location:** `packages/zaino-state/src/chain_index/non_finalised_state.rs:543-548`\n\n```rust\nnew_snapshot.remove_finalized_blocks(finalized_height);\nlet best_block = \u0026new_snapshot\n    .blocks\n    .values()\n    .max_by_key(|block| block.chainwork())\n    .cloned()\n    .expect(\"empty snapshot impossible\"); // \u003c-- LINE 548\n```\n\nIf `finalized_height` is greater than or equal to all blocks in `new_snapshot.blocks`, `remove_finalized_blocks` retains only blocks at or above that height. If none exist, `new_snapshot.blocks` becomes empty. The `.expect()` then panics. While the comment claims this is \"impossible,\" defensive programming dictates it is reachable under corruption or edge-case sync conditions.\n\n### PoC\n\n1. Run a regtest.\n2. Serve a block where `header.previous_block_hash == block.hash()`.\n3. Zaino's `NonFinalizedState::sync` enters `handle_reorg` and infinite-loops.\n4. Sync never completes. CPU usage pegs to 100%. No new blocks are served to clients.\n\n### Fix\n\n1. **Add an explicit recursion depth limit** (e.g., max 1000 iterations) and return `SyncError::ReorgFailure` if exceeded:\n   ```rust\n   const MAX_REORG_DEPTH: usize = 1000;\n   ```\n2. **Track visited hashes** in a `HashSet\u003cBlockHash\u003e` during traversal to detect cycles and abort with an error.\n3. **Replace `.expect(\"empty snapshot impossible\")`** with a proper `Err(UpdateError::DatabaseHole)` or similar error return.\n\n### Additional Attack Vectors\n\n- **Deep reorg DoS:** A miner with significant hash power (or a compromised validator) triggers a deep reorg. Zaino spends excessive CPU and memory in `handle_reorg`, starving the async runtime and stalling response serving.\n- **Fork-choice manipulation:** By serving cyclic or very deep sidechains, an attacker can keep Zaino stuck in reorg handling indefinitely, preventing it from ever serving the real best chain.","ecosystems":["crates.io"],"exploits":{"exploitdb":null,"first_seen":null,"github_poc":null,"max_poc_stars":null,"metasploit":null,"nuclei":null,"refs":[],"tier":null},"has_fix":true,"headline":"zaino-state has a Non-Finalized State Reorg — No Cycle Detection or Depth Limit","id":"GHSA-3whf-vgf2-9w6g","indexable":true,"kev":null,"kind":"advisory","links":{"ecosystem":"crates.io","product":null,"products":[],"type":"denial_of_service","year":"2026"},"n_packages":2,"n_references":null,"packages":[{"ecosystem":"crates.io","fixed":["0.4.1"],"introduced":["0"],"last_affected":[],"package":"zaino-state","purl":null,"source":"GHSA-3whf-vgf2-9w6g"},{"ecosystem":"crates.io","fixed":["0.4.1"],"introduced":["0"],"last_affected":[],"package":"zaino-state","purl":"pkg:cargo/zaino-state","source":"GHSA-3whf-vgf2-9w6g"}],"products":null,"published":"2026-07-31","related":[],"sources":[{"class":"attribution","licence":"CC BY 4.0","name":"GitHub Advisory Database","prefix":"GHSA"}],"ssvc":{"automatable":null,"exploitation":null,"technical_impact":null},"state":null,"updated":null,"vendors":null},"summary":"A malicious validator can cause infinite recursion and CPU exhaustion in the Zaino state library by serving cyclic block data, leading to denial of service.","url":"https://insights.sbomify.com/GHSA-3whf-vgf2-9w6g/"}