gpt4 book ai didi

javascript - 如何确定将哪个站点添加到 cookie 白名单?

转载 作者:行者123 更新时间:2023-11-29 20:26:03 26 4
gpt4 key购买 nike

有一个银行网站,除非我允许接受所有 cookie,否则我无法登录。我使用的是 Firefox 3.0,我已将其设置为不接受定义列表以外的 cookie(工具 - 选项 - 隐私 - Cookies - 异常(exception))。我已经将 Live HTTP Headers 捕获的所有站点添加到白名单中,但登录仍然被禁用。我已尝试启用所有 cookie 并登录,然后查看我收到的 cookie - 没有看到任何新站点被添加到异常(exception)列表中。显然,该网站正在以某种方式检查我是否接受了任意 cookie。我如何找出哪些站点需要列入白名单?还是我对 cookie 不了解,接受所有 cookie 与将所有正确的网站列入白名单在某种程度上是不一样的?

站点是https://www.citizensbank.ca/并且它仅在允许任何 cookie 时显示登录字段,否则显示消息“要登录网上银行,您必须启用 JavaScript 和 cookie。”

最佳答案

我会给自己换另一台机器(或 VMWare 镜像),删除所有 cookie,允许来自所有站点的所有 cookie,然后转到您的站点并登录(这听起来与您已经尝试过的类似)。

然后,在您的银行业务 session 结束后(或者在此期间,如果他们创建一个短暂的 cookie 只是为了测试您启用了它们),请查看您的 cookie jar 以了解银行添加了什么。这应该会告诉您需要添加到您的真实计算机的域。

如果这不起作用,请联系银行并解释您的问题。他们会告诉您需要允许哪些,或者他们会告诉您全部允许。如果是后者,您需要决定它们是否仍然值得保留为您的银行。

或者,您可以:

  • 如果您不希望所有 cookie 都出现在您的主框中,请将您设置为沙箱的虚拟机用于访问银行。
  • 设置脚本以在 FF 关闭后删除所有非白名单 cookie。
  • 完全不用担心 cookie,只要允许它们(我想我从未听说过 cookie 被用作攻击媒介)。

如果您愿意,请将您的帐户详细信息(用户名/密码)发送给我,我会看看是否可以从这里对其进行调试 :-) 开个玩笑(以防它不是很明显)。

更新:

您的银行有一种特别邪恶的方式来检查要求。他们会检查您是否接受所有 cookie,这是他们根本没有业务可做的事情。他们应该看看他们是否可以创建一个 cookie 并将其读回,这将使他们与 cookie 管理器兼容。

他们的代码是:

function testCookie() {
if (typeof navigator.cookieEnabled !== "undefined") {
return !!navigator.cookieEnabled;
} else{
document.cookie="testcookie";
return document.cookie.indexOf("testcookie")!=-1;
}
}
if(!testCookie()){
var browserWarningString = '';
browserWarningString += '<div class="warning">';
browserWarningString += '<p>To login to online banking, you must have
JavaScript and cookies enabled.</p>';
browserWarningString += '</div>\n';
document.getElementById("loginAuth").innerHTML = browserWarningString;
}

这是 testCookie() 的第一位,return !!navigator.cookieEnabled 位有问题。在这里再多的白名单 URL 也无济于事,因为只有当全局 cookieEnabled 设置为 true 时才会检查(这不适合你,这是正确的)。

理想情况下,您只需替换掉下来的 HTML 中的 testCookie() 函数即可。

我找到了一个类似的网站,它讨论了来自不同银行的相同问题(我猜银行是所有脑残的 Javascript child 最终去的地方:-) here ,以及两个建议的解决方案。

首先是安装 GreaseMonkey 并使用此脚本 here .显然,这需要针对您的银行进行更改(URL、功能名称等)。

上面第一个链接的最后一篇文章(目前,请查找“afternoonnap, February 15th, 2009, 10:10 am”文章)也展示了如何使用 NoScript 实现相同的结果。这涉及用更合理的脚本替换 cookieEnabled 脚本(针对该特定页面),尽管我可能只是选择用 "return true" 替换它并挂起后果 :-)。

希望有所帮助。

为了完整起见(以防链接消失),我将在此处包含这两个脚本。 GreaseMonkey 归结为:

// ==UserScript==
// @name TD Canada Trust EasyWeb Repair
// @namespace tag:GossamerGremlin,2007-04-28:Repair
// @description Repair TD Canada Trust EasyWeb website.
// @include https://easyweb*.tdcanadatrust.com/*
// @exclude
// ==/UserScript==

var scriptName = "TD Canada Trust EasyWeb Repair";

// The above @include pattern is overbroad because it exposes this
// user script to potential attacks from URLs such as this:
// https://easyweb.evil.example.com/not.tdcanadatrust.com/bad.html
// The following check eliminates such possibilities:
if (location.href.match(/^https:\/\/easyweb\d\d[a-z].tdcanadatrust.com\//))
{
// Visibly mark page to remind that this script is in use.
if (document.body)
{
host = document.location.host;
dummyDiv = document.createElement('div');
dummyDiv.innerHTML = '<div><span style="color: red">Greased by: ' +
scriptName + ' (' + host + ')</span></div>';
document.body.insertBefore(dummyDiv.firstChild,
document.body.firstChild);
}
unsafeWindow.navigator.__defineGetter__("cookieEnabled",
canStoreCookieFixed);
}

// canStoreCookieFixed()
// TD's version relies on navigator.cookieEnabled, which is not set
// if customer has cookie manager, even when cookies are allowed for
// EasyWeb. The only reliable check for enabled cookies is to actually
// test if session cookie settings succeed, as done in this function
// replacement.
function canStoreCookieFixed()
{
var testSessionCookie ="testSessionCookie=Enabled";
document.cookie = testSessionCookie;
return (document.cookie.indexOf(testSessionCookie) != -1);
}

NoScript 版本归结为“将以下内容添加到 about:config”:

noscript.surrogate.nce.sources=@easyweb*.tdcanadatrust.com

noscript.surrogate.nce.replacement=navigator.__defineGetter__(
"cookieEnabled",function(){
var ed=new Date;
ed.setTime(0);
var tc="__noscriptTestCookie_"+Math.round((Math.random()*99999))
.toString(16)+"=1";
document.cookie=tc;
var ok=document.cookie.indexOf(tc)>-1;
document.cookie=tc+";expires="+ed.toGMTString();
return ok
}
);

测试和更新:

当我在 FF3 中安装 noscript 并完全关闭 cookies,然后添加以下 about:config 项时,登录提示会显示您的银行,所以我认为这可能是可行的方法:

noscript.surrogate.nce.sources     = *.citizensbank.ca
noscript.surrogate.nce.replacement =
navigator.__defineGetter__("cookieEnabled",function(){return true});

我建议您这样做并对其进行测试,以确保您仍然拥有所有功能。

关于javascript - 如何确定将哪个站点添加到 cookie 白名单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/942518/

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