在这种情况下,如何使用PHP防止javascript(http://my_host_here.com/publicati
how do I prevent javascript in this situation using PHP (http://my_host_here.com/publications.php/"><script>alert(1)</script>)?
我已经尝试了下面的代码,但javascript似乎是在http请求发送到服务器之前运行的。
感谢
<?php
class secure
{
function secureSuperGlobalGET(&$value, $key)
{
$_GET[$key] = htmlspecialchars(stripslashes($_GET[$key]));
$_GET[$key] = str_ireplace("script", "blocked", $_GET[$key]);
$_GET[$key] = mysql_escape_string($_GET[$key]);
return $_GET[$key];
}
function secureSuperGlobalPOST(&$value, $key)
{
$_POST[$key] = htmlspecialchars(stripslashes($_POST[$key]));
$_POST[$key] = str_ireplace("script", "blocked", $_POST[$key]);
$_POST[$key] = mysql_escape_string($_POST[$key]);
return $_POST[$key];
}
function secureGlobals()
{
echo "in here";
array_walk($_GET, array($this, 'secureSuperGlobalGET'));
array_walk($_POST, array($this, 'secureSuperGlobalPOST'));
}
}
?>
- "安全"地开除你的班级
- 对于作为带引号的字符串传入SQL查询的值,仅使用
mysql_[real_]escape_string
- 任何其他SQL部分都必须根据其角色进行格式化
- 在组装查询之前设置SQL部分的格式,而不是在其他地方
- 或者更好地使用占位符
最后,为了回答您的问题:在回显用户提交的值时,对其使用htmlspecialchar((。
如果在代码返回服务器之前运行Javascript,那么这很可能是某种形式的基于DOM的XSS。Javascript可能提取/"><script>alert(1)</script>
的值并将其直接放入DOM中。您可能需要更改客户端处理此问题的方式。
OWASP对如何抵御基于DOM的跨站点脚本攻击进行了精彩的概述,例如以下内容:https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet
相关文章:
- 如何在My chrome扩展中获取其他chrome扩展的DOM访问权限
- 为什么不是't my元素:使用变量而不是字符串时包含(变量)功?jquery
- Will my'新对象'在套接字断开连接时被垃圾收集
- 为什么不是't my css `content:`在多个浏览器中工作,并总体上提高跨浏览器兼容性
- toDataURL(), from the Web onto my Computer
- 允许 My(!) 站点与 Iframe 通信
- xxxx@my.csun.edu 正则表达式的自定义电子邮件验证
- Python 3, Web-scraping, and Javascript [Oh My]
- javascript:I want to count words in my textarea it does'
- jquery+draggable/my的输入在删除后不起作用
- 使用Just My Code在Visual Studio 2013中调试Javascript
- 使用deferred.resolve(Value)返回给my.then()的值未定义
- 在 CreateJS 中显示未捕获的类型错误.下面给出了不显示任何 output.my 代码
- 无法使用 AJAX 和 jQuery 将 POST 到 my API
- 通过 window.location.host 比较 URL
- My localStorage.clear(); won't work
- Javascript openWindow with my Chart
- 将网站网址更改为 http://my.url#menuitem 在单击菜单项时
- 使用 JavaScript 方法从 iframe 到 my page(JavaScript)
- wiered javascript result in my code undefiend variable