javascript - 设置 SameSite=none,在 Chrome 扩展中安全

标签 javascript cookies google-chrome-extension manifest.json samesite

在 chrome 最近的 77.0 更新后,我开始在我的 chrome 扩展程序的后台页面上收到此警告。

A cookie associated with a cross-site resource at http://www.google.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

我能够通过设置将扩展恢复到之前的工作状态 SameSite 默认 cookie 为“已启用”。在 chrome://flags 上

当这个临时的客户端修复被禁用时,这段代码被执行,

console.log(rtLink) 

rtLink 返回为未定义,启用客户端修复后,它会正确执行并显示从 google 搜索中找到的 url

//console.log("Background.js is running");

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        fetch(request)
            .then(function(response) {

            return response.text()
            })
            .then(function(html) {
                var parser = new DOMParser();
                var doc = parser.parseFromString(html, "text/html");

                // Finds and sets the first search term URL to rtLink
                var rtLink = doc.getElementsByClassName("r")[0].children[0].href;
                console.log(rtLink);

我的问题是,我该如何设置 SameSite=Lax(或 None)和 Secure 我的获取请求/响应,或者我可能问错了问题。如果是这种情况,我必须具体更改哪些内容才能适应此 cookie 更改?

最佳答案

对于这些警告中的任何一个,如果您不对域负责,则您不负责更新 cookie。在这种情况下,Google 负责更新为来自 google.com 的 cookie 设置 SameSite 属性的相关代码。

此时,警告仅供引用,不会影响功能。直到 M80 才计划在稳定的 Chrome 中强制执行此行为,目前目标是 2020 年 2 月。

如果您希望 cookie 与您的 fetch 请求一起发送,您应该确保您是 explicitly including them .

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        fetch(request, { credentials: 'include' })
            .then(function(response) { // snip

关于javascript - 设置 SameSite=none,在 Chrome 扩展中安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58441115/

相关文章:

php - 为什么我不能在我的 php 脚本中使用 session_start()?它说标题已经发送

javascript - Firebase 不断执行对 .lp 的请求?

javascript - 如何触发 chrome.tabs onClick 事件

javascript - 单击不适用于可观察的数组元素

javascript - 使用触发 javascript 验证的 POST 表单和 AJAX 到 PHP 文件登录。将数据存储到 PHP 时出现问题

swift - 加载单独的 WKWebViews 时单独的 cookies?

python - Flask 回调未通过 pytest 运行

google-chrome-extension - "chrome.tabs.create"有效,但 "chrome.tabs.update"无效

javascript - 在 D3.js 中的 Bundle 布局中读取 JSON 文件时出错

javascript - 如何在一行中的 JavaScript 中的文件名和文件扩展名之间添加一个随机字符串?