fix(core): compute created-skew in checked arithmetic (#358) - #457
beardthelion wants to merge 1 commit into
Conversation
created= is attacker-supplied i64 with no range clamp. now - created overflows on i64::MIN (panic in debug, wrap in release), and the wrap case made abs() return i64::MIN, which is not > 300, so a skew of 2^63 seconds read as fresh. Treat an unrepresentable difference as the largest possible skew.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour. 📝 WalkthroughWalkthroughThe timestamp freshness check now handles extreme ChangesTimestamp freshness validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Low Suggested reviewers: Merge Risk: ⚪ Minimal · up to Extreme attacker-supplied timestamps are rejected safely, with no remaining actionable merge risk identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR hardens HTTP signature freshness validation against signed integer overflow.
Confidence Score: 5/5The PR appears safe to merge and correctly closes the timestamp-overflow freshness bypass. The checked arithmetic preserves existing behavior for representable skews while converting overflow into rejection, and the new tests exercise extreme values through the production parser and freshness check.
|
| Filename | Overview |
|---|---|
| crates/gitlawb-core/src/http_sig.rs | Safely computes attacker-controlled timestamp skew and tests rejection of extreme values. |
Reviews (1): Last reviewed commit: "fix(core): compute created-skew in check..." | Re-trigger Greptile
Summary
check_createdcomputed(now - created).abs()wherecreatedis attacker-supplied i64 from thecreated=signature param.now - createdoverflows oni64::MIN(panic in debug builds, wrap in release), and the wrapped value'sabs()isi64::MINagain, which is not> 300: a signature claiming to be 2^63 seconds old read as fresh.Motivation & context
Closes #358
Kind of change
What changed
crates/gitlawb-core/src/http_sig.rs: skew is nownow.checked_sub(created).map(i64::unsigned_abs).unwrap_or(u64::MAX), so an unrepresentable difference is the largest possible skew rather than a wrap or a panic.extreme_created_timestamps_reject_without_wrappingdrivesi64::MIN,i64::MAX, andnow - i64::MAXthroughHttpSignature::parseintocheck_createdand asserts each rejects.How a reviewer can verify
cargo test -p gitlawb-core http_sigThe new test panics on the old expression (verified by restoring
(now - self.created).abs()), which is also the debug-build behavior this removes.Before you request review
cargo test -p gitlawb-corepasses locallycargo fmt --allandcargo clippy -p gitlawb-core --all-targets -- -D warningsare cleanfeat(...),fix(...),docs(...)).env.exampleupdated if behavior or config changed (or N/A)Protocol & signing impact
did:key, Ed25519 / RFC 9421 signatures, UCAN, ref certs, or P2P wire formatsNotes: the fix only rejects inputs that were always meant to fail the 300s freshness gate. No honestly-generated signature is affected.
Notes for reviewers
http_sig.rsis shared with open #306, #261, and #334, butcheck_createdis a self-contained method; any conflicts should be context-only.Summary by CodeRabbit