server: ensure unique addresses for node ann
What changed, and why it matters
This change makes sure a Lightning node's public announcement doesn't accidentally list the same network address twice. Duplicate addresses could confuse other nodes, waste resources, or in some protocol situations be misused. The fix removes duplicates right before signing the announcement.
Apply the patch. Review all node announcement modifiers to ensure they cannot introduce other invalid or malformed addresses beyond duplicates.
Security signals we found
Deduplication of externally influenced address list before signing
Prevention of duplicate address injection via modifiers
Mitigation of potential gossip protocol abuse or resource exhaustion
Evidence from the diff
In server.go’s genNodeAnnouncement, after all modifiers have been applied to newNodeAnn, the patch deduplicates newNodeAnn.Addresses using a map keyed by addr.String(). It then signs the cleaned announcement. This prevents duplicate net.Addr entries from being published in a node_announcement message.
Changed components
server.gogenNodeAnnouncementnode announcement generationInspect captured patch +12 / −0
diff --git a/server.go b/server.go
index 3c011f8..1c2db3d 100644
--- a/server.go
+++ b/server.go
@@ -3399,6 +3399,18 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
modifier(&newNodeAnn)
}
+ // The modifiers may have added duplicate addresses, so we need to
+ // de-duplicate them here.
+ uniqueAddrs := map[string]struct{}{}
+ dedupedAddrs := make([]net.Addr, 0)
+ for _, addr := range newNodeAnn.Addresses {
+ if _, ok := uniqueAddrs[addr.String()]; !ok {
+ uniqueAddrs[addr.String()] = struct{}{}
+ dedupedAddrs = append(dedupedAddrs, addr)
+ }
+ }
+ newNodeAnn.Addresses = dedupedAddrs
+
// Sign a new update after applying all of the passed modifiers.
err := netann.SignNodeAnnouncement(
s.nodeSigner, s.identityKeyLoc, &newNodeAnn,
Why this scored 38/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.