Skip to content

Commit adab212

Browse files
cweiskefabpot
authored andcommitted
Allow URL-encoded special characters in basic auth part of URLs
Resolves: symfony/symfony#36285
1 parent 0fb0e11 commit adab212

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UrlValidator extends ConstraintValidator
2323
{
2424
const PATTERN = '~^
2525
(%s):// # protocol
26-
(([\_\.\pL\pN-]+:)?([\_\.\pL\pN-]+)@)? # basic auth
26+
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
2727
(
2828
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
2929
| # or

Tests/Constraints/UrlValidatorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public function getValidUrls()
122122
['http://user.name:[email protected]'],
123123
['http://[email protected]'],
124124
['http://[email protected]'],
125+
['http://u%24er:[email protected]'],
126+
['http://user:pa%24%[email protected]'],
125127
['http://symfony.com?'],
126128
['http://symfony.com?query=1'],
127129
['http://symfony.com/?query=1'],
@@ -168,6 +170,8 @@ public function getInvalidUrls()
168170
['http://:password@@symfony.com'],
169171
['http://username:passwordsymfony.com'],
170172
['http://usern@me:[email protected]'],
173+
['http://nota%hex:[email protected]'],
174+
['http://username:nota%[email protected]'],
171175
['http://example.com/exploit.html?<script>alert(1);</script>'],
172176
['http://example.com/exploit.html?hel lo'],
173177
['http://example.com/exploit.html?not_a%hex'],

0 commit comments

Comments
 (0)