maj*_*son 7 xmlhttprequest csrf google-chrome-extension cors fetch-api
我正在尝试制作一个Chrome扩展程序,它使用Fetch API从Github上的Pull Requests中删除一些细节,然后将它们显示在其他位置.当我尝试在Github上使用非公共存储库时,我遇到了一些问题.我认为这与CSRF保护以及管理Chrome扩展程序有权访问会话Cookie的规则有关.
我在扩展程序中有以下内容manifest.json
:
"content_scripts": [{
"matches": [
"*://github.com/*/*/pulls"
],
"js": ["script/underscore-1.8.3.min.js", "script/content.js"]
}],
"permissions": [
"tabs",
"activeTab",
"*://github.com/*",
"webNavigation"
]
Run Code Online (Sandbox Code Playgroud)
但是当我从我的内部运行以下内容时script/content.js
:
fetch('/redacted/redacted/pull/4549', {credentials: 'same-origin'}).then((response) => {
return response.text();
}).then((text) => {
// do cool stuff
})
Run Code Online (Sandbox Code Playgroud)
这会产生Github的404响应.使用Chrome Inspector的网络标签检查此请求,我可以看到它没有向请求发送我的GitHub会话标头.
如果我使用Inspector中的Javascript提示发出相同的请求,我可以看到200响应,我可以看到它正在发送我的会话cookie.
我的理解是在我的指定Github域manifest.json
意味着我的扩展可以访问我的内容脚本中的会话数据,这是不正确的?我应该怎么做才能对此受保护内容提出有效请求?
根据Chrome博客,要包含您需要的Cookie credentials: 'include'
而不是credentials: 'same-origin'
.
归档时间: |
|
查看次数: |
2186 次 |
最近记录: |