Chrome不会警告Cookie,但Firefox会。

3
<html>
<head>
<title>cookie</title>
<script type = "text/javascript">
var user_name;
var del = new Date();
document.write(del.toGMTString());

function check() { 
    user_name = document.getElementById("user").value;
    del.setFullYear(del.getFullYear() + 1);
    document.cookie = escape("name") + "=" + escape(user_name) + ";expires = "+ del.toGMTString();
    alert(document.cookie);
}

</script>
</head>
<body>
<form>
username : <input type = "text" id = "user"></input>
<input type = "button" value = "enter" onClick = "check()"></input>
</form>

</body>


</html>

在Chrome中Cookie不想弹出警报,但是在Firefox中可以工作,但只显示用户的名称。有人有什么建议吗?


Chrome 有弹出任何警报吗?你在 Chrome 中实际设置了 cookie 吗? - Lee Taylor
document.write 是用来做什么的?如果将其删除会发生什么?此外,您是否在浏览器控制台中看到任何 JS 错误? - Spudley
在Chrome中只会出现一个警告框,但它不会显示存储在cookie中的任何信息。它是空的。在Firefox中,它只显示名称=您输入的名称,但不显示时间。 - Andriy Haydash
1个回答

1

我知道这是一个比较老的问题了,但我搜索了一下相同类型的问题。

我是一个渗透测试员,因此在测试XSS和其他各种与Javascript相关的攻击时,alert是我想要使用的常见方法。

然而,在Chrome中,它似乎很难确定何时想要使用。

以下是可能有所帮助的答案:

window是DOMWindow的一个实例,通过将某些东西设置为window.alert,正确的实现被“shadowed”,即当访问alert时,它首先在window对象上查找。通常找不到,然后沿着原型链向上查找以找到本地实现。但是,当手动添加alert属性到窗口时,它立即找到并且不需要沿着原型链进行。使用delete window.alert可以删除窗口自己的属性,并再次公开alert的原型实现。 引用者"Matty F" - alert() not working in Chrome

希望这可以帮助到您!

[编辑] 此外,Chrome内置了XSS过滤器,因此当您进行可疑活动时,例如警报document.cookie等,Chrome会过滤掉它认为是恶意的内容。如果您使用--disable-xss-audit参数启动Chrome,则可以关闭此功能,但在我看来,这似乎不值得麻烦。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接