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

maxcdn.bootstrapcdn.com 替换为 lib.baomitu.com ;新增 code.jquery.com 域名下的 jquery 替换 #89

Merged
merged 40 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ee482c4
add func remove CSP
jingjingxyk Mar 2, 2022
bbb7fe8
新增参考文档
jingjingxyk Mar 2, 2022
138ebec
添加测试用例
jingjingxyk Mar 3, 2022
0400e9c
添加替换地址为指定服务地址功能,用于查看chromium源码
jingjingxyk Mar 27, 2022
4589f9e
add docker run nginx server
jingjingxyk Mar 27, 2022
bbdfba5
解决冲突
jingjingxyk Mar 27, 2022
27a70e7
补上80端口配置
jingjingxyk Mar 27, 2022
09f15b8
add opensource.goole url
jingjingxyk Mar 27, 2022
b740c7e
add cs.opensource.google url
jingjingxyk Mar 27, 2022
dc4392e
使用自己架设的 nginx服务地址替换CDN地址
jingjingxyk Mar 27, 2022
b4b389e
change CSP variable name
jingjingxyk Mar 27, 2022
2158dd8
添加固定替换CDN地址方法
jingjingxyk Mar 27, 2022
52d78bf
替换指定数目的域名
jingjingxyk Mar 27, 2022
4147104
添加测试用例
jingjingxyk Mar 28, 2022
d03c0a2
Merge remote-tracking branch 'upstream/master' into dev
jingjingxyk Mar 28, 2022
b9e5722
优化nginx 配置
jingjingxyk Mar 29, 2022
61708ea
优化nginx 配置二
jingjingxyk Mar 29, 2022
0951750
优化nginx 配置三
jingjingxyk Mar 29, 2022
0c54c5b
优化nginx 配置增加简单权限验证阻止滥用
jingjingxyk Mar 29, 2022
0cced24
优化nginx 配置五
jingjingxyk Mar 29, 2022
ca3b908
添加测试演示用例
jingjingxyk Mar 29, 2022
d1b8e4f
添加测试演示用例
jingjingxyk Mar 29, 2022
e1cd17c
修改动态地址替换注释
jingjingxyk Mar 29, 2022
cdf5e8a
修改错误的单词
jingjingxyk Mar 29, 2022
4e5d95e
Merge remote-tracking branch 'upstream/master' into dev
jingjingxyk Mar 29, 2022
7474581
移除与扩展无关的server文件
jingjingxyk Mar 31, 2022
9addc38
去除普通用户无关的测试脚本以及服务端搭建脚本
jingjingxyk Mar 31, 2022
8d27064
Merge remote-tracking branch 'upstream/master' into v2-prune
jingjingxyk Apr 2, 2022
b26aca7
Merge branch 'v2-prune' into v3-prune
jingjingxyk Apr 2, 2022
7f1be04
修改maxcdn.bootstrapcdn.com替换地址
jingjingxyk May 1, 2022
2512852
替换code.jquery.com 为 ajax.aspnetcdn.com
jingjingxyk May 1, 2022
aeac5b5
code.jquery.com 地址替换
jingjingxyk May 1, 2022
c726bab
pull origin source code
jingjingxyk May 1, 2022
091817d
Merge branch 'v3-prune' into v3-prune-jquery
jingjingxyk May 1, 2022
03abc8f
1、增加域名替换白名单机制;2、两种地址替换方法,依靠优先级混合使用;3新增code.jquery.com域名下jquery 替换
jingjingxyk May 3, 2022
8e565ad
delete ytb
jingjingxyk May 3, 2022
da419ba
新增高级玩法
jingjingxyk May 4, 2022
f251867
新增test service-worker
jingjingxyk May 4, 2022
a024d3c
change changelog
jingjingxyk May 4, 2022
cc917e6
add replace jquery-ui
jingjingxyk May 4, 2022
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
Next Next commit
add func remove CSP
  • Loading branch information
jingjingxyk committed Mar 2, 2022
commit ee482c488b86989d1c6384747a4bdf2520662697
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
extension.zip
.idea/
.DS_Store
Thumbs.db
57 changes: 51 additions & 6 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
*/
const tabinfo = new Map();

/**
* 需要去除的响应头
* @type {string[]}
*/
const removeHeaders=[
'content-security-policy',
'content-security-policy-report-only',
'expect-ct',
'report-to',
'x-content-security-policy',
'x-webkit-csp',
'x-xss-protection',
'x-permitted-cross-domain-policies',
'x-content-type-options',
'x-frame-options',
'Permissions-Policy',
'timing-allow-origin'
];
/**
* 扫描响应头,是否含有 Content-Security-Policy
* @param {chrome.webRequest.HttpHeader[]} headers
Expand All @@ -15,15 +33,42 @@ function hasCSP(headers = []) {
);
}

/**
* 移除CSP
* 参考
* 1、 https://developer.chrome.com/docs/extensions/reference/webRequest/#event-onHeadersReceived
* 2、 Arrow_Function 箭头函数
* 3、 return {responseHeaders: details.responseHeaders};
*
*/

chrome.webRequest.onHeadersReceived.addListener(
function (details) {
tabinfo.set(details.tabId, hasCSP(details.responseHeaders));
details=>{
newResponseHeaders:details.responseHeaders.filter(
header =>!removeHeaders.includes(header.name.toLowerCase())
)
},
{
urls: ["<all_urls>"],
types: ["main_frame"],
// urls: ["<all_urls>"],
//需要移除CSP自己添加url
urls: [
"*://ajax.googleapis.com/*",
"*://fonts.googleapis.com/*",
"*://themes.googleusercontent.com/*",
"*://fonts.gstatic.com/*",
"*://www.google.com/recaptcha/*",
"*://secure.gravatar.com/*",
"*://www.gravatar.com/*",
"*://maxcdn.bootstrapcdn.com/bootstrap/*",
'*://api.github.com/*',
'*://www.gstatic.com/*',
'*://stackoverflow.com/*',
'*://translate.googleapis.com/*',
"*://developers.redhat.com/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"]
},
["responseHeaders"]
["blocking", 'responseHeaders']
);

chrome.webRequest.onBeforeRequest.addListener(
Expand Down Expand Up @@ -65,7 +110,7 @@ chrome.webRequest.onBeforeRequest.addListener(
"*://www.google.com/recaptcha/*",
"*://secure.gravatar.com/*",
"*://www.gravatar.com/*",
"*://maxcdn.bootstrapcdn.com/bootstrap/*",
"*://maxcdn.bootstrapcdn.com/bootstrap/*"
],
},
["blocking"]
Expand Down