fix(signature): validate pubkey length and prefix byte#26
fix(signature): validate pubkey length and prefix byte#26
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🧰 Additional context used📓 Path-based instructions (4)src/attack/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/signature.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/{provider,signature}.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (13)📓 Common learnings📚 Learning: 2026-01-15T17:42:46.869ZApplied to files:
📚 Learning: 2026-01-15T17:42:59.187ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T18:08:47.413ZApplied to files:
📚 Learning: 2026-01-15T17:42:59.187ZApplied to files:
🧬 Code graph analysis (1)src/signature.rs (1)
🔇 Additional comments (4)
📝 WalkthroughWalkthroughAdded stricter validation to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
✨ Simplify code
📝 Coding Plan
Comment |
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- There is a concrete validation gap in
src/signature.rs: SEC1 parsing only checks length/prefix, so invalid curve points are accepted instead of being rejected at input validation time. - Because this is severity 6/10 with high confidence (9/10), it introduces moderate regression risk around error handling and can surface misleading "unrecoverable" failures to users.
- This looks fixable and contained to input validation logic, but it is user-facing enough to warrant caution before merge.
- Pay close attention to
src/signature.rs- tighten SEC1 point validation so malformed points are classified as bad input, not unrecoverable errors.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/signature.rs">
<violation number="1" location="src/signature.rs:97">
P2: This only checks SEC1 length and prefix, so invalid curve points still pass and later get reported as "unrecoverable" instead of bad input.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Client as SignatureInput
participant Sig as Signature::try_from()
participant Val as validate_pubkey_hex()
participant Attack as Attack Engine
participant Downstream as verify_key_matches_pubkey
Note over Client,Val: Validation Phase
Client->>Sig: Convert raw input to Signature
Sig->>Val: NEW: validate_pubkey_hex(pubkey)
Val->>Val: Verify ASCII hex characters
alt Length is 66 (Compressed)
Val->>Val: NEW: Check for 02 or 03 prefix
else Length is 130 (Uncompressed)
Val->>Val: NEW: Check for 04 prefix
else Invalid Length
Val-->>Sig: CHANGED: bail! (Invalid length error)
end
alt Prefix mismatch
Val-->>Sig: CHANGED: bail! (Invalid prefix error)
else Success
Val-->>Sig: Ok(())
end
Note over Sig,Downstream: Execution Phase
alt Validation Failed
Sig-->>Client: Return Error (Early Exit)
else Validation Passed
Sig-->>Client: Return Signature
Client->>Attack: detect(signatures)
Attack->>Downstream: verify_key_matches_pubkey()
Note right of Downstream: Downstream logic now receives<br/>guaranteed valid EC point formats.
Downstream-->>Attack: Match/No Match
end
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| anyhow::bail!("Invalid pubkey: must be hexadecimal"); | ||
| } | ||
|
|
||
| match pubkey.len() { |
There was a problem hiding this comment.
P2: This only checks SEC1 length and prefix, so invalid curve points still pass and later get reported as "unrecoverable" instead of bad input.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/signature.rs, line 97:
<comment>This only checks SEC1 length and prefix, so invalid curve points still pass and later get reported as "unrecoverable" instead of bad input.</comment>
<file context>
@@ -93,6 +93,32 @@ fn validate_pubkey_hex(pubkey: &str) -> Result<()> {
anyhow::bail!("Invalid pubkey: must be hexadecimal");
}
+
+ match pubkey.len() {
+ 66 => {
+ if !pubkey.starts_with("02") && !pubkey.starts_with("03") {
</file context>
validate_pubkey_hexonly checked for hex characters, so"ff","deadbeef", or any hex string passed validation. Downstream,verify_key_matches_pubkeycompares against properly encoded EC points and never matches, so the tool reports vulnerabilities as "unrecoverable" with no hint that the input pubkey is malformed.Now rejects early with a clear message if the pubkey isn't 66 chars (compressed,
02/03prefix) or 130 chars (uncompressed,04prefix).Closes #22