8000 bug #36286 [Validator] Allow URL-encoded special characters in basic … · symfony/symfony@6254cdb · GitHub
[go: up one dir, main page]

Skip to content

Commit 6254cdb

Browse files
committed
bug #36286 [Validator] Allow URL-encoded special characters in basic auth part of URLs (cweiske)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead. Discussion ---------- [Validator] Allow URL-encoded special characters in basic auth part of URLs | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36285 | License | MIT Special characters in HTTP Basic Auth passwords in an URL need to be url-encoded. Example: `foo@bar` becomes `foo%40bar`, in an URL: `http://user:foo%40bar@example.org` The UrlValidator did not allow percent signs in username and password, and this is changed now. Commits ------- 8a56c50 Allow URL-encoded special characters in basic auth part of URLs
2 parents 6dbf9eb + 8a56c50 commit 6254cdb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Component/Validator/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

src/Symfony/Component/Validator/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:pass.word@symfony.com'],
123123
['http://user-name@symfony.com'],
124124
['http://user_name@symfony.com'],
125+
['http://u%24er:password@symfony.com'],
126+
['http://user:pa%24%24word@symfony.com'],
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:password@symfony.com'],
173+
['http://nota%hex:password@symfony.com'],
174+
['http://username:nota%hex@symfony.com'],
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)
0