Skip to content

Validate the PROXY v2 command, family and address length - #1968

Open
cpruijsen wants to merge 1 commit into
uNetworking:masterfrom
cpruijsen:fix/proxy-v2-validate-command-family
Open

cpruijsen wants to merge 1 commit into
uNetworking:masterfrom
cpruijsen:fix/proxy-v2-validate-command-family

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Fixes #1948

ProxyParser::parse() checked the PROXY v2 version but not the command, the family byte or the address length:

  • LOCAL (command 0) was handled like PROXY, so its address block was exposed through getProxiedRemoteAddress().
  • Commands other than 0 and 1 were accepted.
  • Any family byte was accepted. Everything that wasn't IPv4 was read as a 16-byte IPv6 address, including UNIX paths and undefined families.
  • A block shorter than the INET (12) or INET6 (36) address part was accepted and exposed as zeros.
  • A valid block with TLVs after the address was rejected, because the whole block had to fit in proxy_addr.

Now parse() rejects commands other than LOCAL and PROXY. LOCAL consumes the header without exposing an address. For PROXY it accepts only the family/transport bytes the spec defines (0x00, 0x11, 0x12, 0x21, 0x22, 0x31, 0x32), requires the full address for INET and INET6, and copies only the address part, so TLVs after it are skipped. UNSPEC and UNIX are consumed without exposing an IP address. Rejections return {false, 0}, as the version and signature checks already do.

I added tests/ProxyParser.cpp to the unit tests in tests/Makefile, with the cases from the issue plus a block with 28 bytes of TLVs and a UNIX block. On master it fails at the first case the old parser gets wrong; with this change it passes, and make -C tests passes. App.h also compiles with UWS_WITH_PROXY.

This branch has not been deployed

No deployments
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.

PROXY v2 parser accepts invalid commands and returns addresses from invalid family blocks

1 participant