diff options
| author | 2022-08-11 14:20:18 +0100 | |
|---|---|---|
| committer | 2022-08-11 15:40:57 +0100 | |
| commit | f88fbaa2fe91c22f1c7280ecd96c2bcf92f73a4d (patch) | |
| tree | e35803070a6ca8e50ee2d07b2e6c0d71230d53f3 /src/modules/m_websocket.cpp | |
| parent | Clean up the sockaddrs documentation comments. (diff) | |
Move aptosa/untosa into the sockaddrs union and add from/from_ip.
The struct will also now always be zero-initialized by default which
removes the footgun which has happened previously where the union has
been accessed before being initialized leading to it containing weird
values.
Diffstat (limited to 'src/modules/m_websocket.cpp')
| -rw-r--r-- | src/modules/m_websocket.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/modules/m_websocket.cpp b/src/modules/m_websocket.cpp index fd5bd2a73..f9363f998 100644 --- a/src/modules/m_websocket.cpp +++ b/src/modules/m_websocket.cpp @@ -408,7 +408,12 @@ class WebSocketHook final if (proxyheader.Find(recvq, "X-Real-IP:", 10, reqend) || proxyheader.Find(recvq, "X-Forwarded-For:", 16, reqend)) { // Attempt to parse the proxy HTTP header. - irc::sockets::aptosa(proxyheader.ExtractValue(recvq), realsa.port(), realsa); + if (!realsa.from_ip_port(proxyheader.ExtractValue(recvq), realsa.port())) + { + // The proxy header value contains a malformed value. + FailHandshake(sock, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n", "WebSocket: Received a proxied HTTP request that sent a malformed real IP address"); + return -1; + } } else { @@ -416,14 +421,6 @@ class WebSocketHook final FailHandshake(sock, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n", "WebSocket: Received a proxied HTTP request that did not send a real IP address header"); return -1; } - - if (realsa.family() == AF_UNSPEC) - { - // The proxy header value contains a malformed value. - FailHandshake(sock, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n", "WebSocket: Received a proxied HTTP request that sent a malformed real IP address"); - return -1; - } - for (const auto& proxyrange : config.proxyranges) { if (InspIRCd::MatchCIDR(luser->GetIPString(), proxyrange, ascii_case_insensitive_map)) |
