Skip to content

Commit 5cea97e

Browse files
cmb69derickr
authored andcommitted
Fix #81122: SSRF bypass in FILTER_VALIDATE_URL
We need to ensure that the password detected by parse_url() is actually a valid password; we can re-use is_userinfo_valid() for that.
1 parent 996beda commit 5cea97e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ext/filter/logical_filters.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
632632
RETURN_VALIDATION_FAILED
633633
}
634634

635-
if (url->user != NULL && !is_userinfo_valid(url->user)) {
635+
if (url->user != NULL && !is_userinfo_valid(url->user)
636+
|| url->pass != NULL && !is_userinfo_valid(url->pass)
637+
) {
636638
php_url_free(url);
637639
RETURN_VALIDATION_FAILED
638640

ext/filter/tests/bug81122.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #81122 (SSRF bypass in FILTER_VALIDATE_URL)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('filter')) die("skip filter extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$urls = [
10+
"https://example.com:\\@test.com/",
11+
"https://user:\\epass@test.com",
12+
"https://user:\\@test.com",
13+
];
14+
foreach ($urls as $url) {
15+
var_dump(filter_var($url, FILTER_VALIDATE_URL));
16+
}
17+
?>
18+
--EXPECT--
19+
bool(false)
20+
bool(false)
21+
bool(false)

0 commit comments

Comments
 (0)