Skip to content

Commit 28e9fb1

Browse files
bug #59525 [HtmlSanitizer] Fix access to undefined keys in UrlSanitizer (Antoine Beyet)
This PR was merged into the 6.4 branch. Discussion ---------- [HtmlSanitizer] Fix access to undefined keys in UrlSanitizer | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59524 | License | MIT This PR fixes the bug highlighted in #59524 and adds the unit test used to prove the error. Commits ------- c1d8c390042 [HtmlSanitizer] Avoid accessing non existent array key when checking for hosts validity
2 parents 2af88b6 + 0ef273b commit 28e9fb1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: Tests/TextSanitizer/UrlSanitizerTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ public static function provideSanitize(): iterable
274274
'expected' => null,
275275
];
276276

277+
yield [
278+
'input' => 'https://trusted.com/link.php',
279+
'allowedSchemes' => ['http', 'https'],
280+
'allowedHosts' => ['subdomain.trusted.com', 'trusted.com'],
281+
'forceHttps' => false,
282+
'allowRelative' => false,
283+
'expected' => 'https://trusted.com/link.php',
284+
];
285+
277286
// Allow relative
278287
yield [
279288
'input' => '/link.php',

Diff for: TextSanitizer/UrlSanitizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static function matchAllowedHostParts(array $uriParts, array $trustedPar
132132
{
133133
// Check each chunk of the domain is valid
134134
foreach ($trustedParts as $key => $trustedPart) {
135-
if ($uriParts[$key] !== $trustedPart) {
135+
if (!array_key_exists($key, $uriParts) || $uriParts[$key] !== $trustedPart) {
136136
return false;
137137
}
138138
}

0 commit comments

Comments
 (0)