我想修復這個漏洞,其中 PHP 重定向的 URL 部分由查詢字串給出,例如
https://test.dev/test.php?return_page=contact.php
這將重定向到另一個站點contact.php
。
攻擊者可以這樣使用:
https://test.dev/test.php?return_page=http://attack.hack
我的想法是在函式中去掉雙斜杠,這樣生成的重定向將再次是內部的,并且可能是錯誤的:
$_GET['url']=str_replace("//","",$_GET['url']);
但也許有更好的方法來用正則運算式解決這個問題?
uj5u.com熱心網友回復:
擁有允許的回傳頁面引數的白名單。如果給出了不允許的,則拋出 404 或轉發到索引。
$whitelist = ['contact.php', 'about.php'];
$returnPage = $_GET['return_page'] ?? '';
if (in_array($returnPage, $whitelist)) {
header("Location: $returnPage");
exit;
}
http_response_code(404)
exit;
如果您仍然想決議和驗證我推薦使用的 URL parse_url。
uj5u.com熱心網友回復:
只需清理所有可能方案部分的 URL
$url=preg_replace('/^([a-z0-9\s%;\ ] :\/\/ ) /i','',$_GET['url']);
header('Location: ' . $url)
我在https://github.com/rubo77/phpGACL中修復了它
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/507425.html