A free open source IT asset/license management system
Reject scheme-only URLs with no authority
snipe887564141afa
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 6329e70e42..161012c70b 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -1817,6 +1817,12 @@ class Helperreturn null;}+ // Reject scheme-only URLs with no authority (e.g. "https:evil.com",+ // "https:/evil.com", "http:@evil.com").+ if (isset($parts['scheme']) && !isset($parts['host'])) {+ return null;+ }+$host = $parts['host'] ?? null;$appHost = parse_url(config('app.url'), PHP_URL_HOST);diff --git a/tests/Unit/Helpers/HelperTest.php b/tests/Unit/Helpers/HelperTest.phpindex c97e09c16c..14a1d0a2c4 100644--- a/tests/Unit/Helpers/HelperTest.php+++ b/tests/Unit/Helpers/HelperTest.php@@ -10,7 +10,6 @@ use Tests\TestCase;class HelperTest extends TestCase{-public function test_check_if_required_returns_false_when_class_is_null(){$this->assertFalse(Helper::checkIfRequired(null, 'name'));@@ -334,6 +333,26 @@ class HelperTest extends TestCase$this->assertNull(Helper::sameOriginUrl('//evil.example.com/steal-session'));}+ #[\PHPUnit\Framework\Attributes\DataProvider('schemeOnlyBypassProvider')]+ public function test_same_origin_url_rejects_scheme_without_authority(string $input): void+ {+ $this->assertNull(Helper::sameOriginUrl($input));+ }++ public static function schemeOnlyBypassProvider(): array+ {+ return [+ 'https scheme only' => ['https:evil.example.com'],+ 'http scheme only' => ['http:evil.example.com'],+ 'https with path suffix' => ['https:evil.example.com/path?q=1'],+ 'https with port and path' => ['https:evil.example.com:8080/admin'],+ 'http userinfo without authority' => ['http:@evil.example.com'],+ 'https single slash prefix' => ['https:/evil.example.com'],+ 'bare scheme with colon' => ['http:'],+ 'ipv4 loopback via scheme-only' => ['http:127.0.0.1:9931/bg'],+ ];+ }+public function test_same_origin_url_rejects_backslash_userinfo_parser_differential(): void{config(['app.url' => 'https://app.example.com']);