AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
High 78 Bitcoin

Reject onion per-hop lengths that overflow an `Int` (#3408)

Public commit record

What the developer wrote

Authored by pm47

86/100 · Strong
Reject onion per-hop lengths that overflow an `Int` (#3408)

The per-hop payload length is decoded as a `Long` (the varint may use up to 9 bytes) but converted to an `Int` without checking that it fits. A sender who knows our node id can compute the shared secret and a valid hmac, so they can choose a length that wraps around when converted:

- fe 80 00 00 05 wraps to a negative value, which passes the upper bound check added in d3a146a08 and then throws when extracting the hmac, outside of the `Try`. Like before that fix, the exception escaped the relayer (which was resumed, so the HTLC was never failed upstream and kept its slot until expiry) and aborted the `PostRestartHtlcCleaner` on the next restart.
- 9-byte varints can wrap to small positive values (one of them even overflows the Long once the varint size is added), which made us silently accept a garbage per-hop payload.

We now require the decoded length to be non-negative and to fit in an Int before converting it, which turns all these cases into an `InvalidOnionVersion` error as for other invalid lengths.

Reported-by: Fire
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This fix closes a denial-of-service bug in Eclair's Lightning onion routing. A remote sender could craft a malformed per-hop payload length that, when converted from a large number to a normal integer, wrapped around to a negative or tiny value. That bypassed safety checks and crashed the relayer or the post-restart cleanup logic, leaving affected HTLCs stuck until they expired. The patch now rejects oversized lengths before converting them.

Recommended action

Apply the patch and ensure all nodes are upgraded. Monitor for any related unhandled exceptions in onion peeling paths. Consider additional fuzzing of varint decoders in routing/payment codecs.

Security signals we found

01

Integer overflow / truncation from Long to Int

02

Negative length bypasses upper-bound check

03

Exception escapes Try block causing DoS

04

Post-restart cleanup abort on unhandled exception

05

HTLC slot exhaustion / stuck HTLCs until expiry

06

Remote attacker can compute valid HMAC knowing recipient node id

Risk score

Why this scored 78/100

Our methodology →
Potential impact 24/30
Exploitability 18/25
Stealth signal 12/15
Affected reach 10/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.