Skip to content

Commit 28735a6

Browse files
committed
Prevent bad requests due to exceeding max allowed header length
1 parent 3c969ef commit 28735a6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/PostcodeNl/Api/Client.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public function __construct(string $key, string $secret, string $platform)
6262

6363
if (isset($_SERVER['HTTP_REFERER']))
6464
{
65-
curl_setopt($this->_curlHandle, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
65+
// Prevent exceeding max allowed header length
66+
curl_setopt($this->_curlHandle, CURLOPT_REFERER, substr($_SERVER['HTTP_REFERER'], 0, 256));
6667
}
68+
6769
curl_setopt($this->_curlHandle, CURLOPT_HEADERFUNCTION, function($curl, string $header) {
6870
$length = strlen($header);
6971

@@ -431,12 +433,15 @@ protected function _performCurlCall(string $url): array
431433

432434
protected function _getUserAgent(): string
433435
{
434-
return sprintf(
436+
$agent = sprintf(
435437
'%s %s/%s PHP/%s',
436438
$this->_platform,
437439
str_replace('\\', '_', static::class),
438440
static::VERSION,
439441
PHP_VERSION
440442
);
443+
444+
// Prevent exceeding max allowed header length
445+
return substr($agent, 0, 1024);
441446
}
442447
}

0 commit comments

Comments
 (0)