hack to workaround uWebsockets issue preventing parsing of some IPv6 addresses (reported by Petr Kracík)

This commit is contained in:
Doug Hoyte
2024-10-18 18:04:21 -04:00
parent bfb9fd14f4
commit 29d7afe6c3
2 changed files with 7 additions and 0 deletions

View File

@ -1,6 +1,8 @@
* New config param: relay.info.nips which allows you to override the NIPs * New config param: relay.info.nips which allows you to override the NIPs
that are claimed to be supported (requested by ismyhc) that are claimed to be supported (requested by ismyhc)
* New connectionTimeout parameter in router config (thanks Braydon Fuller!) * New connectionTimeout parameter in router config (thanks Braydon Fuller!)
* Bugfix: IPv4-mapped IPv6 addresses in X-Real-IP headers were not parsed
correctly (reported by Petr Kracík)
1.0.1 1.0.1
* Prevent exporting a v2 DB using --fried. The packed representation will be * Prevent exporting a v2 DB using --fried. The packed representation will be

View File

@ -197,6 +197,11 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
if (cfg().relay__realIpHeader.size()) { if (cfg().relay__realIpHeader.size()) {
auto header = req.getHeader(cfg().relay__realIpHeader.c_str()).toString(); // not string_view: parseIP needs trailing 0 byte auto header = req.getHeader(cfg().relay__realIpHeader.c_str()).toString(); // not string_view: parseIP needs trailing 0 byte
// HACK: uWebSockets strips leading : characters, which interferes with IPv6 parsing.
// This fixes it for the common ::1 and ::ffff:1.2.3.4 cases. FIXME: fix the underlying library.
if (header == "1" || header.starts_with("ffff:")) header = std::string("::") + header;
c->ipAddr = parseIP(header); c->ipAddr = parseIP(header);
if (c->ipAddr.size() == 0) LW << "Couldn't parse IP from header " << cfg().relay__realIpHeader << ": " << header; if (c->ipAddr.size() == 0) LW << "Couldn't parse IP from header " << cfg().relay__realIpHeader << ": " << header;
} }