Stricter URL validation
- do not use empty() as empty('0') is true
- do not lowercase the strings, use them as they are
- lowercase all domains in our codebase
- do not allow to specify port
Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
parent
4c34f14077
commit
dac36c3cd8
@ -389,7 +389,7 @@ PMA_printListItem(
|
||||
PMA_printListItem(
|
||||
__('Official Homepage'),
|
||||
'li_pma_homepage',
|
||||
PMA_linkURL('https://www.phpMyAdmin.net/'),
|
||||
PMA_linkURL('https://www.phpmyadmin.net/'),
|
||||
null,
|
||||
'_blank'
|
||||
);
|
||||
|
||||
@ -754,10 +754,17 @@ function PMA_linkURL($url)
|
||||
function PMA_isAllowedDomain($url)
|
||||
{
|
||||
$arr = parse_url($url);
|
||||
// Avoid URLs without hostname or with credentials
|
||||
if (empty($arr['host']) || ! empty($arr['user']) || ! empty($arr['pass'])) {
|
||||
// We need host to be set
|
||||
if (! isset($arr['host']) || strlen($arr['host']) == 0) {
|
||||
return false;
|
||||
}
|
||||
// We do not want these to be present
|
||||
$blocked = array('user', 'pass', 'port');
|
||||
foreach ($blocked as $part) {
|
||||
if (isset($arr[$part]) && strlen($arr[$part]) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$domain = $arr["host"];
|
||||
$domainWhiteList = array(
|
||||
/* Include current domain */
|
||||
@ -766,6 +773,7 @@ function PMA_isAllowedDomain($url)
|
||||
'wiki.phpmyadmin.net', 'www.phpmyadmin.net', 'phpmyadmin.net',
|
||||
'demo.phpmyadmin.net',
|
||||
'docs.phpmyadmin.net',
|
||||
'demo.phpmyadmin.net',
|
||||
/* mysql.com domains */
|
||||
'dev.mysql.com','bugs.mysql.com',
|
||||
/* mariadb domains */
|
||||
@ -781,7 +789,7 @@ function PMA_isAllowedDomain($url)
|
||||
/* Following are doubtful ones. */
|
||||
'mysqldatabaseadministration.blogspot.com',
|
||||
);
|
||||
if (in_array(mb_strtolower($domain), $domainWhiteList)) {
|
||||
if (in_array($domain, $domainWhiteList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,9 @@ class PMA_isAllowedDomain_test extends PHPUnit_Framework_TestCase
|
||||
array('https://www.phpmyadmin.net/', true),
|
||||
array('http://duckduckgo.com\\@github.com', false),
|
||||
array('https://github.com/', true),
|
||||
array('https://github.com:123/', false),
|
||||
array('https://user:pass@github.com:123/', false),
|
||||
array('https://user:pass@github.com/', false),
|
||||
array('https://server.local/', true),
|
||||
array('./relative/', false),
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user