1

在 PHP 中,我需要使用用户的输入作为文件夹的标题。

例如:

$foldername = $_REQUEST["foldername"];
mkdir("./userfolders/".$foldername);

因为,我看到的一个问题是输入可能包含一个“../”,这会导致文件夹被写入父目录,这是我不想要的。我对此的解决方案是str_replace去掉字符串中的所有正斜杠。

还有其他我错过的漏洞吗?

4

2 回答 2

1
于 2012-12-10T08:45:58.977 回答
1

Is there a possibility you can use the urlencode function on the folder name variable. When showing the folder to the user you can then use urldecode.

$foldername = urlencode($_REQUEST["foldername"]);
mkdir("./userfolders/".$foldername);

// Show folder name
echo urldecode($foldername);
于 2012-12-10T08:53:16.067 回答