Repository navigation
Description
Summary
With UWS_WITH_PROXY, ProxyParser::parse() validates the PROXY v2 version but neither its command nor its address-family value and required address length. A LOCAL header and an undefined command are handled like PROXY, while an unsupported family or a too-short INET/INET6 address block can be reported as a client address. The affected address is exposed through HttpResponse::getProxiedRemoteAddress(); no memory-safety issue or access-control bypass has been demonstrated.
Details
File: src/ProxyParser.h. The version check inspects only the high nibble of ver_cmd; the low command nibble is never checked. After a general hostLength <= sizeof(proxy_addr) check, parse() stores header.fam and copies the address bytes without checking whether the family is supported or whether the bytes required by that family are present:
if ((header.ver_cmd & 0xf0) >> 4 != 2) return {false, 0};
/* ... */
if (sizeof(proxy_addr) < hostLength) return {false, 0};
/* ... */
if (!done) {
family = header.fam;
memcpy(&addr, data.data() + 16, hostLength);
done = true;
}getSourceAddress() returns no address only when the entire family byte is zero; it treats a high family nibble of 1 as IPv4 and every other nonzero value as IPv6. HttpResponse::getProxiedRemoteAddress() exposes this parser result to applications.
The PROXY protocol v2 specification §2.2 defines command 0x0 (LOCAL) to use the real connection endpoints and ignore protocol/address information; only 0x0 and 0x1 (PROXY) are defined. For PROXY, INET requires a 12-byte address block and INET6 requires 36 bytes. The specification lists 0x00, 0x11, 0x12, 0x21, 0x22, 0x31, and 0x32 as valid family/transport bytes; other values must be rejected.
Reproduction
Compile the unmodified src/ProxyParser.h with UWS_WITH_PROXY. For each case, construct a header from the 12-byte PROXY v2 signature 0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a, followed by the indicated ver_cmd, family byte, two-byte big-endian block length, and then address bytes 01 02 ... up to that length. Pass the header to a fresh uWS::ProxyParser::parse() and inspect getSourceAddress():
| Case | ver_cmd |
Family | Block length | Observed address |
|---|---|---|---|---|
| Valid PROXY IPv4 control | 21 |
11 |
12 | 01020304 (IPv4) |
| LOCAL with IPv4-looking block | 20 |
11 |
12 | 01020304 (IPv4), instead of no proxied address |
| Undefined command 2 | 22 |
11 |
12 | 01020304 (IPv4), header accepted |
| Unsupported family 4 | 21 |
41 |
12 | 0102030405060708090a0b0c00000000 (16-byte IPv6 value) |
| Invalid UNSPEC + STREAM | 21 |
01 |
0 | 00000000000000000000000000000000 (16-byte IPv6 value) |
| Too-short IPv4 block | 21 |
11 |
0 | 00000000 (IPv4) |
| Too-short IPv6 block | 21 |
21 |
0 | 00000000000000000000000000000000 (IPv6) |
| Valid UNSPEC control | 21 |
00 |
0 | no address |
Expected behavior: for LOCAL, consume the header without exposing its address block as a proxied source; reject an undefined command. For PROXY, reject invalid family/transport bytes and short INET/INET6 blocks. Handle valid UNSPEC and UNIX families without fabricating an IP address, or explicitly reject unsupported valid families.
Impact and fix
Applications that use the proxied remote address for logging or policy decisions may receive 1.2.3.4, 0.0.0.0, ::, or an arbitrary 16-byte value that the header did not validly supply. PROXY protocol normally assumes a trusted upstream; if an untrusted client can reach a PROXY-enabled listener, it can already spoof an address with an ordinary valid PROXY header. The address union is zero-initialized, so short blocks expose zeros rather than stale memory. These tests do not show a crash, memory-safety issue, or a security-policy bypass.
Validate the command nibble before using an address block. Treat LOCAL separately and reject unknown commands. For PROXY, validate the entire family/transport byte and the minimum address length before copying or exposing the address; handle UNSPEC and UNIX explicitly. The current maximum-length check also rejects valid blocks with TLVs after the address portion, so a fix should copy only the address portion and skip supported TLVs rather than requiring the whole block to fit in proxy_addr.
Activity