Skip to content

Commit ffa2680

Browse files
committed
Request::getOrigin() accepts only URL as defined in RFC 6454
1 parent 3c8f16f commit ffa2680

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/Http/Request.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,11 @@ public function getReferer(): ?UrlImmutable
212212
*/
213213
public function getOrigin(): ?UrlImmutable
214214
{
215-
$header = $this->headers['origin'] ?? 'null';
216-
try {
217-
return $header === 'null'
218-
? null
219-
: new UrlImmutable($header);
220-
} catch (Nette\InvalidArgumentException) {
215+
$header = $this->headers['origin'] ?? '';
216+
if (!preg_match('~^[a-z][a-z0-9+.-]*://[^/]+$~i', $header)) {
221217
return null;
222218
}
219+
return new UrlImmutable($header);
223220
}
224221

225222

tests/Http/Request.getOrigin.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ test('valid Origin header', function () {
2727
]);
2828
Assert::equal(new UrlImmutable('https://nette.org'), $request->getOrigin());
2929
});
30+
31+
32+
test('invalid Origin header', function () {
33+
$request = new Http\Request(new Http\UrlScript, headers: [
34+
'Origin' => 'https://nette.org/path',
35+
]);
36+
Assert::null($request->getOrigin());
37+
});

0 commit comments

Comments
 (0)