Skip to content

Commit

Permalink
Add _ to host validation (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximal authored Dec 10, 2024
1 parent c5bad9b commit 97a40cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Driver/Http1Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function handleClient(
throw new ClientException($this->client, "Bad Request: multiple host headers", HttpStatus::BAD_REQUEST);
}

if (!\preg_match("#^([A-Z\d.\-]+|\[[\d:]+])(?::([1-9]\d*))?$#i", $headers["host"][0], $matches)) {
if (!\preg_match("#^([A-Z\d._\-]+|\[[\d:]+])(?::([1-9]\d*))?$#i", $headers["host"][0], $matches)) {
throw new ClientException($this->client, "Bad Request: invalid host header", HttpStatus::BAD_REQUEST);
}

Expand Down Expand Up @@ -317,7 +317,7 @@ public function handleClient(
);
}

if (!\preg_match("#^([A-Z\d.\-]+|\[[\d:]+]):([1-9]\d*)$#i", $target, $matches)) {
if (!\preg_match("#^([A-Z\d._\-]+|\[[\d:]+]):([1-9]\d*)$#i", $target, $matches)) {
throw new ClientException(
$this->client,
"Bad Request: invalid connect target",
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Http2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ public function handleHeaders(int $streamId, array $pseudo, array $headers, bool
[':method' => $method, ':path' => $target, ':scheme' => $scheme, ':authority' => $host] = $pseudo;
$query = null;

if (!\preg_match("#^([A-Z\d.\-]+|\[[\d:]+])(?::([1-9]\d*))?$#i", $host, $matches)) {
if (!\preg_match("#^([A-Z\d._\-]+|\[[\d:]+])(?::([1-9]\d*))?$#i", $host, $matches)) {
throw new Http2StreamException(
"Invalid authority (host) name",
$streamId,
Expand Down

0 comments on commit 97a40cc

Please sign in to comment.