我遇到了 PHP 中的 URL 路由问题。
在我的本地主机上,我有两个项目目录:
- 项目一:
- index.php
- 其他目录
- 项目一:
- 黑客脚本:
- index.php
- database_dump.php
- 黑客脚本:
当我必须访问我的 project_one 时,我会使用 localhost/project_one
这个工作正常。但是当我在这个 localhost/project_one/../../hacking_script
中输入时,它打开了 localhost/hacking_script/index.php
文件。
所以如何预防,我没有任何想法。我可以使用 .htaccess 来防止它吗?如果是那么怎么办?
最佳答案
如果您在谈论路由,那么您就是在谈论这个:
Request -> Router -> GetController -> ExecuteAction
这意味着 GetController
很可能会include
或 require
一些文件...有一部分,你需要确定,它只需要允许的文件。例如 whitelist (这是推荐的方式)。或者确保不允许使用 ../
等特殊字符。
关于php - URL 安全漏洞修复 '../',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36980771/