http icon indicating copy to clipboard operation
http copied to clipboard

New request parser breaks on local host names

Open akadlec opened this issue 1 year ago • 0 comments

I'm using react/http on my local server which is creating server to interact with HomeKit. And the latest version break parsing incoming request because of host name.

Data which are sent by HomeKit to my server may look like this:

POST /pair-verify HTTP/1.1\r\n
Host: HomeKit\032Integration\0322509EB._hap._tcp.local\r\n
Content-Length: 37\r\n
Content-Type: application/pairing+tlv8\r\n
\r\n
\x06\x01\x01\x03 … \xE73o\xE1\xE0o\x82\xB6\xE1\x17

And this data are taken by RequestHeaderParser to parse -> ServerRequest -> new Uri and here it crashes:

if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s_%+]#', $parts['host']))) {
                throw new \InvalidArgumentException('Invalid URI given');
}

because the uri is: http://HomeKit\032Integration\0322509EB._hap._tcp.local/pair-verify

akadlec avatar Aug 10 '24 09:08 akadlec