File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,18 @@ echo $curl->response;
21
21
Safer:
22
22
23
23
``` php
24
- function is_website_url($url, $allowed_schemes = array('http', 'https')) {
25
- $validate_url = !(filter_var($url, FILTER_VALIDATE_URL) === false);
26
- $scheme = parse_url($url, PHP_URL_SCHEME);
27
- return $validate_url && in_array($scheme, $allowed_schemes, true);
24
+ function is_allowed_url($url, $allowed_url_schemes = array('http', 'https')) {
25
+ $valid_url = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED) !== false;
26
+ if ($valid_url) {
27
+ $scheme = parse_url($url, PHP_URL_SCHEME);
28
+ return in_array($scheme, $allowed_url_schemes, true);
29
+ }
30
+ $valid_ip = filter_var($url, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false;
31
+ return $valid_ip;
28
32
}
29
33
30
34
$url = $_GET['url'];
31
- if (!is_website_url ($url)) {
35
+ if (!is_allowed_url ($url)) {
32
36
die('Unsafe url detected.');
33
37
}
34
38
```
You can’t perform that action at this time.
0 commit comments