Skip to content

lnpeer: add some rate-limiting against ping flood#10665

Merged
SomberNight merged 2 commits into
spesmilo:masterfrom
SomberNight:202605_lnpeer_ping_flood
May 26, 2026
Merged

lnpeer: add some rate-limiting against ping flood#10665
SomberNight merged 2 commits into
spesmilo:masterfrom
SomberNight:202605_lnpeer_ping_flood

Conversation

@SomberNight

Copy link
Copy Markdown
Member

A remote peer could send us lots of small ping messages, requesting large pong responses. This is cheap for them but potentially expensive for us. Does not seem too serious, but I think we could add some rate-limiting.

note: There are many ways for a remote peer to inflate our incoming traffic usage, but the cost of that is usually shared between them and us (they need to send the data, we receive it).

Comment thread electrum/lnpeer.py Outdated
await asyncio.sleep(min_delay - elapsed_since_last)
self._last_ping_recv_time = time.monotonic()
l = payload['num_pong_bytes']
self.send_message('pong', byteslen=l)

@f321x f321x May 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to drain the transport like this as well?

Suggested change
self.send_message('pong', byteslen=l)
msg = encode_msg('pong', byteslen=l)
await self.transport.send_bytes_and_drain(msg)

Otherwise, maybe a peer could just fill up our sockets outgoing buffer by ~234mb/h if they stop reading from their socket and keep sending pings every second.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuuuuu nice observation.
I don't know if such an attack would actually work though -- I would expect some kind of TCP timeout to get triggered from the OS. But maybe I am wrong?
In any case, let's do this, defense in depth.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if they stop reading

I guess if they keep reading reeeeeeaaaalllyy slow, but send stuff at a steady pace, that might work, maybe.

SomberNight and others added 2 commits May 26, 2026 14:18
A remote peer could send us lots of small ping messages, requesting large pong responses. This is cheap for them but potentially expensive for us.
Does not seem too serious, but I think we could add some rate-limiting.

note: There are many ways for a remote peer to inflate our incoming traffic usage,
but the cost of that is usually shared between them and us (they need to send the data, we receive it).
might help against some memory exhaustion attacks

f321x said:
> maybe a peer could just fill up our sockets outgoing buffer by ~234mb/h
> if they stop reading from their socket and keep sending pings every second.

Co-authored-by: f321x <f@f321x.com>
@SomberNight SomberNight force-pushed the 202605_lnpeer_ping_flood branch from 33eb6e4 to 9b20657 Compare May 26, 2026 14:19
@SomberNight SomberNight merged commit 9c64deb into spesmilo:master May 26, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants