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

lnrpc: fix Sec-Websocket-Protocol parsing

Public commit record

What the developer wrote

Authored by Gijs van Dam

90/100 · Strong
lnrpc: fix Sec-Websocket-Protocol parsing

forwardHeaders assumed that a Sec-Websocket-Protocol value matching one
of the allowed prefixes also contains the "+" delimiter, and indexed the
split result at [1] unconditionally. A client that sends only the
protocol name, for example "Grpc-Metadata-Macaroon" with no delimiter,
therefore caused an index out of range panic.

The panic is currently contained because forwardHeaders runs on the
net/http handler goroutine, whose deferred recover catches it, so only
the client's own connection dies. That containment is incidental to the
current call graph rather than by design though: neither the read loop
nor the backend forwarder goroutine has a recover of its own.

The prefix match was too loose in the other direction as well. The field
is a comma separated list of sub protocols, but it was matched and split
as a single string, so "Grpc-Metadata-Macaroon,other+value" passed the
prefix check and forwarded "value" from the second entry as the macaroon
for the first.

Split the field on "," first and cut each entry at its own delimiter,
forwarding only entries whose name adjoins that delimiter and is
allowed. Add a table test covering the forwarding rules including these
cases.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit fixes a bug in how LND's WebSocket proxy handled a special browser header called Sec-Websocket-Protocol. Previously, a client could send just the protocol name without a required separator, causing the server to crash with a panic. The crash was only contained by accident, not by design. The fix also prevents a trick where a client could make one protocol entry steal a value from another entry in the same list. The patch adds tests to confirm the correct behavior.

Recommended action

Apply the patch and ensure any custom WebSocket clients send protocol values in the exact "Name+value" form. Review whether other goroutines in the WebSocket proxy path need explicit panic recovery. No additional vendor advisory is supplied in the materials.

Security signals we found

01

Denial of service via unhandled index out-of-range panic in request header parsing

02

Authentication bypass / credential confusion risk from loose prefix matching on comma-separated protocol list

03

Fix hardens parsing by requiring exact allowed protocol names and a delimiter before forwarding values

04

Incident containment described as incidental rather than by design, indicating latent reliability risk

05

Test coverage added for parsing edge cases

Risk score

Why this scored 67/100

Our methodology →
Potential impact 18/30
Exploitability 15/25
Stealth signal 8/15
Affected reach 12/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.