javascript - Chrome 不会提醒 cookie,但 Firefox 会

标签 javascript google-chrome cookies alert

<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>

Cookie 不想在 chrome 中提醒,但它在 Firefox 中有效,但只显示用户名。有人有什么建议吗?

最佳答案

是的,我知道这是一个很老的问题了,但我用谷歌搜索了同样的东西。

我是一名渗透测试人员,所以在测试 XSS 和其他各种与 Javascript 相关的攻击时,警报是我想使用的一种非常常用的方法。

然而,在 Chrome 中,它似乎非常断断续续地工作。

这是一个可能有帮助的答案:

window is an instance of DOMWindow, and by setting something to window.alert, the correct implementation is being "shadowed", i.e. when accessing alert it is first looking for it on the window object. Usually this is not found, and it then goes up the prototype chain to find the native implementation. However, when manually adding the alert property to window it finds it straight away and does not need to go up the prototype chain. Using delete window.alert you can remove the window own property and again expose the prototype implementation of alert. Quote by "Matty F" - alert() not working in Chrome

希望对您有所帮助!

[编辑] 此外,Chrome 有一个内置的 XSS 过滤器,所以当你进行可疑事件时,例如警告 document.cookie 等,Chrome 会过滤掉它认为是恶意的东西。如果您使用 --disable-xss-audit 参数启动 Chrome,有多种方法可以关闭此功能,但是,在我看来,这似乎比它的值(value)更麻烦。

关于javascript - Chrome 不会提醒 cookie,但 Firefox 会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16070241/

相关文章:

android - 如何防止 Retrofit 自动跟随 302

javascript - 如何使用 cookie 记住 html 中的按钮切换或类?

Javascript:将参数传递给对象和函数......?

javascript - 余额仍停留在5000

google-chrome - Chrome 59+ websocket 框架在 DevTools 中不再可见

jquery - 如何使用 chrome 扩展/插件访问 HTML 元素?

javascript - 控制台中结果为 4.08-1.36

javascript - 公开函数并返回对象

JavaScript 正则表达式 : successive matches

Java HttpServletResponse addCookie 在 chrome 和 ie 上没有用