Skip to content

Commit 5c34517

Browse files
committed
20260510-1243 修复看不了旧文章的bug
1 parent 940a0e2 commit 5c34517

2 files changed

Lines changed: 55 additions & 34 deletions

File tree

CCW-Code-Injection-Risk-Warning.user.js

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @name CCW-Code-Injection-Risk-Warning
33
// @description CCW代码注入风险警告,让你的账号更安全。
44
// @author bddjr
5-
// @version 20260509-1820
5+
// @version 20260510-1243
66
// @match https://www.ccw.site/*
77
// @match https://learn.ccw.site/*
88
// @match https://m.ccw.site/*
@@ -14,34 +14,59 @@
1414
// ==/UserScript==
1515
//@ts-nocheck
1616

17-
// Source Code:
17+
// 更多注意事项,请看源代码仓库:
1818
// https://github.com/bddjr/CCW-Code-Injection-Risk-Warning
1919

20-
if (location.hostname == 'learn.ccw.site') {
20+
if (location.hostname == 'm.ccw.site') {
21+
// 基于新标签页访问 svg 网址的代码注入攻击
22+
// 脚本无法防御该攻击,因为攻击者的代码先执行。
23+
// 参考 https://github.com/bddjr/CCW-Code-Injection-Risk-Warning/issues/3
24+
if (document.contentType == 'image/svg+xml') {
25+
try {
26+
window.stop()
27+
} catch (e) { }
28+
alert(`【脚本 CCW代码注入风险警告】
29+
30+
您正在使用标签页访问svg,恶意代码可能已经执行。
31+
建议您关掉该标签页,然后尽快修改您的账号的密码。
32+
如果攻击者已经使用您的账号捣乱,请及时向共创世界管理员或鸭鸭院长申诉。`)
33+
}
34+
35+
} else if (location.hostname == 'learn.ccw.site' || location.pathname.toLowerCase().startsWith('/post/')) {
2136
// 自动防御基于 iframe 的代码注入攻击,仅允许白名单网址
2237

2338
// 创作者学院编辑器提示:暂时只支持bilibili和西瓜视频以及站内链接
2439
// 查找并分析js文件
2540
// https://learn.ccw.site/_next/static/chunks/708-9a7dbfbb32eca7d3.js
2641
// https://learn.ccw.site/_next/static/chunks/5191-e0df96b8928838d4.js
2742
// https://learn.ccw.site/_next/static/chunks/app/(normal)/home/layout-a9cb46b1ff2d4762.js
28-
// 创作者学院前端支持插入的 URL origin :
43+
// 创作者学院前端支持插入的 URL origin :
2944
// [
30-
// "https://scratch.mit.edu",
31-
// "https://youtube.com",
32-
// "https://www.facebook.com",
33-
// "https://www.twitch.tv",
34-
// "https://twitter.com",
35-
// "https://qa.cocrea.world",
36-
// "https://www.ixigua.com",
37-
// "https://ixigua.com",
38-
// "https://bilibili.com",
39-
// "https://player.bilibili.com",
40-
// "https://www.bilibili.com",
41-
// "https://www.ccw.site",
42-
// "https://ccw.site",
43-
// "https://learn.ccw.site",
44-
// "https://learn-qa.xiguacity.cn"
45+
// // 境内不能直连的,非必要
46+
// "https://scratch.mit.edu",
47+
// "https://youtube.com", // 重定向到 www.youtube.com
48+
// "https://www.facebook.com",
49+
// "https://www.twitch.tv",
50+
// "https://twitter.com", // 重定向到 x.com
51+
//
52+
// // 已无 DNS 解析
53+
// "https://qa.cocrea.world",
54+
//
55+
// // 西瓜视频已改名为抖音精选,以下旧域名会重定向到 www.douyin.com/jingxuan
56+
// // 目前为止没看到有人嵌入这个网站的视频,非必要
57+
// "https://www.ixigua.com",
58+
// "https://ixigua.com",
59+
//
60+
// // bilibili
61+
// "https://bilibili.com",
62+
// "https://player.bilibili.com",
63+
// "https://www.bilibili.com",
64+
//
65+
// // CCW
66+
// "https://www.ccw.site",
67+
// "https://ccw.site",
68+
// "https://learn.ccw.site",
69+
// "https://learn-qa.xiguacity.cn" // 已无 DNS 解析
4570
// ]
4671
// 或者 origin 包含 "ccw.site" 或 "xiguacity.cn" 。
4772
// 仅在编辑器里插入的时候会校验,但查看文章的时候加载iframe前不会校验。
@@ -50,8 +75,15 @@ if (location.hostname == 'learn.ccw.site') {
5075
// 定义自己的白名单
5176
// 参考 https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/frame-src
5277
const whitelist = [
78+
// CCW 兼容旧文章
79+
"https://ccw.site/post/",
80+
"https://www.ccw.site/post/",
81+
82+
// CCW 使用 embed 页面嵌入作品,不会在点开文章的时候立即执行恶意代码
5383
"https://www.ccw.site/embed",
5484
"https://ccw.site/embed",
85+
86+
// bilibili 嵌入视频
5587
"https://player.bilibili.com/player.html",
5688
"https://www.bilibili.com/video/",
5789
"https://bilibili.com/video/",
@@ -62,21 +94,6 @@ if (location.hostname == 'learn.ccw.site') {
6294
document.head.appendChild(meta)
6395
console.log('【脚本 CCW代码注入风险警告】自动防御基于 iframe 的代码注入攻击,仅允许白名单网址\n', meta, '\n', whitelist)
6496

65-
} else if (location.hostname == 'm.ccw.site') {
66-
// 基于svg的代码注入攻击
67-
// 脚本无法防御该攻击,因为攻击者的代码先执行。
68-
// 参考 https://github.com/bddjr/CCW-Code-Injection-Risk-Warning/issues/3
69-
if (document.contentType == 'image/svg+xml') {
70-
try {
71-
window.stop()
72-
} catch (e) { }
73-
alert(`【脚本 CCW代码注入风险警告】
74-
75-
您正在使用标签页访问svg,恶意代码可能已经执行。
76-
建议您关掉该标签页,然后尽快修改您的账号的密码。
77-
如果攻击者已经使用您的账号捣乱,请及时向共创世界管理员或鸭鸭院长申诉。`)
78-
}
79-
8097
} else {
8198
// www.ccw.site
8299

const meta = document.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const meta = document.createElement('meta')
2+
meta.setAttribute('http-equiv', 'content-security-policy')
3+
meta.setAttribute('content', `default-src 'self' 'unsafe-eval' 'unsafe-inline' https://*.ccw.site https://*.xiguacity.cn https://zhishi.oss-cn-beijing.aliyuncs.com/ https://*.qq.com;`)
4+
document.head.appendChild(meta)

0 commit comments

Comments
 (0)