Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化nginx 配置和演示用例 #83

Merged
merged 24 commits into from
Mar 29, 2022
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change CSP variable name
  • Loading branch information
jingjingxyk committed Mar 27, 2022
commit b4b389e2340d93e125797c96ac543447e2e24b0f
49 changes: 29 additions & 20 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function hasCSP(headers = []) {
* 响应头里CSP相关的选项
* @type {string[]}
*/
const removeCSP=[
const remove_csp_item=[
'content-security-policy',
'content-security-policy-report-only',
'expect-ct',
Expand All @@ -34,7 +34,26 @@ const removeCSP=[
'permissions-policy',
'timing-allow-origin'
];

/**
* 需要移除CSP的URL
* @type {string[]}
*/
const remove_cps_urls=[
"*://ajax.googleapis.com/*",
"*://fonts.googleapis.com/*",
"*://themes.googleusercontent.com/*",
"*://fonts.gstatic.com/*",
"*://*.google.com/*",
"*://secure.gravatar.com/*",
"*://www.gravatar.com/*",
"*://maxcdn.bootstrapcdn.com/*",
'*://api.github.com/*',
'*://www.gstatic.com/*',
'*://stackoverflow.com/*',
'*://translate.googleapis.com/*',
"*://developers.redhat.com/*",
"*://cloud-soft.xieyaokun.com/*"
]
/**
* 移除CSP
* 参考文档:
Expand All @@ -52,36 +71,23 @@ chrome.webRequest.onHeadersReceived.addListener(
tabinfo.set(details.tabId, hasCSP(details.responseHeaders)); //暂时不知道什么地方用到
return {
responseHeaders:details.responseHeaders.filter(
header =>!removeCSP.includes(header.name.toLowerCase())
header =>!remove_csp_item.includes(header.name.toLowerCase())
)
};
},
{
// urls: ["<all_urls>"],
//需要移除CSP自己添加url
urls: [
"*://ajax.googleapis.com/*",
"*://fonts.googleapis.com/*",
"*://themes.googleusercontent.com/*",
"*://fonts.gstatic.com/*",
"*://*.google.com/*",
"*://secure.gravatar.com/*",
"*://www.gravatar.com/*",
"*://maxcdn.bootstrapcdn.com/*",
'*://api.github.com/*',
'*://www.gstatic.com/*',
'*://stackoverflow.com/*',
'*://translate.googleapis.com/*',
"*://developers.redhat.com/*",
"*://cloud-soft.xieyaokun.com/*"
...remove_cps_urls
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"]
},
["blocking", 'responseHeaders']
);

//Open Source urls
let opensource_gogole_urls=[
let opensource_goole_urls=[
"*://*.chromium.org/*", //Chromium ChromiumOS GN
"*://*.googlesource.com/*", //Chromium
"*://summerofcode.withgoogle.com/*",
Expand All @@ -106,7 +112,7 @@ let opensource_gogole_urls=[
* @returns {string}
*
*/
let use_nginx_proxy=(details,proxy_provider='.proxy.domain.com')=>{
let use_nginx_proxy=(details,proxy_provider)=>{
// 主要是和 nginx 配合使用
let url = details.url.replace('http://', 'https://')
// 代理服务提供者 需要支持泛域名
Expand Down Expand Up @@ -164,7 +170,10 @@ chrome.webRequest.onBeforeRequest.addListener(
"*://secure.gravatar.com/*",
"*://www.gravatar.com/*",
"*://maxcdn.bootstrapcdn.com/bootstrap/*",
//...opensource_gogole_urls
/*
...opensource_goole_urls

*/
],
},
["blocking"]
Expand Down