gpt4 book ai didi

javascript - Safari 和 Chrome 将表单值添加到 URL

转载 作者:行者123 更新时间:2023-11-30 09:07:45 26 4
gpt4 key购买 nike

长话短说:仅在 Chrome 和 Safari 上,来自登录表单的值有时被粘贴到用户的 URL 中,即使实际登录是通过 AJAX 发布的。

http://my-site.example/?name=user&pw=xxx&challenge=b1be8ad7aac242...

它被反复报道,我亲眼目睹了它的发生,但我自己无法重现,更不用说弄清楚到底是怎么回事了。以下是登录表单的内容:

<form name="login">
<input type="Text" name="name">
<input type="password" name="pw">
<input type="hidden" name="challenge">
<input type="button" onclick='JavaScript:xmlhttpPost("/php/login.php")'>
</form>

实际的 POSTed 请求甚至不包含挑战参数:

function xmlhttpPost(strURL) {
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
...
query = 'name=' + encodeURIComponent(name) + '&pw=' + encodeURIComponent(hash) + '&lpw=' + encodeURIComponent(legacy_hash);
self.xmlHttpReq.send(query);
}

并且在成功登录后,当且仅当用户的语言设置与默认设置不同时,用户才会被重定向回同一页面(= 强制重新加载):

location.href = "http://" + location.host + location.pathname;

有什么想法吗?

最佳答案

在您描述的情况下,表单实际上已发布,可能是因为用户关闭了 Javascript 或 xmlhttpPost 中出现脚本错误。

在某些浏览器中,表单将作为 GET 请求发送,因为您没有指定 method 属性。 (我认为 GET 是标准的正确默认值,但有些浏览器与此不同)。因此,表单数据将在 URL 中结束。

为表单提供一个method="POST":这将修复 URL 部分中的密码数据。

关于javascript - Safari 和 Chrome 将表单值添加到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3541289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com