Allow URL-encoded special characters in basic auth part of URLs

Resolves: https://github.com/symfony/symfony/issues/36285
This commit is contained in:
Christian Weiske 2020-03-31 11:41:21 +02:00 committed by Fabien Potencier
parent 6dbf9eb663
commit 8a56c506e3
2 changed files with 5 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class UrlValidator extends ConstraintValidator
{
const PATTERN = '~^
(%s):// # protocol
(([\_\.\pL\pN-]+:)?([\_\.\pL\pN-]+)@)? # basic auth
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
(
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or

View File

@ -122,6 +122,8 @@ class UrlValidatorTest extends ConstraintValidatorTestCase
['http://user.name:pass.word@symfony.com'],
['http://user-name@symfony.com'],
['http://user_name@symfony.com'],
['http://u%24er:password@symfony.com'],
['http://user:pa%24%24word@symfony.com'],
['http://symfony.com?'],
['http://symfony.com?query=1'],
['http://symfony.com/?query=1'],
@ -168,6 +170,8 @@ class UrlValidatorTest extends ConstraintValidatorTestCase
['http://:password@@symfony.com'],
['http://username:passwordsymfony.com'],
['http://usern@me:password@symfony.com'],
['http://nota%hex:password@symfony.com'],
['http://username:nota%hex@symfony.com'],
['http://example.com/exploit.html?<script>alert(1);</script>'],
['http://example.com/exploit.html?hel lo'],
['http://example.com/exploit.html?not_a%hex'],