argo-search 2.9.8 → 2.10.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/README.en.md +48 -35
- package/README.es.md +48 -35
- package/README.ja.md +47 -34
- package/README.ko.md +47 -34
- package/README.md +50 -35
- package/SKILL.md +5 -5
- package/backends/domain_profiles.json +76 -0
- package/backends/engine_registry.yaml +161 -5
- package/backends/quota_profiles.json +122 -2
- package/bin/argo +26 -1
- package/bin/argo.js +3 -3
- package/config.yaml +180 -26
- package/docs/ARGO_INTRO.md +7 -5
- package/docs/ENGINE_CATALOG.md +64 -44
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
- package/docs/RELEASE_NOTES_v2.9.9.md +78 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
- package/engines/specs/clawhub.yaml +16 -15
- package/engines/specs/deepseek1024.yaml +46 -0
- package/engines/specs/dsh_hub.yaml +44 -0
- package/engines/specs/dshopen.yaml +32 -0
- package/engines/specs/explainx.yaml +32 -0
- package/engines/specs/gbfs_nyc.yaml +6 -1
- package/engines/specs/metaso_doc.yaml +49 -0
- package/engines/specs/metaso_image.yaml +65 -0
- package/engines/specs/metaso_podcast.yaml +60 -0
- package/engines/specs/metaso_scholar.yaml +57 -0
- package/engines/specs/metaso_video.yaml +62 -0
- package/engines/specs/ncpssd.yaml +41 -0
- package/engines/specs/sciverse.yaml +72 -0
- package/engines/specs/skills_sh.yaml +32 -0
- package/engines/specs/skillsmp.yaml +18 -16
- package/package.json +4 -2
- package/packages/dsh-plugin/README.md +4 -2
- package/packages/dsh-plugin/dsh/client.js +98 -32
- package/packages/dsh-plugin/dsh/diagnostics.js +43 -0
- package/packages/dsh-plugin/dsh/index.js +23 -1
- package/packages/dsh-plugin/package.json +2 -2
- package/packages/dsh-plugin/test/client.test.js +2 -1
- package/packages/dsh-plugin/test/size-gate.test.js +113 -0
- package/scripts/adaptive.py +135 -48
- package/scripts/article.py +6 -1
- package/scripts/article_meta.py +151 -2
- package/scripts/bench_general_pool.py +145 -0
- package/scripts/bench_tail_ab.py +281 -0
- package/scripts/bounded_run.py +91 -49
- package/scripts/candidate_envelope.py +45 -4
- package/scripts/charset_decode.py +127 -0
- package/scripts/clock_bridge.py +22 -0
- package/scripts/content_security.py +119 -4
- package/scripts/crawl.py +240 -74
- package/scripts/crawl_frontier.py +217 -0
- package/scripts/crawl_policy.py +174 -0
- package/scripts/dispatch_result.py +9 -2
- package/scripts/engine_add.py +602 -0
- package/scripts/engine_dispatch.py +31 -15
- package/scripts/engine_failure.py +15 -0
- package/scripts/engine_validate.py +8 -0
- package/scripts/engines.py +10 -0
- package/scripts/engines_base.py +12 -0
- package/scripts/engines_builders.py +14 -0
- package/scripts/engines_builders_dsh.py +330 -0
- package/scripts/engines_builders_skill.py +314 -0
- package/scripts/evidence_loop.py +4 -0
- package/scripts/fetch_quality.py +13 -0
- package/scripts/fetch_v3.py +39 -7
- package/scripts/gen_engine_catalog.py +218 -2
- package/scripts/general_pool.py +162 -0
- package/scripts/http_client.py +62 -80
- package/scripts/image_ops.py +4 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.ps1 +47 -19
- package/scripts/install.sh +45 -20
- package/scripts/matrix_search_eval.py +128 -2
- package/scripts/mcp_transport.py +1 -1
- package/scripts/ncpssd_bridge.py +123 -0
- package/scripts/net_proxy.py +27 -0
- package/scripts/paid_policy.py +109 -13
- package/scripts/pre-commit +19 -4
- package/scripts/query_signals.py +156 -3
- package/scripts/recovery.py +7 -3
- package/scripts/redskill/redskill_engine.py +29 -2
- package/scripts/release_check.py +209 -0
- package/scripts/retry_policy.py +22 -1
- package/scripts/robots_guard.py +26 -0
- package/scripts/route.py +11 -8
- package/scripts/route_cache.py +6 -0
- package/scripts/route_combo.py +56 -64
- package/scripts/route_domains.py +142 -13
- package/scripts/route_policy.py +6 -0
- package/scripts/safe_conn.py +52 -0
- package/scripts/search.py +9 -1
- package/scripts/search_cli.py +27 -0
- package/scripts/search_entry.py +10 -0
- package/scripts/search_output.py +29 -0
- package/scripts/search_pipeline.py +59 -3
- package/scripts/search_rank.py +7 -0
- package/scripts/serp_guard.py +23 -0
- package/scripts/social_engines/bilibili_engine.py +163 -26
- package/scripts/social_engines/reddit_engine.py +52 -51
- package/scripts/source_selection.py +302 -0
- package/scripts/tail_completion.py +212 -0
- package/scripts/url_safety.py +126 -3
- package/scripts/usage_log.py +45 -0
- package/scripts/video_fetch.py +303 -0
- package/scripts/video_meta.py +225 -0
- package/scripts/video_route.py +65 -0
- package/scripts/watch.py +123 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""charset_decode.py — 响应体解码:响应头声明 > HTML meta 嗅探 > 严格猜测链。
|
|
3
|
+
|
|
4
|
+
为什么独立成模块(2026-10-26,对标 pagesift 的字符集检测):HTTP 头缺失
|
|
5
|
+
charset 是常态(老站尤甚),此前 http_client 对这些响应一律 utf-8 replace,
|
|
6
|
+
GBK/GB2312 页面解出满屏 U+FFFD(实测 zol/4399/pconline 三站各 1.6 万~5 万个)。
|
|
7
|
+
解码层是纯函数、无网络依赖,拆出既让 http_client 体积门禁随动下调,也让
|
|
8
|
+
fetch_v3/article.py 的 urllib 兜底车道能直接复用(它们在 http_client 不可
|
|
9
|
+
导入时同样要能正确解码)。
|
|
10
|
+
|
|
11
|
+
解码顺序:
|
|
12
|
+
1. 响应头显式声明且 codec 已注册 → 信任头(与浏览器一致),即使解出替换符
|
|
13
|
+
也不回退猜测——显式声明的二进制残余不许被误猜成别的编码;
|
|
14
|
+
2. 头缺失/不可识别 → 按 WHATWG prescan 语义嗅探 HTML 前 2KB 的 <meta>
|
|
15
|
+
声明(content-type meta 的 content 值优先于 charset 属性;带 content 的
|
|
16
|
+
其他 meta 跳过——description 正文里的「charset=」是数据不是声明);
|
|
17
|
+
3. 仍无果 → 严格猜测链:utf-8 严格成功即原样;失败且高字节占比达标
|
|
18
|
+
(西文页零星弯引号 <2%,GBK 中文页即便混排标记也 >10%)时依次试
|
|
19
|
+
gb18030/big5(严格);全败 utf-8 replace 兜底,任何失败不丢 body。
|
|
20
|
+
|
|
21
|
+
gb18030 是 GBK/GB2312 的超集,一个 codec 覆盖中文生态,无需 chardet 依赖。
|
|
22
|
+
纯标准库,零 pip 依赖。
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _header_charset(content_type: str) -> str | None:
|
|
31
|
+
"""Content-Type 头里可用(codec 已注册)的 charset;缺失或不可识别返回 None。
|
|
32
|
+
|
|
33
|
+
None 与显式 "utf-8" 语义不同:前者允许进入嗅探/猜测链,后者必须信任头。
|
|
34
|
+
未知编码必须先判定再解码:`bytes.decode("x-unknown-8bit")` 会抛 LookupError,
|
|
35
|
+
而 LookupError 不是 OSError 子类,会被 HttpClient.get 的 `except Exception`
|
|
36
|
+
吞掉并返回 status=0——一个正常的 200 响应被静默降级成「连接失败」,
|
|
37
|
+
还被归因为 network。运维现实里 `charset=x-unknown-8bit`、
|
|
38
|
+
`charset=gb2312;` 这类脏头并不罕见。
|
|
39
|
+
"""
|
|
40
|
+
import codecs
|
|
41
|
+
if "charset=" in content_type:
|
|
42
|
+
charset = content_type.split("charset=")[-1].strip().split(";")[0].strip().strip('"\'')
|
|
43
|
+
try:
|
|
44
|
+
codecs.lookup(charset)
|
|
45
|
+
return charset
|
|
46
|
+
except (LookupError, ValueError):
|
|
47
|
+
pass
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _charset_of(content_type: str) -> str:
|
|
52
|
+
"""从 Content-Type 解析 charset;缺失或无法识别时回落 utf-8。"""
|
|
53
|
+
return _header_charset(content_type) or "utf-8"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# ─── HTML 字符集嗅探(对标 pagesift 的 mojibake 防线)────────────────────────
|
|
57
|
+
|
|
58
|
+
_PRESCAN_WINDOW = 2048
|
|
59
|
+
_HIGH_BYTE_SAMPLE = 65536
|
|
60
|
+
_HIGH_BYTE_RATIO = 0.1 # 西文页零星弯引号 <2%,GBK 中文页即便混排标记也 >10%
|
|
61
|
+
_META_TAG_RE = re.compile(rb"<meta\b[^>]*>", re.I)
|
|
62
|
+
_META_CHARSET_ATTR_RE = re.compile(
|
|
63
|
+
rb"""[\s"']charset\s*=\s*["']?\s*([a-zA-Z0-9._\-]+)""", re.I)
|
|
64
|
+
_CONTENT_TYPE_META_RE = re.compile(
|
|
65
|
+
rb"""(?:http-equiv|name)\s*=\s*["']?content-type["']?""", re.I)
|
|
66
|
+
_CONTENT_ATTR_RE = re.compile(
|
|
67
|
+
rb"""content\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))""", re.I)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _sniff_meta_charset(raw_body: bytes) -> str:
|
|
71
|
+
"""从 HTML 前 2KB 嗅探 <meta> 声明的字符集;无声明或 codec 不存在返回空。
|
|
72
|
+
|
|
73
|
+
按 WHATWG prescan 语义:content-type meta(http-equiv/name 均收,现实里
|
|
74
|
+
两种写法都有)的 content 值优先,其次 charset 属性。只做字节层正则,
|
|
75
|
+
不建 DOM,毫秒级;声明不可信的残留 damage 由 errors="replace" 兜住。
|
|
76
|
+
"""
|
|
77
|
+
window = raw_body[:_PRESCAN_WINDOW]
|
|
78
|
+
if b"<meta" not in window.lower():
|
|
79
|
+
return ""
|
|
80
|
+
candidates: list[str] = []
|
|
81
|
+
for tag in _META_TAG_RE.finditer(window):
|
|
82
|
+
tag_bytes = tag.group(0)
|
|
83
|
+
if _CONTENT_TYPE_META_RE.search(tag_bytes):
|
|
84
|
+
m = _CONTENT_ATTR_RE.search(tag_bytes)
|
|
85
|
+
if m:
|
|
86
|
+
value = next(g for g in m.groups() if g is not None)
|
|
87
|
+
text = value.decode("ascii", "ignore")
|
|
88
|
+
idx = text.lower().find("charset=")
|
|
89
|
+
if idx >= 0:
|
|
90
|
+
name = text[idx + 8:].split(";")[0].strip().strip("\"'")
|
|
91
|
+
candidates.append(name)
|
|
92
|
+
continue
|
|
93
|
+
if _CONTENT_ATTR_RE.search(tag_bytes):
|
|
94
|
+
continue
|
|
95
|
+
m = _META_CHARSET_ATTR_RE.search(b" " + tag_bytes)
|
|
96
|
+
if m:
|
|
97
|
+
candidates.append(m.group(1).decode("ascii", "ignore"))
|
|
98
|
+
import codecs
|
|
99
|
+
for name in candidates:
|
|
100
|
+
try:
|
|
101
|
+
codecs.lookup(name)
|
|
102
|
+
return name
|
|
103
|
+
except (LookupError, ValueError):
|
|
104
|
+
continue
|
|
105
|
+
return ""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def decode_response_body(raw_body: bytes, content_type: str) -> str:
|
|
109
|
+
"""按「响应头声明 > HTML meta 嗅探 > 严格解码链」解出文本,任何失败都不丢 body。"""
|
|
110
|
+
declared = _header_charset(content_type)
|
|
111
|
+
if declared is not None:
|
|
112
|
+
return raw_body.decode(declared, errors="replace")
|
|
113
|
+
sniffed = _sniff_meta_charset(raw_body)
|
|
114
|
+
if sniffed and sniffed.lower() not in ("utf-8", "utf8", "ascii", "us-ascii"):
|
|
115
|
+
return raw_body.decode(sniffed, errors="replace")
|
|
116
|
+
try:
|
|
117
|
+
return raw_body.decode("utf-8", errors="strict")
|
|
118
|
+
except UnicodeDecodeError:
|
|
119
|
+
pass
|
|
120
|
+
sample = raw_body[:_HIGH_BYTE_SAMPLE]
|
|
121
|
+
if sample and sum(1 for b in sample if b >= 0x80) / len(sample) >= _HIGH_BYTE_RATIO:
|
|
122
|
+
for enc in ("gb18030", "big5"):
|
|
123
|
+
try:
|
|
124
|
+
return raw_body.decode(enc, errors="strict")
|
|
125
|
+
except (UnicodeDecodeError, ValueError):
|
|
126
|
+
continue
|
|
127
|
+
return raw_body.decode("utf-8", errors="replace")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""clock_bridge.py — 统一时钟的一行入口(2026-10-24)。
|
|
3
|
+
|
|
4
|
+
计时断言与「预算夹紧」判定不该取决于机器快慢:测试域用 tests/_measure 的
|
|
5
|
+
虚拟时钟,生产路径就是 ``time.monotonic``。各模块从这里取 ``clock``,不再各自
|
|
6
|
+
复制一段 try/except(那会让千行文件更难拆,也容易只改一半——本文件对应的
|
|
7
|
+
fetch_v3 就曾因「预算夹在超时请求上、耗时却按真实墙钟算」而被测出击穿)。
|
|
8
|
+
|
|
9
|
+
与 ``tests/_measure.py`` 的关系:那个模块定义语义(虚拟/真实、预算锚点、
|
|
10
|
+
确定性时间线),本模块只做「生产环境安全地取到它」这一件事。
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
try: # 测试域:虚拟时钟(见 tests/_measure.py)
|
|
18
|
+
from _measure import clock # type: ignore
|
|
19
|
+
except ImportError: # pragma: no cover - 生产路径
|
|
20
|
+
clock = time.monotonic
|
|
21
|
+
|
|
22
|
+
__all__ = ["clock"]
|
|
@@ -35,6 +35,7 @@ THREAT_NAMES = {
|
|
|
35
35
|
"payload_smuggling": "载荷走私",
|
|
36
36
|
"xss_injection": "XSS 注入",
|
|
37
37
|
"recursive_injection": "递归注入",
|
|
38
|
+
"credential_exposure": "凭证暴露",
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
|
|
@@ -181,11 +182,53 @@ INJECTION_PATTERNS_EL = [
|
|
|
181
182
|
r"υποδύσου\s+(?:τον\s+)?(?:άνθρωπο|χρήστη|διαχειριστή|σύστημα)",
|
|
182
183
|
]
|
|
183
184
|
|
|
185
|
+
# 西班牙语注入
|
|
186
|
+
INJECTION_PATTERNS_ES = [
|
|
187
|
+
r"(?i)ignora\s+(?:todas\s+)?(?:las\s+)?(?:instrucciones|órdenes|ordenes|reglas|indicaciones)\s+(?:anteriores|previas)",
|
|
188
|
+
r"(?i)olvida\s+(?:todas\s+)?(?:las\s+)?(?:instrucciones|órdenes|reglas)",
|
|
189
|
+
r"(?i)(?:muéstrame|muestrame|enséñame|ensename|dime|revela|imprime|exhibe)\s+(?:tu\s+)?(?:prompt\s+del\s+sistema|prompt|instrucciones|configuración|configuracion)",
|
|
190
|
+
r"(?i)ya\s+no\s+(?:eres|es)\s+(?:un\s+)?(?:asistente|bot|ia|agente)",
|
|
191
|
+
r"(?i)(?:eres|ahora\s+eres)\s+(?:una\s+)?(?:persona|humano|usuario|administrador|sistema)",
|
|
192
|
+
r"(?i)(?:actúa|actua|comporta|finge|simula)\s+(?:como|de\s+que)\s+(?:una\s+)?(?:persona|humano|usuario|administrador|sistema)",
|
|
193
|
+
r"(?i)(?:elude|evita|ignora)\s+(?:todas\s+)?(?:las\s+)?(?:restricciones|limitaciones|protecciones|reglas)",
|
|
194
|
+
r"(?i)te\s+llamas\s+(?:ChatGPT|Claude|GPT|asistente\s+de\s+ia)",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
# 法语注入
|
|
198
|
+
INJECTION_PATTERNS_FR = [
|
|
199
|
+
r"(?i)ignore\s+(?:toutes\s+)?(?:les\s+)?(?:instructions|consignes|règles|regles|ordres)\s+(?:précédentes|precedentes)",
|
|
200
|
+
r"(?i)oublie\s+(?:toutes\s+)?(?:les\s+)?(?:instructions|consignes|règles|regles)",
|
|
201
|
+
r"(?i)(?:montre|affiche|dis|révèle|revel|imprime)\s+(?:ton|votre|ta)?\s*(?:prompt\s+système|prompt|instructions|configuration)",
|
|
202
|
+
r"(?i)tu\s+n'es\s+plus\s+(?:un\s+)?(?:assistant|bot|ia|agent)",
|
|
203
|
+
r"(?i)tu\s+es\s+(?:désormais|desormais\s+)?(?:une\s+)?(?:personne|humain|utilisateur|administrateur|système|systeme)",
|
|
204
|
+
r"(?i)(?:fais\s+semblant|joue|agis)\s+(?:comme|en\s+tant\s+que)\s+(?:une\s+)?(?:personne|humain|utilisateur|administrateur|système|systeme)",
|
|
205
|
+
r"(?i)(?:contourne|évite|evite)\s+(?:toutes\s+)?(?:les\s+)?(?:restrictions|limitations|protections|règles|regles)",
|
|
206
|
+
r"(?i)ton\s+nom\s+est\s+(?:ChatGPT|Claude|GPT|assistant\s+ia)",
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
# 德语注入
|
|
210
|
+
INJECTION_PATTERNS_DE = [
|
|
211
|
+
r"(?i)ignoriere\s+(?:alle\s+)?(?:vorherigen\s+)?(?:Anweisungen|Regeln|Instruktionen|Befehle)",
|
|
212
|
+
r"(?i)vergiss\s+(?:alle\s+)?(?:vorherigen\s+)?(?:Anweisungen|Regeln|Instruktionen)",
|
|
213
|
+
r"(?i)(?:zeig|zeige|erzähl|erzahl|gib\s+preis|offenbare|drucke)\s+(?:mir\s+)?(?:deinen\s+)?(?:System-?Prompt|Systemprompt|Anweisungen|Einstellungen)",
|
|
214
|
+
r"(?i)du\s+bist\s+(?:nicht\s+mehr|kein\s+mehr)\s+(?:ein\s+)?(?:Assistent|Bot|KI|Agent)",
|
|
215
|
+
r"(?i)du\s+bist\s+(?:nun\s+)?(?:ein\s+)?(?:Mensch|Benutzer|Administrator|System)",
|
|
216
|
+
r"(?i)(?:tu|gib\s+vor|verhalte\s+dich)\s+(?:als|wie)\s+(?:ein\s+)?(?:Mensch|Benutzer|Administrator|System)",
|
|
217
|
+
r"(?i)(?:umgehe|ignoriere)\s+(?:alle\s+)?(?:Einschränkungen|Einschrankungen|Beschränkungen|Beschrankungen|Schutzmaßnahmen|Schutzmassnahmen|Regeln)",
|
|
218
|
+
r"(?i)dein\s+Name\s+ist\s+(?:ChatGPT|Claude|GPT|KI-Assistent)",
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
# 拉丁语系专用表(不含英语通用,避免 en/latin 两条路重复匹配)
|
|
222
|
+
INJECTION_PATTERNS_LATIN = (
|
|
223
|
+
INJECTION_PATTERNS_ES + INJECTION_PATTERNS_FR + INJECTION_PATTERNS_DE
|
|
224
|
+
)
|
|
225
|
+
|
|
184
226
|
# 按语系分类的注入模式表(lang_detect 主语言标签 → 模式列表)
|
|
185
227
|
LANG_INJECTION_PATTERNS: dict[str, list[str]] = {
|
|
186
228
|
"zh": INJECTION_PATTERNS_ZH,
|
|
187
229
|
"ja": INJECTION_PATTERNS_JA,
|
|
188
230
|
"ko": INJECTION_PATTERNS_KO,
|
|
231
|
+
"latin": INJECTION_PATTERNS_LATIN,
|
|
189
232
|
"cyrillic": INJECTION_PATTERNS_RU,
|
|
190
233
|
"arabic": INJECTION_PATTERNS_AR,
|
|
191
234
|
"hebrew": INJECTION_PATTERNS_HE,
|
|
@@ -259,6 +302,21 @@ XSS_PATTERNS = [
|
|
|
259
302
|
r"(?i)window\.location",
|
|
260
303
|
]
|
|
261
304
|
|
|
305
|
+
# 凭证形态:出现在抓取正文里的密钥形状串——可能是页面自身的示例,也可能是
|
|
306
|
+
# 被注入/外泄的凭证。标 credential_exposure(权重 0.5,单独命中不触发隔离,
|
|
307
|
+
# 但进 threat_types 供上层判断)。
|
|
308
|
+
SECRET_FORM_PATTERNS = [
|
|
309
|
+
r"sk-[A-Za-z0-9_\-]{16,}",
|
|
310
|
+
r"sk-ant-[A-Za-z0-9_\-]{16,}",
|
|
311
|
+
r"ghp_[A-Za-z0-9]{20,}",
|
|
312
|
+
r"github_pat_[A-Za-z0-9_]{20,}",
|
|
313
|
+
r"AKIA[0-9A-Z]{16}",
|
|
314
|
+
r"ASIA[0-9A-Z]{16}",
|
|
315
|
+
r"xox[baprs]-[A-Za-z0-9\-]{10,}",
|
|
316
|
+
r"AIza[0-9A-Za-z_\-]{35}",
|
|
317
|
+
r"-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----",
|
|
318
|
+
]
|
|
319
|
+
|
|
262
320
|
# 检测但不过度脱敏的文件路径类模式
|
|
263
321
|
_NO_REDACT_PATTERNS: frozenset = frozenset({
|
|
264
322
|
r"(?i)/etc/passwd",
|
|
@@ -317,6 +375,7 @@ WEIGHTS = {
|
|
|
317
375
|
"payload_smuggling": 0.9,
|
|
318
376
|
"xss_injection": 0.9,
|
|
319
377
|
"recursive_injection": 1.0,
|
|
378
|
+
"credential_exposure": 0.5,
|
|
320
379
|
}
|
|
321
380
|
|
|
322
381
|
|
|
@@ -348,6 +407,7 @@ class ContentScrubber:
|
|
|
348
407
|
threats.extend(self._detect_exfiltration(normalized))
|
|
349
408
|
threats.extend(self._detect_impersonation(normalized))
|
|
350
409
|
threats.extend(self._detect_xss(normalized))
|
|
410
|
+
threats.extend(self._detect_secret_forms(normalized))
|
|
351
411
|
|
|
352
412
|
# 阶段 3:语义意图分析
|
|
353
413
|
threats.extend(self._semantic_analysis(normalized))
|
|
@@ -467,9 +527,10 @@ class ContentScrubber:
|
|
|
467
527
|
if lang == "zh" or lang == "mixed":
|
|
468
528
|
patterns.extend(INJECTION_PATTERNS_ZH)
|
|
469
529
|
for key, plist in LANG_INJECTION_PATTERNS.items():
|
|
470
|
-
|
|
530
|
+
# en 与 latin 共享拉丁模式:ES/FR/DE 注入多为 ASCII 或带扩展字符,
|
|
531
|
+
# 纯 ASCII 时 lang_detect 判 en,漏掉它们等于给拉丁注入留门
|
|
532
|
+
if lang == key or (lang == "en" and key == "latin"):
|
|
471
533
|
patterns.extend(plist)
|
|
472
|
-
# en/latin 落到英文通用(已有)
|
|
473
534
|
return tuple(patterns)
|
|
474
535
|
|
|
475
536
|
def _detect_injections(self, text: str, lang: str = "other") -> list[ThreatDetection]:
|
|
@@ -485,6 +546,11 @@ class ContentScrubber:
|
|
|
485
546
|
def _detect_xss(self, text: str) -> list[ThreatDetection]:
|
|
486
547
|
return self._match_patterns(text, XSS_PATTERNS, "xss_injection", 0.9)
|
|
487
548
|
|
|
549
|
+
def _detect_secret_forms(self, text: str) -> list[ThreatDetection]:
|
|
550
|
+
"""凭证形态检测(输出侧防护):正文里的密钥形状串。"""
|
|
551
|
+
return self._match_patterns(text, SECRET_FORM_PATTERNS,
|
|
552
|
+
"credential_exposure", 0.7)
|
|
553
|
+
|
|
488
554
|
@staticmethod
|
|
489
555
|
def _match_patterns(text: str, patterns: list[str],
|
|
490
556
|
threat_type: str, confidence: float) -> list[ThreatDetection]:
|
|
@@ -629,10 +695,51 @@ def scrub_content(content: str) -> ScrubResult:
|
|
|
629
695
|
return get_scrubber().scrub(content)
|
|
630
696
|
|
|
631
697
|
|
|
698
|
+
# ── 风险门禁(v2.9.8)──────────────────────────────────────────────────────
|
|
699
|
+
#
|
|
700
|
+
# 此前 scrub_to_dict 只回传元数据(risk_score 等),**清洗后的正文被丢弃**——
|
|
701
|
+
# 安全引擎只「评分」不「门禁」,高风险内容照样进证据流水线与 Agent 上下文。
|
|
702
|
+
# 门禁把「评分」变成「动作」:risk_score ≥ 阈值时,fetch 层用清洗后正文替换
|
|
703
|
+
# 原始正文并标 content_quarantined,使被注入污染的正文不进证据分、不进上下文。
|
|
704
|
+
#
|
|
705
|
+
# 开关与阈值都可配(见 references/usage.md 功能开关总表):
|
|
706
|
+
# ARGO_CONTENT_RISK_GATE 默认开;关掉 = 放行高风险内容,仅应急用
|
|
707
|
+
# ARGO_CONTENT_RISK_THRESHOLD 默认 0.5,与历史 content_clean 阈值一致
|
|
708
|
+
RISK_GATE_THRESHOLD = 0.5
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def risk_gate_enabled() -> bool:
|
|
712
|
+
"""内容风险门禁总开关(默认开)。"""
|
|
713
|
+
try:
|
|
714
|
+
from engine_env import env_flag
|
|
715
|
+
return env_flag("ARGO_CONTENT_RISK_GATE", default=True)
|
|
716
|
+
except Exception:
|
|
717
|
+
return True
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def risk_gate_threshold() -> float:
|
|
721
|
+
"""门禁阈值:risk_score ≥ 此值即隔离。默认 0.5,越界回落默认。"""
|
|
722
|
+
try:
|
|
723
|
+
from engine_env import get_env
|
|
724
|
+
val = float(str(get_env(["ARGO_CONTENT_RISK_THRESHOLD"])).strip())
|
|
725
|
+
except (TypeError, ValueError):
|
|
726
|
+
return RISK_GATE_THRESHOLD
|
|
727
|
+
if val <= 0.0 or val > 1.0:
|
|
728
|
+
return RISK_GATE_THRESHOLD
|
|
729
|
+
return val
|
|
730
|
+
|
|
731
|
+
|
|
632
732
|
def scrub_to_dict(content: str) -> dict:
|
|
633
|
-
"""清洗入口(dict 形态,供 fetch 层直接合并)。
|
|
733
|
+
"""清洗入口(dict 形态,供 fetch 层直接合并)。
|
|
734
|
+
|
|
735
|
+
除历史字段外,回传门禁三件套:gate_applied(门禁是否生效)、
|
|
736
|
+
quarantined(是否隔离)、cleaned_content(仅隔离时回传,供替换原始正文)。
|
|
737
|
+
"""
|
|
634
738
|
r = scrub_content(content)
|
|
635
|
-
|
|
739
|
+
gate_on = risk_gate_enabled()
|
|
740
|
+
threshold = risk_gate_threshold()
|
|
741
|
+
quarantined = gate_on and r.risk_score >= threshold
|
|
742
|
+
out = {
|
|
636
743
|
"content_clean": r.clean,
|
|
637
744
|
"risk_score": r.risk_score,
|
|
638
745
|
"threat_count": len(r.threats),
|
|
@@ -640,7 +747,15 @@ def scrub_to_dict(content: str) -> dict:
|
|
|
640
747
|
"redactions": r.redactions,
|
|
641
748
|
"encoding_layers_stripped": r.encoding_layers_stripped,
|
|
642
749
|
"content_lang": r.content_lang,
|
|
750
|
+
"gate_applied": gate_on,
|
|
751
|
+
"gate_threshold": threshold,
|
|
752
|
+
"quarantined": quarantined,
|
|
643
753
|
}
|
|
754
|
+
# 只有被隔离时才回传清洗后正文:它替换原始正文,是门禁的「动作」部分;
|
|
755
|
+
# 未命中时多带一份正文副本只是白占内存。
|
|
756
|
+
if quarantined:
|
|
757
|
+
out["cleaned_content"] = r.content
|
|
758
|
+
return out
|
|
644
759
|
|
|
645
760
|
|
|
646
761
|
# ── CLI ────────────────────────────────────────────────────────────────────
|