10000 bug #59525 [HtmlSanitizer] Fix access to undefined keys in UrlSanitiz… · symfony/symfony@8abf1ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 8abf1ae

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 ------- c1d8c39 [HtmlSanitizer] Avoid accessing non existent array key when checking for hosts validity
2 parents 6c8c994 + c1d8c39 commit 8abf1ae

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/HtmlSanitizer/Tests/TextSanitizer/UrlSanitizerTest.php

Lines changed: 9 additions & 0 deletions
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',

src/Symfony/Component/HtmlSanitizer/TextSanitizer/UrlSanitizer.php

Lines changed: 1 addition & 1 deletion
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)
0