Skip to content

channel_db: skip non-ASCII DNS hostnames in node announcements - #10823

Open
ekzyis wants to merge 1 commit into
spesmilo:masterfrom
ekzyis:skip-non-ascii-dns-hostnames
Open

channel_db: skip non-ASCII DNS hostnames in node announcements#10823
ekzyis wants to merge 1 commit into
spesmilo:masterfrom
ekzyis:skip-non-ascii-dns-hostnames

Conversation

@ekzyis

@ekzyis ekzyis commented Aug 8, 2026

Copy link
Copy Markdown

BOLT-07 mentions here that senders of node_announcement need to encode DNS hostname bytes with ASCII:

   * `5`: DNS hostname; data = `[1:hostname_len][hostname_len:hostname][2:port]` (length up to 258)
       * `hostname` bytes MUST be ASCII characters.
       * Non-ASCII characters MUST be encoded using Punycode:
         https://en.wikipedia.org/wiki/Punycode

(Punycode maps non-ASCII characters to ASCII characters.)

However, receivers need to check that the bytes are indeed decodable as ASCII. Currently, the code to parse address descriptors would throw UnicodeDecodeError on the first DNS hostname with non-ASCII characters and drop the remaining descriptors.1 With this PR, such invalid address descriptors are skipped.

FYI, LND additionally checks that the characters are within [a-zA-Z0-9_.] but this is not part of the specification.

Footnotes

  1. I haven't tested this against running code, only using the existing tests, so I don't know if Electrum would crash during runtime or not.

Comment thread electrum/channel_db.py
Comment on lines 282 to +289
elif atype == 5: # dns hostname
len_hostname = int.from_bytes(read(1), 'big')
host = read(len_hostname).decode('ascii')
host_bytes = read(len_hostname)
port = int.from_bytes(read(2), 'big')
try:
host = host_bytes.decode('ascii')
except UnicodeDecodeError:
continue

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.

receivers need to check that the bytes are indeed decodable as ASCII

are we allowed to forward the node announcement message if it fails this check?

@ekzyis ekzyis Aug 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have only found this in the spec regarding not forwarding node announcements:

  - if more than one `type 5` address is announced:
    - SHOULD ignore the additional data.
    - MUST not forward the `node_announcement`.

Fwiw, LND does not forward node_announcements if they contain an invalid DNS hostname, see here.

Before, we also did not forward it. With this PR, we do, like the other test cases that fail to parse. Maybe it's better to actually throw like LND?

@accumulator

accumulator commented Aug 9, 2026

Copy link
Copy Markdown
Member

To be totally conformant, we should 'punydecode' the hostname, but since at least LND does not seem to do that, it's likely node operators avoid unicode domain names anyway.

@ekzyis

ekzyis commented Aug 9, 2026

Copy link
Copy Markdown
Author

To be totally conformant, we should 'punydecode' the hostname

I only see the spec mentioning that the sender must encode DNS hostname bytes as ASCII, and Punycode for non-ASCII characters. I don't see where it mentions the receiver needs to decode Punycode back into Unicode. For connection purposes, the Punycode ASCII characters should be enough. Did you mean for display purposes?

since at least LND does not seem to do that, it's likely node operators avoid Unicode domain names anyway.

Yes, I agree, I think Unicode domains are rare.

@accumulator

Copy link
Copy Markdown
Member

I don't see where it mentions the receiver needs to decode Punycode back into Unicode

Indeed, it is actually what DNS resolvers do when resolving a unicode domain name; convert to punycode :)
So no need to decode before presenting to the resolver.

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.

3 participants