bbt*_*ang 2 php security variables url
我是在线网络应用程序的新手.我使用的是php,我得到了这段代码:
if(isset($_GET['return']) && !empty($_GET['return'])){
return = $_GET['return'];
header("Location: ./index.php?" . $return);
} else {
header("Location: ./index.php");
Run Code Online (Sandbox Code Playgroud)
}
的$return变量是URL变量可以由黑客容易地改变.
我$return从这里得到变量:www.web.com/verify.php?return=profile.php
有什么我应该注意的吗?我应该在这一行中使用htmlentities:
header("Location: ./index.php?" . htmlentities($return));
Run Code Online (Sandbox Code Playgroud)
它是否容易受到黑客的攻击?
我该怎么做才能防止黑客入侵?
除了第2行的拼写错误(应该是$ return = $ _GET ['return'];)你应该执行$ return = urlencode($ return)以确保$ return是一个有效的QueryString,因为它作为参数传递给索引.PHP.
然后index.php应验证返回是用户有权访问的有效URL.我不知道你的index.php是如何工作的,但是如果它只是显示一个页面,那么你最终会得到像index.php?/ etc/passwd或类似的东西,这可能确实是一个安全问题.
编辑:你得到什么安全漏洞?我可以看到两个可能的问题,具体取决于index.php如何使用返回值:
如上所述,您希望确保通过查询字符串传入的URL有效.一些方法可以是:
有很多方法可以为这只猫提供皮肤,但通常你想要以某种方式验证$ return指向一个有效的目标.这些有效目标取决于您的规格.
| 归档时间: |
|
| 查看次数: |
971 次 |
| 最近记录: |