如何确保以下基于DOM的XSS攻击?
具体来说,是否有一个protect()函数,使下面的安全吗?
如果没有,那么还有另一种解决方案吗?
例如:给div一个id然后再为该元素分配一个onclick处理程序
function protect()
{
// For non-DOM XSS attacks, hex-encoding all non-alphanumeric characters
// with ASCII values less than 256 works (ie: \xHH)
// But is it possible to augment this function to protect against
// the below DOM based XSS attack?
}
?>
var xss = "<?php echo protect($_GET["xss"]) ?>";
$("#mydiv").html("
我希望答案不是“避免使用innerHTML”或“正则表达式xss变量到[a-zA-Z0-9]”……即:是否有更通用的解决方案?
谢谢
解决方法:
扩展Vineet的回复,这里有一组测试用例:
标签:php,javascript,dom,xss
来源: https://codeday.me/bug/20190630/1338984.html