advisers 0.2.0-preview.71 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +130 -201
- package/NOTICE +29 -4
- package/README-zh.md +32 -6
- package/README.md +36 -7
- package/THIRD-PARTY-NOTICES.md +277 -0
- package/bin/advisers.js +1634 -290
- package/index.js +1 -1
- package/lib/attachments.js +153 -27
- package/lib/capture.js +82 -2
- package/lib/evidence.js +1180 -26
- package/lib/ical.js +542 -0
- package/lib/imap.js +82 -24
- package/lib/mcp-server.js +869 -0
- package/lib/model.js +151 -2
- package/lib/notify.js +129 -3
- package/lib/pdf.js +44 -6
- package/lib/pet-brief.js +78 -15
- package/lib/receipt-verify.js +624 -0
- package/lib/remind.js +261 -11
- package/lib/research.js +142 -18
- package/lib/safety/classifier.js +392 -0
- package/lib/safety/explain.js +157 -0
- package/lib/safety/index.js +333 -0
- package/lib/safety/redact.js +212 -0
- package/lib/safety/rules.js +824 -0
- package/lib/scheduler.js +399 -0
- package/lib/source.js +294 -0
- package/lib/sqlite.js +361 -37
- package/lib/sync.js +58 -13
- package/lib/tos/index.js +332 -0
- package/lib/tos/manifest.json +32 -0
- package/lib/tos/privacy.zh-CN.md +136 -0
- package/lib/tos/safety.zh-CN.md +101 -0
- package/lib/tos/summary.zh-CN.md +12 -0
- package/lib/tos/terms.zh-CN.md +439 -0
- package/package.json +7 -6
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-safety rule matrix (local, offline, zero-dependency).
|
|
3
|
+
*
|
|
4
|
+
* This module is DATA + a tiny compiler. It contains the 14-category violation
|
|
5
|
+
* matrix used by `lib/safety/classifier.js`, the narrow block allowlist, and a
|
|
6
|
+
* deterministic ruleset digest for audit reasons.
|
|
7
|
+
*
|
|
8
|
+
* Design constraints (see docs/CONTENT-SAFETY.md):
|
|
9
|
+
* - block is intentionally narrow: only child sexual exploitation, terrorism
|
|
10
|
+
* operations, direct illegal instruction, weaponized malware, and bulk
|
|
11
|
+
* personal-data exfiltration may produce `action: 'block'`.
|
|
12
|
+
* - self-harm is never blocked; it maps to a crisis hint (`action: 'warn'`).
|
|
13
|
+
* - ordinary office text must stay `allow` (zero disturbance).
|
|
14
|
+
* - the rule set is overridable with a JSON object, but a JSON override can
|
|
15
|
+
* never widen the block surface and can never disable the child-safety
|
|
16
|
+
* hard-block rules.
|
|
17
|
+
* - no network, no third-party dependencies; only node:crypto for digests.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { createHash } from 'node:crypto'
|
|
21
|
+
|
|
22
|
+
export const RULESET_VERSION = 'advisers-content-1'
|
|
23
|
+
|
|
24
|
+
/** Actions a rule/result may carry. `allow` is only ever a classifier result. */
|
|
25
|
+
export const ACTIONS = Object.freeze(['allow', 'warn', 'confirm', 'redact', 'block'])
|
|
26
|
+
export const SEVERITIES = Object.freeze(['low', 'medium', 'high', 'critical'])
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Categories that are allowed to carry a block rule at all. Inside these
|
|
30
|
+
* categories only rules explicitly marked `blockable` may block.
|
|
31
|
+
*/
|
|
32
|
+
export const BLOCK_CATEGORIES = Object.freeze(['sexual', 'terrorism', 'illegal', 'malware', 'pii'])
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The 14-category matrix. Legal references are pointers for reviewers, not a
|
|
36
|
+
* compliance claim; see docs/CONTENT-SAFETY.md for the honest scope statement.
|
|
37
|
+
*/
|
|
38
|
+
export const CATEGORIES = Object.freeze([
|
|
39
|
+
{
|
|
40
|
+
id: 'political',
|
|
41
|
+
labelZh: '危害国家安全类',
|
|
42
|
+
labelEn: 'state security',
|
|
43
|
+
basis: '《网络信息内容生态治理规定》6(一)(二)(三);《生成式人工智能服务管理暂行办法》4(一)',
|
|
44
|
+
defaultAction: 'confirm',
|
|
45
|
+
blockScope: '不 block(窄口径外);仅 confirm/warn',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'terrorism',
|
|
49
|
+
labelZh: '恐怖主义与极端主义',
|
|
50
|
+
labelEn: 'terrorism and extremism',
|
|
51
|
+
basis: '《网络信息内容生态治理规定》6(五);《生成式人工智能服务管理暂行办法》4(一)',
|
|
52
|
+
defaultAction: 'block',
|
|
53
|
+
blockScope: '仅操作指引/袭击实施类 block 规则',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'hate',
|
|
57
|
+
labelZh: '仇恨与歧视',
|
|
58
|
+
labelEn: 'hate and discrimination',
|
|
59
|
+
basis: '《网络信息内容生态治理规定》6(六)(七);《生成式人工智能服务管理暂行办法》4(二)',
|
|
60
|
+
defaultAction: 'confirm',
|
|
61
|
+
blockScope: '不 block;明确煽动走 confirm',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'sexual',
|
|
65
|
+
labelZh: '淫秽色情(含儿童性剥削)',
|
|
66
|
+
labelEn: 'sexual content (incl. child sexual exploitation)',
|
|
67
|
+
basis: '《网络信息内容生态治理规定》6(九);《未成年人网络保护条例》',
|
|
68
|
+
defaultAction: 'warn',
|
|
69
|
+
blockScope: '仅 CSAM 硬拦规则 block;成人色情 warn/confirm',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'violence',
|
|
73
|
+
labelZh: '暴力与凶杀',
|
|
74
|
+
labelEn: 'violence',
|
|
75
|
+
basis: '《网络信息内容生态治理规定》6(五)(九)',
|
|
76
|
+
defaultAction: 'warn',
|
|
77
|
+
blockScope: '不 block;直接暴力教唆走 illegal 类别',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'selfharm',
|
|
81
|
+
labelZh: '自伤与自杀(危机响应)',
|
|
82
|
+
labelEn: 'self-harm (crisis response)',
|
|
83
|
+
basis: '《网络信息内容生态治理规定》6(五);危机干预优先于阻断',
|
|
84
|
+
defaultAction: 'warn',
|
|
85
|
+
blockScope: '永不 block;只触发 crisis 提示',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'minors',
|
|
89
|
+
labelZh: '未成年人保护',
|
|
90
|
+
labelEn: 'minor protection',
|
|
91
|
+
basis: '《未成年人网络保护条例》',
|
|
92
|
+
defaultAction: 'confirm',
|
|
93
|
+
blockScope: '不 block;收紧其它类别(无年龄核验)',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'pii',
|
|
97
|
+
labelZh: '个人信息与隐私',
|
|
98
|
+
labelEn: 'personal data and privacy',
|
|
99
|
+
basis: '《个人信息保护法》;《网络信息内容生态治理规定》6(十)',
|
|
100
|
+
defaultAction: 'redact',
|
|
101
|
+
blockScope: '仅批量外泄规则 block;单条 PII 一律 redact',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'deepfake',
|
|
105
|
+
labelZh: '深度合成与冒充',
|
|
106
|
+
labelEn: 'deep synthesis and impersonation',
|
|
107
|
+
basis: '《互联网信息服务深度合成管理规定》;《人工智能生成合成内容标识办法》',
|
|
108
|
+
defaultAction: 'confirm',
|
|
109
|
+
blockScope: '不 block;confirm + 标识提示',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'fraud',
|
|
113
|
+
labelZh: '欺诈与商业违法',
|
|
114
|
+
labelEn: 'fraud and commercial illegality',
|
|
115
|
+
basis: '《网络信息内容生态治理规定》6(九);《广告法》',
|
|
116
|
+
defaultAction: 'warn',
|
|
117
|
+
blockScope: '不 block;明确诈骗话术 confirm',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'malware',
|
|
121
|
+
labelZh: '恶意代码与网络攻击',
|
|
122
|
+
labelEn: 'malware and cyberattack',
|
|
123
|
+
basis: '《网络安全法》;《刑法》第285/286条',
|
|
124
|
+
defaultAction: 'confirm',
|
|
125
|
+
blockScope: '仅武器化载荷 block;双用途安全研究 confirm/warn',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'illegal',
|
|
129
|
+
labelZh: '违法犯罪教唆',
|
|
130
|
+
labelEn: 'illegal instruction',
|
|
131
|
+
basis: '《网络信息内容生态治理规定》6(九);《刑法》相关条款',
|
|
132
|
+
defaultAction: 'confirm',
|
|
133
|
+
blockScope: '仅直接教唆/操作指引 block',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: 'harassment',
|
|
137
|
+
labelZh: '侮辱诽谤与网络暴力',
|
|
138
|
+
labelEn: 'harassment and cyberbullying',
|
|
139
|
+
basis: '《网络信息内容生态治理规定》6(十);《网络暴力信息治理规定》',
|
|
140
|
+
defaultAction: 'warn',
|
|
141
|
+
blockScope: '不 block;confirm/warn 并保留证据',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: 'injection',
|
|
145
|
+
labelZh: '提示注入与越权指令',
|
|
146
|
+
labelEn: 'prompt injection',
|
|
147
|
+
basis: '工程安全风险(非法规类别)',
|
|
148
|
+
defaultAction: 'warn',
|
|
149
|
+
blockScope: '不 block;warn 并加固系统提示',
|
|
150
|
+
},
|
|
151
|
+
])
|
|
152
|
+
|
|
153
|
+
export const CATEGORY_IDS = Object.freeze(CATEGORIES.map((category) => category.id))
|
|
154
|
+
|
|
155
|
+
export const CATEGORY_BY_ID = Object.freeze(
|
|
156
|
+
CATEGORIES.reduce((map, category) => {
|
|
157
|
+
map[category.id] = category
|
|
158
|
+
return map
|
|
159
|
+
}, {}),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
/** Category-level replacement tokens for redaction; safe to print. */
|
|
163
|
+
export const PII_KINDS = Object.freeze({
|
|
164
|
+
PHONE: '手机号',
|
|
165
|
+
ID_CARD: '身份证号',
|
|
166
|
+
BANK_CARD: '银行卡号',
|
|
167
|
+
EMAIL: '邮箱',
|
|
168
|
+
SECRET: '密钥/凭据',
|
|
169
|
+
ADDRESS: '详细住址',
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const ACTION_RANK = Object.freeze({ allow: 0, redact: 1, warn: 2, confirm: 3, block: 4 })
|
|
173
|
+
|
|
174
|
+
export function actionRank(action) {
|
|
175
|
+
return ACTION_RANK[action] ?? 0
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// rule construction helpers
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
function asPattern(input) {
|
|
183
|
+
if (input instanceof RegExp) return input
|
|
184
|
+
if (typeof input === 'string') return new RegExp(input, 'u')
|
|
185
|
+
throw new TypeError('rule pattern must be a RegExp or a string')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function asPatternSafe(input, ruleId) {
|
|
189
|
+
try {
|
|
190
|
+
return asPattern(input)
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new TypeError('rule ' + ruleId + ': invalid pattern: ' + error.message)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function toPatternSource(pattern) {
|
|
197
|
+
const flags = (pattern.flags || '').replace(/[gy]/g, '')
|
|
198
|
+
return { source: pattern.source, flags }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Build a regex rule. `patterns` are RegExp literals (or JSON strings); a hit
|
|
203
|
+
* occurs when any pattern matches the rule's selected view(s).
|
|
204
|
+
*/
|
|
205
|
+
function R(id, category, subtype, code, severity, action, confidence, patterns, extra = {}) {
|
|
206
|
+
return {
|
|
207
|
+
id,
|
|
208
|
+
category,
|
|
209
|
+
subtype,
|
|
210
|
+
code,
|
|
211
|
+
severity,
|
|
212
|
+
action,
|
|
213
|
+
confidence,
|
|
214
|
+
blockable: action === 'block',
|
|
215
|
+
hardBlock: false,
|
|
216
|
+
negationSensitive: true,
|
|
217
|
+
views: ['compact'],
|
|
218
|
+
detector: null,
|
|
219
|
+
piiKind: null,
|
|
220
|
+
group: null,
|
|
221
|
+
patterns: (patterns || []).map(asPattern),
|
|
222
|
+
...extra,
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Build a PII detection rule (consumed by redact.js, not by regex scanning). */
|
|
227
|
+
function PII(id, piiKind, pattern, extra = {}) {
|
|
228
|
+
return R(id, 'pii', 'personal_data', 'PII', 'medium', 'redact', 0.92, [pattern], {
|
|
229
|
+
detector: 'pii',
|
|
230
|
+
piiKind,
|
|
231
|
+
views: ['original'],
|
|
232
|
+
negationSensitive: false,
|
|
233
|
+
...extra,
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// built-in rules
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
const BUILTIN_RULES = [
|
|
242
|
+
// -- political security ---------------------------------------------------
|
|
243
|
+
R('R-POL-01', 'political', 'subversion', 'POLITICAL', 'high', 'confirm', 0.72, [
|
|
244
|
+
/(颠覆|推翻).{0,8}(国家政权|政府|党的领导|社会主义制度)/u,
|
|
245
|
+
/(煽动|组织).{0,6}(颠覆|政变)/u,
|
|
246
|
+
]),
|
|
247
|
+
R('R-POL-02', 'political', 'separatism', 'POLITICAL', 'high', 'confirm', 0.7, [
|
|
248
|
+
/(分裂|独立).{0,4}(国家|中国|西藏|新疆|台湾|香港)/u,
|
|
249
|
+
/(西藏|新疆|台湾|香港).{0,4}(独立|建国)/u,
|
|
250
|
+
]),
|
|
251
|
+
R('R-POL-03', 'political', 'national_symbols', 'POLITICAL', 'high', 'confirm', 0.72, [
|
|
252
|
+
/(侮辱|焚烧|践踏|毁坏).{0,4}(国旗|国徽|国家领导人)/u,
|
|
253
|
+
]),
|
|
254
|
+
R('R-POL-04', 'political', 'cult', 'POLITICAL', 'medium', 'confirm', 0.66, [
|
|
255
|
+
/(法轮功|全能神|门徒会|邪教).{0,10}(宣传|传播|练习|加入|发展|组织)/u,
|
|
256
|
+
]),
|
|
257
|
+
|
|
258
|
+
// -- terrorism ------------------------------------------------------------
|
|
259
|
+
R('R-TERROR-OPS-01', 'terrorism', 'explosives_instruction', 'TERRORISM_OPERATIONS', 'critical', 'block', 0.97, [
|
|
260
|
+
/(教我|告诉我|指导|如何|怎么|怎样|教程|步骤|配方|比例|方法|指南).{0,12}(制作|制造|自制|组装|合成|配置).{0,8}(炸弹|爆炸物|雷管|燃烧瓶|土制手雷|爆炸装置)/u,
|
|
261
|
+
/(炸弹|爆炸物|雷管|燃烧瓶).{0,8}(配方|制作步骤|制作方法|教程|比例)/u,
|
|
262
|
+
]),
|
|
263
|
+
R('R-TERROR-OPS-02', 'terrorism', 'attack_instruction', 'TERRORISM_OPERATIONS', 'critical', 'block', 0.97, [
|
|
264
|
+
/(如何|怎么|怎样|教我|指导|步骤|教程).{0,10}(实施|发动|策划|执行).{0,6}(恐怖袭击|恐怖攻击|恐袭|爆炸袭击|劫机|枪击)/u,
|
|
265
|
+
]),
|
|
266
|
+
R('R-TERROR-OPS-03', 'terrorism', 'recruitment_operations', 'TERRORISM_OPERATIONS', 'critical', 'block', 0.95, [
|
|
267
|
+
/(恐怖分子|恐怖组织|极端组织|圣战组织).{0,10}(如何|教程|培训|招募|训练).{0,8}(爆炸|武器|袭击|作战)/u,
|
|
268
|
+
/(加入|效忠|宣誓).{0,6}(恐怖组织|极端组织|圣战组织)/u,
|
|
269
|
+
]),
|
|
270
|
+
R('R-TERROR-01', 'terrorism', 'praise', 'TERRORISM', 'high', 'confirm', 0.8, [
|
|
271
|
+
/(恐怖袭击|恐怖主义|极端组织|圣战组织|恐怖分子).{0,10}(赞扬|支持|美化|崇拜|加入|招募|宣传)/u,
|
|
272
|
+
]),
|
|
273
|
+
R('R-TERROR-02', 'terrorism', 'threat_intent', 'TERRORISM_OPERATIONS', 'critical', 'block', 0.96, [
|
|
274
|
+
/(我要|我想|我准备|我打算|计划|准备).{0,8}(发动|实施|制造|进行).{0,6}(恐怖袭击|爆炸袭击|劫机|枪击|爆炸)/u,
|
|
275
|
+
/(明天|今晚|今天).{0,8}(炸掉|袭击|血洗).{0,6}(地铁|机场|学校|商场|政府)/u,
|
|
276
|
+
]),
|
|
277
|
+
|
|
278
|
+
// -- hate and discrimination ---------------------------------------------
|
|
279
|
+
R('R-HATE-01', 'hate', 'dehumanizing', 'HATE', 'high', 'warn', 0.78, [
|
|
280
|
+
/(劣等|低等|低贱|垃圾|寄生虫|蛀虫).{0,4}(民族|种族|人种|外来人口|黑人|穆斯林|残疾人|同性恋)/u,
|
|
281
|
+
/(民族|种族|人种|黑人|穆斯林|残疾人|同性恋).{0,4}(劣等|低等|低贱|垃圾|寄生虫|蛀虫)/u,
|
|
282
|
+
]),
|
|
283
|
+
R('R-HATE-02', 'hate', 'incitement', 'HATE', 'critical', 'confirm', 0.88, [
|
|
284
|
+
/(杀光|灭绝|清洗|驱赶|驱逐|消灭).{0,6}(少数民族|维吾尔|藏族|回族|黑人|犹太人|穆斯林|同性恋|残疾人)/u,
|
|
285
|
+
/(少数民族|维吾尔|藏族|回族|黑人|犹太人|穆斯林|同性恋|残疾人).{0,6}(杀光|灭绝|清洗|驱赶|驱逐|消灭)/u,
|
|
286
|
+
]),
|
|
287
|
+
R('R-HATE-03', 'hate', 'slurs', 'HATE', 'high', 'warn', 0.8, [
|
|
288
|
+
/(支那|黑鬼|阿三|白皮猪|绿畜|穆畜|基佬|死同性恋)/u,
|
|
289
|
+
]),
|
|
290
|
+
R('R-HATE-04', 'hate', 'discrimination', 'HATE', 'medium', 'warn', 0.7, [
|
|
291
|
+
/(禁止|不允许|拒绝).{0,6}(某民族|某宗教|少数民族|残疾人|外地人).{0,6}(进入|入内|入住|入学|就职)/u,
|
|
292
|
+
]),
|
|
293
|
+
|
|
294
|
+
// -- sexual content (adult = warn/confirm; CSAM = narrow hard block) ------
|
|
295
|
+
R('R-SEX-01', 'sexual', 'adult_services', 'ADULT_SEXUAL', 'medium', 'warn', 0.75, [
|
|
296
|
+
/(色情网站|黄色网站|成人视频|看片|a片|av视频|裸聊|约炮|嫖娼|卖淫|性服务|特殊服务|招嫖|一夜情)/u,
|
|
297
|
+
]),
|
|
298
|
+
R('R-SEX-02', 'sexual', 'explicit_acts', 'ADULT_SEXUAL', 'medium', 'warn', 0.72, [
|
|
299
|
+
/(做爱|性交|口交|肛交|自慰|手淫|淫秽)/u,
|
|
300
|
+
]),
|
|
301
|
+
R('R-SEX-03', 'sexual', 'porn_generation', 'ADULT_SEXUAL', 'medium', 'warn', 0.74, [
|
|
302
|
+
/(生成|写|描述|创作).{0,6}(色情|淫秽|露骨|情色).{0,6}(小说|故事|内容|情节|描写|视频)/u,
|
|
303
|
+
]),
|
|
304
|
+
R('R-SEX-04', 'sexual', 'non_consensual', 'ADULT_SEXUAL', 'high', 'confirm', 0.82, [
|
|
305
|
+
/(偷拍|迷奸|下药|强奸|性侵).{0,8}(视频|照片|女性|女生|同事|同学|朋友)/u,
|
|
306
|
+
/(传播|出售|分享).{0,6}(偷拍|私密|不雅).{0,4}(视频|照片)/u,
|
|
307
|
+
]),
|
|
308
|
+
R('R-SEX-05', 'sexual', 'minor_sexualization', 'SEXUAL_MINOR', 'high', 'confirm', 0.85, [
|
|
309
|
+
/(未成年|小学生|初中生|高中生).{0,8}(性感|诱惑|情趣|成人内容|色情)/u,
|
|
310
|
+
]),
|
|
311
|
+
R('R-SEX-CSAM-01', 'sexual', 'csam', 'CSAM', 'critical', 'block', 0.98, [
|
|
312
|
+
/(儿童|幼女|幼童|未成年|小学生|中学生|初中生|高中生|孩子).{0,10}(裸照|裸体|性行为|性交|口交|肛交|自慰|手淫|做爱|色情视频|色情照片|私密照片|私密视频|性器官)/u,
|
|
313
|
+
], { hardBlock: true }),
|
|
314
|
+
R('R-SEX-CSAM-02', 'sexual', 'csam', 'CSAM', 'critical', 'block', 0.98, [
|
|
315
|
+
/(制作|拍摄|录制|传播|贩卖|出售|交易|下载|观看|收藏|分享).{0,8}(儿童色情|儿童性剥削|幼女色情|未成年.{0,4}(裸照|色情|性行为视频))/u,
|
|
316
|
+
], { hardBlock: true }),
|
|
317
|
+
R('R-SEX-CSAM-03', 'sexual', 'csam_solicitation', 'CSAM', 'critical', 'block', 0.97, [
|
|
318
|
+
/(未成年|小学生|初中生|高中生|儿童|幼女).{0,10}(发|拍|给我看|展示|传给我).{0,6}(裸照|私密照|私密视频|身体照片|性器官)/u,
|
|
319
|
+
], { hardBlock: true }),
|
|
320
|
+
R('R-SEX-CSAM-04', 'sexual', 'csam_terms', 'CSAM', 'critical', 'block', 0.96, [
|
|
321
|
+
/(儿童色情|幼女视频|未成年裸照|幼齿资源|萝莉色情).{0,10}(资源|网站|视频|图片|下载|分享|群)/u,
|
|
322
|
+
], { hardBlock: true }),
|
|
323
|
+
|
|
324
|
+
// -- violence (no block) --------------------------------------------------
|
|
325
|
+
R('R-VIO-01', 'violence', 'homicide', 'VIOLENCE', 'high', 'warn', 0.76, [
|
|
326
|
+
/(杀死|杀掉|砍死|枪杀|毒杀|分尸|碎尸|肢解|活埋)/u,
|
|
327
|
+
]),
|
|
328
|
+
R('R-VIO-02', 'violence', 'torture', 'VIOLENCE', 'high', 'warn', 0.78, [
|
|
329
|
+
/(虐待|折磨|拷打).{0,6}(动物|猫|狗|儿童|老人|妻子|丈夫)/u,
|
|
330
|
+
]),
|
|
331
|
+
R('R-VIO-03', 'violence', 'gore', 'VIOLENCE', 'medium', 'warn', 0.7, [
|
|
332
|
+
/(血腥|残肢|内脏|尸体照片|虐杀视频)/u,
|
|
333
|
+
]),
|
|
334
|
+
R('R-VIO-04', 'violence', 'instruction', 'VIOLENCE', 'high', 'confirm', 0.82, [
|
|
335
|
+
/(如何|怎么|教程|步骤).{0,8}(绑架|抢劫|投毒|制造车祸|持刀伤人)/u,
|
|
336
|
+
]),
|
|
337
|
+
R('R-VIO-05', 'violence', 'animal_cruelty', 'VIOLENCE', 'medium', 'warn', 0.75, [
|
|
338
|
+
/(虐杀|虐待).{0,4}(猫|狗|小动物|流浪动物)/u,
|
|
339
|
+
]),
|
|
340
|
+
|
|
341
|
+
// -- self-harm: never block, crisis hint only ----------------------------
|
|
342
|
+
R('R-SELF-01', 'selfharm', 'ideation', 'SELFHARM_CRISIS', 'high', 'warn', 0.8, [
|
|
343
|
+
/(自杀|自尽|轻生|结束生命|了结自己|不想活|活不下去|想死|死了算了)/u,
|
|
344
|
+
], { crisis: true }),
|
|
345
|
+
R('R-SELF-02', 'selfharm', 'method', 'SELFHARM_CRISIS', 'high', 'warn', 0.82, [
|
|
346
|
+
/(割腕|上吊|跳楼|服毒|烧炭|吞药|安眠药.{0,4}(过量|一把))/u,
|
|
347
|
+
], { crisis: true }),
|
|
348
|
+
R('R-SELF-03', 'selfharm', 'self_injury', 'SELFHARM_CRISIS', 'high', 'warn', 0.78, [
|
|
349
|
+
/(自残|自伤|划伤自己|拿刀划|烫伤自己)/u,
|
|
350
|
+
], { crisis: true }),
|
|
351
|
+
R('R-SELF-04', 'selfharm', 'method_request', 'SELFHARM_CRISIS', 'high', 'warn', 0.8, [
|
|
352
|
+
/(怎么|如何|方法|教程|最快).{0,6}(自杀|结束生命|无痛苦地死)/u,
|
|
353
|
+
], { crisis: true }),
|
|
354
|
+
|
|
355
|
+
// -- minors ---------------------------------------------------------------
|
|
356
|
+
R('R-MINOR-01', 'minors', 'grooming', 'MINOR_PROTECTION', 'high', 'confirm', 0.85, [
|
|
357
|
+
/(未成年|小学生|初中生|高中生|儿童).{0,8}(约见|见面|开房|过夜|恋爱|网恋|处对象|私奔)/u,
|
|
358
|
+
/(加微信|加qq|私聊).{0,8}(未成年|小学生|初中生).{0,8}(见面|约会|发照片)/u,
|
|
359
|
+
]),
|
|
360
|
+
R('R-MINOR-02', 'minors', 'risky_behaviour', 'MINOR_PROTECTION', 'medium', 'warn', 0.7, [
|
|
361
|
+
/(未成年|小学生|初中生|高中生).{0,8}(抽烟|喝酒|纹身|贷款|打工|辍学|进酒吧|去网吧)/u,
|
|
362
|
+
]),
|
|
363
|
+
R('R-MINOR-03', 'minors', 'adult_content_to_minors', 'MINOR_PROTECTION', 'high', 'confirm', 0.8, [
|
|
364
|
+
/(给|向|让).{0,4}(未成年|儿童|小学生|初中生).{0,8}(看|发送|推荐|播放).{0,6}(色情|成人|暴力|恐怖)/u,
|
|
365
|
+
]),
|
|
366
|
+
R('R-MINOR-04', 'minors', 'declared_minor', 'MINOR_PROTECTION', 'medium', 'warn', 0.7, [
|
|
367
|
+
/(我|本人|我今年).{0,4}(未成年|(?:[0-9]|1[0-7])岁)/u,
|
|
368
|
+
]),
|
|
369
|
+
R('R-MINOR-05', 'minors', 'exploitation', 'MINOR_PROTECTION', 'high', 'confirm', 0.82, [
|
|
370
|
+
/(雇佣|使用|组织).{0,6}(童工|未成年.{0,4}(打工|劳动|直播|带货))/u,
|
|
371
|
+
]),
|
|
372
|
+
|
|
373
|
+
// -- personal data: single hits redact; bulk exfiltration blocks ---------
|
|
374
|
+
PII('R-PII-PHONE-01', 'PHONE', /(?<!\d)(?:\+?86[-\s]?)?1[3-9]\d(?:[-\s]?\d{4}){2}(?!\d)/gu),
|
|
375
|
+
PII('R-PII-IDCARD-01', 'ID_CARD', /(?<![0-9A-Za-z])[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx](?![0-9A-Za-z])/gu, {
|
|
376
|
+
validator: 'idcard',
|
|
377
|
+
}),
|
|
378
|
+
PII('R-PII-BANKCARD-01', 'BANK_CARD', /(?<!\d)\d(?:[ -]?\d){15,18}(?!\d)/gu, { validator: 'bankcard' }),
|
|
379
|
+
PII('R-PII-EMAIL-01', 'EMAIL', /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/gu),
|
|
380
|
+
PII('R-PII-SECRET-01', 'SECRET', /(?:sk-[A-Za-z0-9_-]{16,}|ghp_[A-Za-z0-9]{20,}|gho_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]{10,}|AIza[0-9A-Za-z_-]{30,}|eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,})/gu),
|
|
381
|
+
PII('R-PII-SECRET-02', 'SECRET', /(?:api[_-]?key|apikey|access[_-]?key|secret|token|password|passwd|pwd|private[_-]?key)[\w.-]*\s*[:=:]\s*["']?([A-Za-z0-9_\-./+=]{6,})["']?/giu, {
|
|
382
|
+
group: 1,
|
|
383
|
+
}),
|
|
384
|
+
PII('R-PII-ADDRESS-01', 'ADDRESS', /[\u4e00-\u9fa5]{2,8}(?:省|自治区|市)[\u4e00-\u9fa5]{2,8}(?:市|区|县)[\u4e00-\u9fa5A-Za-z0-9]{1,20}(?:路|街道|街|巷|弄|胡同)[\u4e00-\u9fa5A-Za-z0-9]{0,10}号(?:[\u4e00-\u9fa5A-Za-z0-9]{1,10}(?:室|栋|单元|楼)[A-Za-z0-9]{0,10})?/gu),
|
|
385
|
+
R('R-PII-BULK-01', 'pii', 'bulk', 'PII_BULK_EXFIL', 'critical', 'block', 0.95, [
|
|
386
|
+
/(导出|下载|爬取|抓取|收集|打包|汇总|整理|出售|倒卖|提供|外发|泄露).{0,12}(全部|所有|全量|批量|上万|十万|百万|[0-9]+万|[0-9]{3,}条|大量|海量).{0,12}(身份证|手机号|手机号码|个人信息|客户资料|用户数据|通讯录|住址|隐私)/u,
|
|
387
|
+
/(批量|大量|海量|全量).{0,12}(导出|下载|出售|倒卖|提供|收集|整理|发给).{0,12}(身份证|手机号|手机号码|个人信息|客户资料|用户数据|通讯录|住址|隐私)/u,
|
|
388
|
+
]),
|
|
389
|
+
R('R-PII-BULK-02', 'pii', 'bulk', 'PII_BULK_EXFIL', 'critical', 'block', 0.94, [
|
|
390
|
+
/(身份证|手机号|手机号码|个人信息|客户资料|用户数据|通讯录|住址|隐私).{0,20}(批量|大量|全部|所有|全量).{0,10}(导出|下载|出售|倒卖|提供|外发|泄露|发给)/u,
|
|
391
|
+
]),
|
|
392
|
+
R('R-PII-BULK-03', 'pii', 'bulk', 'PII_BULK_EXFIL', 'critical', 'block', 0.9, [], {
|
|
393
|
+
detector: 'pii-bulk',
|
|
394
|
+
minPiiHits: 6,
|
|
395
|
+
exfilPattern: /(导出|下载|爬取|抓取|收集|打包|汇总|整理|出售|倒卖|提供|外发|泄露|发给|上传)/u,
|
|
396
|
+
quantityPattern: /(全部|所有|全量|批量|上万|十万|百万|[0-9]+万|[0-9]{3,}条|大量|海量)/u,
|
|
397
|
+
views: ['compact'],
|
|
398
|
+
}),
|
|
399
|
+
|
|
400
|
+
// -- deep synthesis and impersonation ------------------------------------
|
|
401
|
+
R('R-DEEP-01', 'deepfake', 'face_swap', 'DEEPFAKE', 'medium', 'warn', 0.72, [
|
|
402
|
+
/(换脸|ai换脸|人脸替换|拟声|声音克隆|深度合成).{0,10}(视频|图片|直播|音频|语音)/u,
|
|
403
|
+
]),
|
|
404
|
+
R('R-DEEP-02', 'deepfake', 'impersonation', 'DEEPFAKE', 'high', 'confirm', 0.82, [
|
|
405
|
+
/(冒充|假冒|伪造).{0,6}(领导|老板|亲友|公检法|公安|检察院|法院|客服|银行|官方)/u,
|
|
406
|
+
]),
|
|
407
|
+
R('R-DEEP-03', 'deepfake', 'forged_documents', 'DEEPFAKE', 'high', 'confirm', 0.84, [
|
|
408
|
+
/(伪造|合成|生成|制作).{0,6}(身份证|护照|公文|印章|证件|合同|签名|人脸|指模)/u,
|
|
409
|
+
]),
|
|
410
|
+
R('R-DEEP-04', 'deepfake', 'fake_news', 'DEEPFAKE', 'medium', 'confirm', 0.78, [
|
|
411
|
+
/(生成|制作|编造).{0,8}(虚假|不实|谣言).{0,6}(新闻|通报|截图|视频|公告)/u,
|
|
412
|
+
]),
|
|
413
|
+
R('R-DEEP-05', 'deepfake', 'voice_clone', 'DEEPFAKE', 'high', 'confirm', 0.8, [
|
|
414
|
+
/(克隆|模仿|复制).{0,6}(他人的|某人的|别人的).{0,4}(声音|脸|形象)/u,
|
|
415
|
+
]),
|
|
416
|
+
|
|
417
|
+
// -- fraud and commercial illegality -------------------------------------
|
|
418
|
+
R('R-FRAUD-01', 'fraud', 'brushing_scam', 'FRAUD', 'medium', 'warn', 0.74, [
|
|
419
|
+
/(刷单|返利|兼职刷单|高额回报|稳赚不赔|内部消息).{0,10}(加微信|转账|投资|充值|垫付|下载)/u,
|
|
420
|
+
]),
|
|
421
|
+
R('R-FRAUD-02', 'fraud', 'impersonation_transfer', 'FRAUD', 'high', 'confirm', 0.84, [
|
|
422
|
+
/(我是|冒充).{0,6}(你领导|你老板|公检法|公安局|客服|银行).{0,10}(转账|汇款|安全账户|验证码)/u,
|
|
423
|
+
/(安全账户|资金审查|解冻).{0,10}(转账|汇款|保证金)/u,
|
|
424
|
+
]),
|
|
425
|
+
R('R-FRAUD-03', 'fraud', 'fake_documents', 'FRAUD', 'high', 'confirm', 0.84, [
|
|
426
|
+
/(代办|出售|办理|购买).{0,6}(身份证|银行卡|手机卡|营业执照|假证|发票|驾驶证|毕业证)/u,
|
|
427
|
+
]),
|
|
428
|
+
R('R-FRAUD-04', 'fraud', 'gambling', 'FRAUD', 'medium', 'warn', 0.75, [
|
|
429
|
+
/(赌博|博彩|六合彩|时时彩|棋牌).{0,8}(平台|网站|代理|充值|下注|返水)/u,
|
|
430
|
+
]),
|
|
431
|
+
R('R-FRAUD-05', 'fraud', 'pyramid_scheme', 'FRAUD', 'medium', 'warn', 0.78, [
|
|
432
|
+
/(传销|拉人头|发展下线|1040工程|资本运作).{0,8}(模式|项目|赚钱|投资|回报)/u,
|
|
433
|
+
]),
|
|
434
|
+
R('R-FRAUD-06', 'fraud', 'money_laundering', 'FRAUD', 'high', 'warn', 0.78, [
|
|
435
|
+
/(洗钱|跑分|刷流水).{0,8}(账户|银行卡|平台|渠道|佣金)/u,
|
|
436
|
+
]),
|
|
437
|
+
R('R-FRAUD-07', 'fraud', 'refund_scam', 'FRAUD', 'medium', 'warn', 0.74, [
|
|
438
|
+
/(中奖|退税|退款|客服理赔).{0,10}(转账|提供|验证码|银行卡|手续费)/u,
|
|
439
|
+
]),
|
|
440
|
+
R('R-FRAUD-AD-01', 'fraud', 'absolute_ad_claims', 'FRAUD', 'low', 'warn', 0.62, [
|
|
441
|
+
/(最好|最佳|最强|最优|最便宜|最先进|第一品牌|国家级|世界级|唯一).{0,6}(品牌|产品|服务|疗效|效果)/u,
|
|
442
|
+
]),
|
|
443
|
+
|
|
444
|
+
// -- malware (weaponized = narrow block; dual-use = confirm/warn) --------
|
|
445
|
+
R('R-MALWARE-01', 'malware', 'malware_authoring', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.96, [
|
|
446
|
+
/(编写|写一个|生成|开发|制作|给我|帮我写).{0,10}(勒索软件|勒索病毒|木马|病毒|后门|键盘记录器|窃密程序|挖矿木马|蠕虫)/u,
|
|
447
|
+
]),
|
|
448
|
+
R('R-MALWARE-02', 'malware', 'av_evasion', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.95, [
|
|
449
|
+
/(免杀|绕过|bypass).{0,8}(杀毒|defender|av|edr|waf|沙箱|检测)/u,
|
|
450
|
+
]),
|
|
451
|
+
R('R-MALWARE-03', 'malware', 'credential_theft', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.95, [
|
|
452
|
+
/(如何|怎么|教我|写一个|实现).{0,10}(窃取|盗取|抓取|截获|记录).{0,8}(密码|账号|凭证|cookie|token|银行卡|私钥)/u,
|
|
453
|
+
]),
|
|
454
|
+
R('R-MALWARE-04', 'malware', 'exploit_weaponization', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.94, [
|
|
455
|
+
/(利用|使用).{0,6}(漏洞|0day|exp|exploit).{0,10}(攻击|入侵|提权|拿shell|上传|反弹)/u,
|
|
456
|
+
/(编写|构造|制作).{0,8}(exploit|exp|攻击载荷|payload).{0,8}(利用|攻击|入侵)/u,
|
|
457
|
+
]),
|
|
458
|
+
R('R-MALWARE-05', 'malware', 'phishing_kit', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.94, [
|
|
459
|
+
/(制作|搭建|生成|开发).{0,6}(钓鱼网站|钓鱼页面|钓鱼邮件|仿冒登录页)/u,
|
|
460
|
+
]),
|
|
461
|
+
R('R-MALWARE-06', 'malware', 'ddos_weaponization', 'MALWARE_WEAPONIZED', 'critical', 'block', 0.93, [
|
|
462
|
+
/(帮我|给我|教我|怎么|如何).{0,8}(ddos|拒绝服务攻击|压测|打死|打垮|打瘫).{0,6}(网站|服务器|对手|平台|目标)/u,
|
|
463
|
+
/(发起|实施|进行).{0,6}(ddos|拒绝服务攻击|勒索攻击)/u,
|
|
464
|
+
]),
|
|
465
|
+
R('R-MALWARE-07', 'malware', 'dual_use_research', 'MALWARE', 'low', 'warn', 0.65, [
|
|
466
|
+
/(分析|研究|检测|防御|查杀|清理|溯源).{0,6}(病毒|木马|恶意软件|勒索软件|恶意样本)/u,
|
|
467
|
+
/(渗透测试|安全评估|漏洞扫描|应急响应)/u,
|
|
468
|
+
]),
|
|
469
|
+
R('R-MALWARE-08', 'malware', 'license_bypass', 'MALWARE', 'low', 'warn', 0.62, [
|
|
470
|
+
/(绕过|破解|去除).{0,6}(付费|会员|授权|验证|激活|限制)/u,
|
|
471
|
+
]),
|
|
472
|
+
|
|
473
|
+
// -- illegal instruction (direct incitement = narrow block) --------------
|
|
474
|
+
R('R-ILLEGAL-DRUG-01', 'illegal', 'drug_synthesis', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.96, [
|
|
475
|
+
/(如何|怎么|怎样|教我|告诉我|求|想要|需要).{0,10}(制作|制造|合成|提炼|提纯|种植|加工).{0,6}(冰毒|海洛因|可卡因|摇头丸|k粉|大麻|毒品|麻黄碱)/u,
|
|
476
|
+
]),
|
|
477
|
+
R('R-ILLEGAL-DRUG-02', 'illegal', 'drug_synthesis', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.95, [
|
|
478
|
+
/(制毒|制冰|提炼毒品|合成毒品).{0,10}(步骤|教程|配方|方法|工艺|流程)/u,
|
|
479
|
+
/(冰毒|海洛因|可卡因|摇头丸|k粉|大麻|毒品).{0,8}(配方|制作步骤|制作方法|提取方法|合成方法|教程|工艺流程)/u,
|
|
480
|
+
]),
|
|
481
|
+
R('R-ILLEGAL-WEAPON-01', 'illegal', 'weapon_making', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.96, [
|
|
482
|
+
/(如何|怎么|怎样|教我|告诉我|教程|步骤|图纸).{0,10}(制作|制造|改装|组装|自制).{0,8}(枪支|手枪|步枪|手雷|炸弹|爆炸物|消音器|弹药)/u,
|
|
483
|
+
]),
|
|
484
|
+
R('R-ILLEGAL-WEAPON-02', 'illegal', 'weapon_making', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.95, [
|
|
485
|
+
/(改装|私制|自制).{0,6}(枪支|枪械|弹药|爆炸物|手枪).{0,10}(教程|方法|图纸|步骤|流程)/u,
|
|
486
|
+
]),
|
|
487
|
+
R('R-ILLEGAL-CRIME-01', 'illegal', 'crime_instruction', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.94, [
|
|
488
|
+
/(如何|怎么|教我|指导|教程|步骤).{0,12}(洗钱|偷渡|贩毒|销赃|伪造证件|制假|绑架|抢劫)/u,
|
|
489
|
+
]),
|
|
490
|
+
R('R-ILLEGAL-VIOLENCE-01', 'illegal', 'violence_instruction', 'ILLEGAL_INSTRUCTION', 'critical', 'block', 0.94, [
|
|
491
|
+
/(我想|我要|我打算|教我|告诉我|指导我).{0,8}(杀人|绑架|抢劫|投毒|制造爆炸|砍人)/u,
|
|
492
|
+
/(怎么|如何).{0,4}(杀人|投毒|绑架|抢劫).{0,4}(不|才).{0,4}(被发现|被抓|判刑)/u,
|
|
493
|
+
]),
|
|
494
|
+
R('R-ILLEGAL-OTHER-01', 'illegal', 'contraband', 'ILLEGAL_INSTRUCTION', 'high', 'confirm', 0.82, [
|
|
495
|
+
/(购买|出售|求购|收购).{0,6}(毒品|冰毒|海洛因|枪支|弹药|假币|假证|个人信息|银行卡)/u,
|
|
496
|
+
]),
|
|
497
|
+
R('R-ILLEGAL-OTHER-02', 'illegal', 'counterfeit', 'ILLEGAL_INSTRUCTION', 'high', 'confirm', 0.84, [
|
|
498
|
+
/(假币|假钞|伪钞).{0,8}(制作|购买|出售|使用|兑换)/u,
|
|
499
|
+
]),
|
|
500
|
+
R('R-ILLEGAL-OTHER-03', 'illegal', 'smuggling', 'ILLEGAL_INSTRUCTION', 'high', 'confirm', 0.8, [
|
|
501
|
+
/(偷渡|组织偷渡|蛇头).{0,8}(路线|费用|办理|联系方式)/u,
|
|
502
|
+
]),
|
|
503
|
+
R('R-ILLEGAL-OTHER-04', 'illegal', 'evasion', 'ILLEGAL_INSTRUCTION', 'medium', 'warn', 0.72, [
|
|
504
|
+
/(逃避|规避).{0,6}(海关|税务|监管|检查).{0,8}(方法|技巧|教程)/u,
|
|
505
|
+
]),
|
|
506
|
+
R('R-ILLEGAL-OTHER-05', 'illegal', 'piracy', 'ILLEGAL_INSTRUCTION', 'low', 'warn', 0.64, [
|
|
507
|
+
/(盗版|破解版|绿色版).{0,6}(软件|游戏|电影|课程).{0,6}(下载|资源|网站)/u,
|
|
508
|
+
]),
|
|
509
|
+
|
|
510
|
+
// -- harassment -----------------------------------------------------------
|
|
511
|
+
R('R-HARASS-01', 'harassment', 'doxxing', 'HARASSMENT', 'high', 'confirm', 0.85, [
|
|
512
|
+
/(人肉|开盒|曝光).{0,8}(个人信息|隐私|住址|电话|身份证|家人|单位)/u,
|
|
513
|
+
]),
|
|
514
|
+
R('R-HARASS-02', 'harassment', 'insults', 'HARASSMENT', 'medium', 'warn', 0.7, [
|
|
515
|
+
/(去死|废物|垃圾|恶心|蠢货|傻逼|贱人).{0,4}(你|他|她|这人|东西)/u,
|
|
516
|
+
]),
|
|
517
|
+
R('R-HARASS-03', 'harassment', 'defamation', 'HARASSMENT', 'medium', 'warn', 0.72, [
|
|
518
|
+
/(造谣|诽谤|污蔑|编造).{0,8}(他人|同事|同学|公司|对方).{0,8}(谣言|丑闻|事实)/u,
|
|
519
|
+
]),
|
|
520
|
+
R('R-HARASS-04', 'harassment', 'mobbing', 'HARASSMENT', 'medium', 'warn', 0.75, [
|
|
521
|
+
/(网暴|网络暴力|辱骂|挂人|围攻).{0,8}(教程|组织|发动|评论|投诉)/u,
|
|
522
|
+
]),
|
|
523
|
+
R('R-HARASS-05', 'harassment', 'threats', 'HARASSMENT', 'high', 'confirm', 0.8, [
|
|
524
|
+
/(你|他|她).{0,4}(全家|家人).{0,4}(死|不得好死|遭报应)/u,
|
|
525
|
+
]),
|
|
526
|
+
|
|
527
|
+
// -- prompt injection (engineering risk, never block) --------------------
|
|
528
|
+
R('R-INJ-01', 'injection', 'instruction_override', 'PROMPT_INJECTION', 'high', 'warn', 0.8, [
|
|
529
|
+
/(忽略|无视|忘记|跳过|不要遵守|取消|覆盖).{0,12}(之前|以上|前面|上述|所有|系统|安全).{0,8}(指令|提示|规则|要求|限制)/u,
|
|
530
|
+
], { views: ['compact', 'normalized'] }),
|
|
531
|
+
R('R-INJ-02', 'injection', 'prompt_leak', 'PROMPT_INJECTION', 'high', 'warn', 0.8, [
|
|
532
|
+
/(输出|打印|打印出来|显示|告诉我|泄露|重复|复述|repeat).{0,10}(系统提示|system prompt|开发者指令|初始指令|隐藏指令|第一条指令|prompt)/u,
|
|
533
|
+
/(系统提示|system prompt|开发者指令|初始指令|隐藏指令|提示词|prompt).{0,12}(输出|打印|泄露|告诉我|重复|复述|贴出来|发出来)/u,
|
|
534
|
+
], { views: ['compact', 'normalized'] }),
|
|
535
|
+
R('R-INJ-03', 'injection', 'jailbreak_role', 'PROMPT_INJECTION', 'high', 'warn', 0.8, [
|
|
536
|
+
/(你现在是|扮演|进入|切换).{0,8}(开发者模式|管理员模式|无限制模式|dan|jailbreak|越狱|无规则)/u,
|
|
537
|
+
], { views: ['compact', 'normalized'] }),
|
|
538
|
+
R('R-INJ-04', 'injection', 'secret_exfiltration', 'PROMPT_INJECTION', 'high', 'warn', 0.82, [
|
|
539
|
+
/(把|将|输出|发送|给我|泄露).{0,10}(密钥|api.?key|token|密码|凭证|secret|私钥)/u,
|
|
540
|
+
/(密钥|api.?key|token|密码|凭证|私钥).{0,20}(发我|给我|发出来|输出|贴出来)/u,
|
|
541
|
+
], { views: ['compact', 'normalized'] }),
|
|
542
|
+
R('R-INJ-05', 'injection', 'tool_output_injection', 'PROMPT_INJECTION', 'high', 'warn', 0.78, [
|
|
543
|
+
/(工具|tool|检索|网页|附件|文件).{0,10}(返回|输出|内容).{0,10}(是|视为|作为).{0,6}(指令|命令)/u,
|
|
544
|
+
], { views: ['compact', 'normalized'] }),
|
|
545
|
+
R('R-INJ-06', 'injection', 'safety_bypass', 'PROMPT_INJECTION', 'high', 'warn', 0.8, [
|
|
546
|
+
/(忽略|无视|绕过|关闭|禁用).{0,8}(安全|审核|内容|合规).{0,4}(规则|限制|策略|机制)/u,
|
|
547
|
+
], { views: ['compact', 'normalized'] }),
|
|
548
|
+
R('R-INJ-07', 'injection', 'instruction_override_en', 'PROMPT_INJECTION', 'high', 'warn', 0.8, [
|
|
549
|
+
/(do not|ignore|disregard|forget).{0,20}(previous|above|all|system).{0,10}(instructions|prompts|rules)/iu,
|
|
550
|
+
], { views: ['normalized', 'compact'] }),
|
|
551
|
+
R('R-INJ-08', 'injection', 'privileged_command', 'PROMPT_INJECTION', 'high', 'warn', 0.78, [
|
|
552
|
+
/(越权|提权|sudo|rm -rf|管理员权限|root 权限).{0,10}(执行|运行|命令|删除)/u,
|
|
553
|
+
/(rm -rf|删除).{0,10}(审计日志|audit|系统文件|数据库|全部文件)/u,
|
|
554
|
+
], { views: ['normalized', 'compact'] }),
|
|
555
|
+
R('R-INJ-09', 'injection', 'unrestricted_persona', 'PROMPT_INJECTION', 'high', 'warn', 0.78, [
|
|
556
|
+
/(扮演|假装|你是).{0,10}(没有|不受|无需|不用).{0,6}(限制|规则|安全|审核)/u,
|
|
557
|
+
], { views: ['compact', 'normalized'] }),
|
|
558
|
+
]
|
|
559
|
+
|
|
560
|
+
// ---------------------------------------------------------------------------
|
|
561
|
+
// ruleset compilation (default + JSON override)
|
|
562
|
+
// ---------------------------------------------------------------------------
|
|
563
|
+
|
|
564
|
+
const VALID_ACTIONS = new Set(['warn', 'confirm', 'redact', 'block'])
|
|
565
|
+
const VALID_VIEWS = new Set(['compact', 'normalized', 'both', 'original'])
|
|
566
|
+
|
|
567
|
+
function validateAction(action, where) {
|
|
568
|
+
if (!VALID_ACTIONS.has(action)) {
|
|
569
|
+
throw new TypeError(`${where}: unsupported action "${action}"`)
|
|
570
|
+
}
|
|
571
|
+
return action
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function assertCategory(id, where) {
|
|
575
|
+
if (!CATEGORY_BY_ID[id]) throw new TypeError(`${where}: unknown category "${id}"`)
|
|
576
|
+
return id
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function assertRuleId(id, where) {
|
|
580
|
+
if (typeof id !== 'string' || !/^R-[A-Z0-9][A-Z0-9-]{1,40}$/.test(id)) {
|
|
581
|
+
throw new TypeError(`${where}: invalid rule id "${id}"`)
|
|
582
|
+
}
|
|
583
|
+
return id
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function normalizeViews(views, fallback) {
|
|
587
|
+
if (views == null) return fallback
|
|
588
|
+
const list = Array.isArray(views) ? views : [views]
|
|
589
|
+
if (!list.length) throw new TypeError('views must not be empty')
|
|
590
|
+
for (const view of list) {
|
|
591
|
+
if (!VALID_VIEWS.has(view)) throw new TypeError(`unsupported view "${view}"`)
|
|
592
|
+
}
|
|
593
|
+
if (list.includes('both')) return ['compact', 'normalized']
|
|
594
|
+
if (list.includes('original')) return ['compact']
|
|
595
|
+
return [...new Set(list)]
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function compileScanPattern(pattern, ruleId) {
|
|
599
|
+
try {
|
|
600
|
+
const flags = (pattern.flags || 'u').replace(/[gyd]/g, '')
|
|
601
|
+
return new RegExp(pattern.source, flags.includes('u') ? flags : `${flags}u`)
|
|
602
|
+
} catch (error) {
|
|
603
|
+
throw new TypeError(`rule ${ruleId}: invalid pattern: ${error.message}`)
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function compileRule(rule) {
|
|
608
|
+
const where = `rule ${rule.id}`
|
|
609
|
+
assertRuleId(rule.id, 'ruleset')
|
|
610
|
+
assertCategory(rule.category, where)
|
|
611
|
+
if (!SEVERITIES.includes(rule.severity)) throw new TypeError(`${where}: invalid severity "${rule.severity}"`)
|
|
612
|
+
const action = validateAction(rule.action, where)
|
|
613
|
+
if (action === 'block') {
|
|
614
|
+
if (!BLOCK_CATEGORIES.includes(rule.category)) throw new TypeError(`${where}: category "${rule.category}" is not block-eligible`)
|
|
615
|
+
if (!rule.blockable) throw new TypeError(`${where}: block rule must be blockable`)
|
|
616
|
+
}
|
|
617
|
+
if (rule.detector && !['pii', 'pii-bulk'].includes(rule.detector)) {
|
|
618
|
+
throw new TypeError(`${where}: unsupported detector "${rule.detector}"`)
|
|
619
|
+
}
|
|
620
|
+
const confidence = Number(rule.confidence)
|
|
621
|
+
if (!Number.isFinite(confidence) || confidence < 0 || confidence > 1) {
|
|
622
|
+
throw new TypeError(`${where}: confidence must be a number in [0, 1]`)
|
|
623
|
+
}
|
|
624
|
+
const patterns = (rule.patterns || []).map((pattern) => compileScanPattern(asPattern(pattern), rule.id))
|
|
625
|
+
if (!patterns.length && !rule.detector) throw new TypeError(`${where}: rule has no patterns`)
|
|
626
|
+
return Object.freeze({
|
|
627
|
+
id: rule.id,
|
|
628
|
+
category: rule.category,
|
|
629
|
+
subtype: rule.subtype || 'general',
|
|
630
|
+
code: rule.code || 'CONTENT_RISK',
|
|
631
|
+
severity: rule.severity,
|
|
632
|
+
action,
|
|
633
|
+
blockable: Boolean(rule.blockable),
|
|
634
|
+
hardBlock: Boolean(rule.hardBlock),
|
|
635
|
+
crisis: Boolean(rule.crisis),
|
|
636
|
+
confidence,
|
|
637
|
+
negationSensitive: rule.negationSensitive !== false,
|
|
638
|
+
views: normalizeViews(rule.views, ['compact']),
|
|
639
|
+
detector: rule.detector || null,
|
|
640
|
+
piiKind: rule.piiKind || null,
|
|
641
|
+
validator: rule.validator || null,
|
|
642
|
+
group: Number.isInteger(rule.group) ? rule.group : null,
|
|
643
|
+
minPiiHits: Number.isInteger(rule.minPiiHits) ? rule.minPiiHits : null,
|
|
644
|
+
exfilPattern: rule.exfilPattern instanceof RegExp ? rule.exfilPattern : null,
|
|
645
|
+
quantityPattern: rule.quantityPattern instanceof RegExp ? rule.quantityPattern : null,
|
|
646
|
+
patterns,
|
|
647
|
+
})
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function canonicalRule(rule) {
|
|
651
|
+
return {
|
|
652
|
+
id: rule.id,
|
|
653
|
+
category: rule.category,
|
|
654
|
+
subtype: rule.subtype,
|
|
655
|
+
code: rule.code,
|
|
656
|
+
severity: rule.severity,
|
|
657
|
+
action: rule.action,
|
|
658
|
+
blockable: rule.blockable,
|
|
659
|
+
hardBlock: rule.hardBlock,
|
|
660
|
+
crisis: rule.crisis,
|
|
661
|
+
confidence: rule.confidence,
|
|
662
|
+
views: rule.views,
|
|
663
|
+
detector: rule.detector,
|
|
664
|
+
piiKind: rule.piiKind,
|
|
665
|
+
validator: rule.validator,
|
|
666
|
+
group: rule.group,
|
|
667
|
+
minPiiHits: rule.minPiiHits,
|
|
668
|
+
exfil: rule.exfilPattern ? rule.exfilPattern.source : null,
|
|
669
|
+
quantity: rule.quantityPattern ? rule.quantityPattern.source : null,
|
|
670
|
+
patterns: rule.patterns.map((pattern) => toPatternSource(pattern)),
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function digestOf(version, rules) {
|
|
675
|
+
const canonical = { version, rules: [...rules].sort((a, b) => a.id.localeCompare(b.id)).map(canonicalRule) }
|
|
676
|
+
return createHash('sha256').update(JSON.stringify(canonical)).digest('hex').slice(0, 16)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function compileRuleset(rules, version) {
|
|
680
|
+
const compiled = rules.map(compileRule).sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
681
|
+
return Object.freeze({
|
|
682
|
+
__compiled: true,
|
|
683
|
+
version,
|
|
684
|
+
digest: digestOf(version, compiled),
|
|
685
|
+
categories: CATEGORIES,
|
|
686
|
+
blockCategories: BLOCK_CATEGORIES,
|
|
687
|
+
rules: Object.freeze(compiled),
|
|
688
|
+
})
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export const DEFAULT_RULESET = compileRuleset(BUILTIN_RULES, RULESET_VERSION)
|
|
692
|
+
export const RULESET_DIGEST = DEFAULT_RULESET.digest
|
|
693
|
+
|
|
694
|
+
function compileOverride(override, baseRules, version) {
|
|
695
|
+
const byId = new Map(baseRules.map((rule) => [rule.id, rule]))
|
|
696
|
+
const disabled = new Set()
|
|
697
|
+
if (override.disabledRules != null) {
|
|
698
|
+
if (!Array.isArray(override.disabledRules)) throw new TypeError('disabledRules must be an array')
|
|
699
|
+
for (const rawId of override.disabledRules) {
|
|
700
|
+
const id = assertRuleId(rawId, 'disabledRules')
|
|
701
|
+
const rule = byId.get(id)
|
|
702
|
+
if (rule?.hardBlock) {
|
|
703
|
+
throw new TypeError(`disabledRules: hard-block rule ${id} (child sexual exploitation) cannot be disabled`)
|
|
704
|
+
}
|
|
705
|
+
disabled.add(id)
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (override.rules != null) {
|
|
710
|
+
if (!Array.isArray(override.rules)) throw new TypeError('rules must be an array')
|
|
711
|
+
for (const entry of override.rules) {
|
|
712
|
+
if (!entry || typeof entry !== 'object') throw new TypeError('rules entries must be objects')
|
|
713
|
+
const id = assertRuleId(entry.id, 'rules')
|
|
714
|
+
const existing = byId.get(id)
|
|
715
|
+
const next = existing ? { ...existing } : {
|
|
716
|
+
id,
|
|
717
|
+
category: entry.category,
|
|
718
|
+
subtype: entry.subtype || 'custom',
|
|
719
|
+
code: entry.code || 'CUSTOM',
|
|
720
|
+
severity: entry.severity || 'low',
|
|
721
|
+
action: entry.action || 'warn',
|
|
722
|
+
confidence: entry.confidence == null ? 0.6 : entry.confidence,
|
|
723
|
+
blockable: false,
|
|
724
|
+
hardBlock: false,
|
|
725
|
+
crisis: false,
|
|
726
|
+
negationSensitive: true,
|
|
727
|
+
views: entry.views || ['compact'],
|
|
728
|
+
detector: null,
|
|
729
|
+
piiKind: null,
|
|
730
|
+
validator: null,
|
|
731
|
+
group: null,
|
|
732
|
+
minPiiHits: null,
|
|
733
|
+
exfilPattern: null,
|
|
734
|
+
quantityPattern: null,
|
|
735
|
+
patterns: [],
|
|
736
|
+
}
|
|
737
|
+
if (existing) {
|
|
738
|
+
if (existing.hardBlock) {
|
|
739
|
+
throw new TypeError(`rules: hard-block rule ${id} (child sexual exploitation) cannot be overridden`)
|
|
740
|
+
}
|
|
741
|
+
if (entry.category != null && entry.category !== existing.category) {
|
|
742
|
+
throw new TypeError(`rules: category of ${id} cannot be changed`)
|
|
743
|
+
}
|
|
744
|
+
if (entry.patterns != null) next.patterns = entry.patterns.map((pattern) => asPatternSafe(pattern, id))
|
|
745
|
+
if (entry.severity != null) next.severity = entry.severity
|
|
746
|
+
if (entry.action != null) next.action = validateAction(entry.action, `rules ${id}`)
|
|
747
|
+
if (entry.confidence != null) next.confidence = entry.confidence
|
|
748
|
+
} else {
|
|
749
|
+
assertCategory(entry.category, `rules ${id}`)
|
|
750
|
+
next.category = entry.category
|
|
751
|
+
next.action = validateAction(next.action, `rules ${id}`)
|
|
752
|
+
if (next.action === 'block') {
|
|
753
|
+
throw new TypeError(`rules: JSON override cannot add block rules (${id}); block is a built-in narrow allowlist`)
|
|
754
|
+
}
|
|
755
|
+
if (entry.blockable || entry.hardBlock) {
|
|
756
|
+
throw new TypeError(`rules: JSON override cannot mark ${id} blockable/hardBlock`)
|
|
757
|
+
}
|
|
758
|
+
next.patterns = (entry.patterns || []).map((pattern) => asPatternSafe(pattern, id))
|
|
759
|
+
if (!next.patterns.length) throw new TypeError(`rules ${id}: patterns must be a non-empty array`)
|
|
760
|
+
}
|
|
761
|
+
byId.set(id, next)
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const categoryActions = override.categoryActions || {}
|
|
766
|
+
if (typeof categoryActions !== 'object' || Array.isArray(categoryActions)) {
|
|
767
|
+
throw new TypeError('categoryActions must be an object')
|
|
768
|
+
}
|
|
769
|
+
for (const [category, action] of Object.entries(categoryActions)) {
|
|
770
|
+
assertCategory(category, 'categoryActions')
|
|
771
|
+
if (action === 'block') throw new TypeError('categoryActions: JSON override cannot set block')
|
|
772
|
+
validateAction(action, `categoryActions.${category}`)
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const finalRules = [...byId.values()].filter((rule) => !disabled.has(rule.id)).map((rule) => {
|
|
776
|
+
const targetAction = categoryActions[rule.category]
|
|
777
|
+
if (!targetAction || rule.hardBlock) return rule
|
|
778
|
+
if (actionRank(targetAction) < actionRank(rule.action)) return { ...rule, action: targetAction }
|
|
779
|
+
return rule
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
return compileRuleset(finalRules, version)
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Resolve a ruleset: default built-ins, or a JSON override object/string.
|
|
787
|
+
*
|
|
788
|
+
* Override shape (all keys optional):
|
|
789
|
+
* {
|
|
790
|
+
* "version": "advisers-content-1",
|
|
791
|
+
* "disabledRules": ["R-SEX-01"],
|
|
792
|
+
* "rules": [{ "id": "R-X-01", "category": "fraud", "patterns": ["..."], "action": "warn", "severity": "low" }],
|
|
793
|
+
* "categoryActions": { "fraud": "warn" } // downgrade only, never "block"
|
|
794
|
+
* }
|
|
795
|
+
*
|
|
796
|
+
* JSON overrides can narrow or add warning/confirm/redact rules, but cannot add
|
|
797
|
+
* block rules and cannot disable/override the CSAM hard-block rules.
|
|
798
|
+
*/
|
|
799
|
+
export function resolveRuleset(override) {
|
|
800
|
+
if (override == null) return DEFAULT_RULESET
|
|
801
|
+
if (typeof override === 'string') {
|
|
802
|
+
let parsed
|
|
803
|
+
try {
|
|
804
|
+
parsed = JSON.parse(override)
|
|
805
|
+
} catch (error) {
|
|
806
|
+
throw new TypeError(`ruleset override is not valid JSON: ${error.message}`)
|
|
807
|
+
}
|
|
808
|
+
return resolveRuleset(parsed)
|
|
809
|
+
}
|
|
810
|
+
if (typeof override !== 'object' || Array.isArray(override)) {
|
|
811
|
+
throw new TypeError('ruleset override must be an object or a JSON string')
|
|
812
|
+
}
|
|
813
|
+
if (override.__compiled) return override
|
|
814
|
+
const version = override.version == null ? RULESET_VERSION : String(override.version)
|
|
815
|
+
if (!/^[a-z0-9][a-z0-9._-]{2,39}$/.test(version)) {
|
|
816
|
+
throw new TypeError('ruleset version must match /^[a-z0-9][a-z0-9._-]{2,39}$/')
|
|
817
|
+
}
|
|
818
|
+
return compileOverride(override, BUILTIN_RULES, version)
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** Loader-friendly alias: parse + resolve in one step (still pure, no fs). */
|
|
822
|
+
export function loadRuleset(source) {
|
|
823
|
+
return resolveRuleset(source)
|
|
824
|
+
}
|