keep-web: fail closed instead of panicking when the RNG health check trips - #918
Merged
Conversation
WalkthroughSecure randomness failures are now handled explicitly for WebSocket tickets and NIP-46 approval IDs. Ticket requests return HTTP 503, while approval requests are denied when an approval ID cannot be generated. The related JavaScript-safety test now unwraps the optional ID. ChangesEntropy failure handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four paths in the web co-signer drew randomness through the panicking
random_bytes()helper. Two are reachable while the service is running, so an entropy health-check failure would unwind inside a live signer rather than being reported; the other two abort startup with a raw panic message instead of the clean error theirio::Resultsignature already supports. All four now use the fallible helper and fail closed.Request paths
ws_ticket): returns503with a retry hint instead of panicking. The ticket authorizes a WebSocket upgrade, so a value the health check has flagged must never be issued.random_approval_id): returnsNonewhen the check trips, and the caller refuses the approval and logs it, mirroring the existing refusal used when co-signing is disabled. Unguessability is the entire purpose of this id (it is defense-in-depth alongside the auth gate), so refusing beats falling back to anything predictable. The refusal happens before the approval slot is registered or broadcast, so no half-created approval is left behind.Startup paths (both already returned
io::Result, and the crate already defines the fallible wrapper used by its siblings)After this, no caller of the panicking helper remains anywhere in the crate.
Scope note: this covers the entropy health-check verdict. A hard OS-entropy failure still unwinds inside the RNG itself before the check can report it; that is a pre-existing keep-core issue and is tracked separately rather than papered over here.
Part of #803.
Test plan
cargo test -p keep-web— 54 passed, 0 failed. The existing approval-id range test now asserts the healthy path yields an id.cargo clippy -p keep-web --all-targets -- -D warningsandcargo fmt --check— clean.