我的网址就像page.php?path=content/x/y/z/aaa.md。下面的php代码XSS-安全吗?
include "Parsedown.php";
function path_purifier($path) {
if(substr($path, 0, 8) !== "content/")
return null;
if (strpos($path,'..') !== false)
return null;
return "./" . $path;
}
$parsedown = new Parsedown();
$path = $_GET['path'];
$path = path_purifier($path);
echo $parsedown->text(file_get_contents($path));谢谢你的关注
发布于 2015-03-06 21:18:19
是的,看起来很安全,但还是不完美。在调用is_file()之前,还需要调用file_get_contents()并确保其返回true。此外,为了使它更安全,您可以在其之上实现一个CSRF保护。
此外,请记住,一些主机提供商不允许相对路径。因此,如果像'/content/x/y/file.md'这样的路径可能在您的本地机器上工作,请记住,在某些主机上它不会工作。所以你最好总是使用像__DIR__ . '/content/x/y/file.md'这样的绝对路径
https://stackoverflow.com/questions/28907400
复制相似问题