Skip to content

Commit 3e48185

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

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
@@ -210,14 +210,11 @@ public function getReferer(): ?UrlImmutable
210210
*/
211211
public function getOrigin(): ?UrlImmutable
212212
{
213-
$header = $this->headers['origin'] ?? 'null';
214-
try {
215-
return $header === 'null'
216-
? null
217-
: new UrlImmutable($header);
218-
} catch (Nette\InvalidArgumentException) {
213+
$header = $this->headers['origin'] ?? '';
214+
if (!preg_match('~^[a-z][a-z0-9+.-]*://[^/]+$~i', $header)) {
219215
return null;
220216
}
217+
return new UrlImmutable($header);
221218
}
222219

223220

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)