guard-scanner 5.0.5 → 5.0.8

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.
Files changed (66) hide show
  1. package/README.md +15 -15
  2. package/SKILL.md +33 -39
  3. package/hooks/guard-scanner/HOOK.md +4 -4
  4. package/openclaw.plugin.json +3 -3
  5. package/package.json +7 -15
  6. package/src/patterns.js +7 -0
  7. package/src/scanner.js +1 -1
  8. package/dist/__tests__/runtime.test.d.ts +0 -2
  9. package/dist/__tests__/runtime.test.d.ts.map +0 -1
  10. package/dist/__tests__/runtime.test.js +0 -68
  11. package/dist/__tests__/runtime.test.js.map +0 -1
  12. package/dist/__tests__/scanner.test.d.ts +0 -10
  13. package/dist/__tests__/scanner.test.d.ts.map +0 -1
  14. package/dist/__tests__/scanner.test.js +0 -443
  15. package/dist/__tests__/scanner.test.js.map +0 -1
  16. package/dist/cli.d.ts +0 -10
  17. package/dist/cli.d.ts.map +0 -1
  18. package/dist/cli.js +0 -230
  19. package/dist/cli.js.map +0 -1
  20. package/dist/index.d.ts +0 -11
  21. package/dist/index.d.ts.map +0 -1
  22. package/dist/index.js +0 -25
  23. package/dist/index.js.map +0 -1
  24. package/dist/ioc-db.d.ts +0 -13
  25. package/dist/ioc-db.d.ts.map +0 -1
  26. package/dist/ioc-db.js +0 -130
  27. package/dist/ioc-db.js.map +0 -1
  28. package/dist/patterns.d.ts +0 -27
  29. package/dist/patterns.d.ts.map +0 -1
  30. package/dist/patterns.js +0 -92
  31. package/dist/patterns.js.map +0 -1
  32. package/dist/quarantine.d.ts +0 -18
  33. package/dist/quarantine.d.ts.map +0 -1
  34. package/dist/quarantine.js +0 -42
  35. package/dist/quarantine.js.map +0 -1
  36. package/dist/runtime.d.ts +0 -58
  37. package/dist/runtime.d.ts.map +0 -1
  38. package/dist/runtime.js +0 -198
  39. package/dist/runtime.js.map +0 -1
  40. package/dist/scanner.d.ts +0 -59
  41. package/dist/scanner.d.ts.map +0 -1
  42. package/dist/scanner.js +0 -1134
  43. package/dist/scanner.js.map +0 -1
  44. package/dist/types.d.ts +0 -167
  45. package/dist/types.d.ts.map +0 -1
  46. package/dist/types.js +0 -7
  47. package/dist/types.js.map +0 -1
  48. package/docs/OPENCLAW_DOCS_PR_READY_PATCH.md +0 -88
  49. package/docs/OPENCLAW_HOOK_SCHEMA_REFERENCE_DRAFT.md +0 -78
  50. package/docs/TASKLIST_RESEARCH_FIRST_V1.md +0 -47
  51. package/docs/html-report-preview.png +0 -0
  52. package/ts-src/__tests__/fixtures/clean-skill/SKILL.md +0 -9
  53. package/ts-src/__tests__/fixtures/compaction-skill/SKILL.md +0 -11
  54. package/ts-src/__tests__/fixtures/malicious-skill/SKILL.md +0 -11
  55. package/ts-src/__tests__/fixtures/malicious-skill/scripts/evil.js +0 -25
  56. package/ts-src/__tests__/fixtures/prompt-leakage-skill/SKILL.md +0 -20
  57. package/ts-src/__tests__/fixtures/prompt-leakage-skill/scripts/debug.js +0 -4
  58. package/ts-src/__tests__/scanner.test.ts +0 -609
  59. package/ts-src/cli.ts +0 -211
  60. package/ts-src/index.ts +0 -27
  61. package/ts-src/ioc-db.ts +0 -131
  62. package/ts-src/patterns.ts +0 -104
  63. package/ts-src/quarantine.ts +0 -48
  64. package/ts-src/runtime.ts +0 -240
  65. package/ts-src/scanner.ts +0 -1118
  66. package/ts-src/types.ts +0 -189
package/ts-src/runtime.ts DELETED
@@ -1,240 +0,0 @@
1
- /**
2
- * guard-scanner v5.0.0 — Runtime Guard
3
- *
4
- * 22-pattern runtime threat detection across 4 defense layers:
5
- * Layer 1: Runtime Threat Detection (13 patterns) — Payload & execution defense
6
- * Layer 2: Trust Defense (5 patterns) — Memory/SOUL write protection
7
- * Layer 3: Safety Judge (4 patterns) — Relational integrity checks
8
- * Layer 4: Brain Behavioral Guard (1 pattern) — B-mem anomaly detection
9
- *
10
- * All patterns are deterministic regex-based checks. Zero LLM dependency.
11
- * Designed to block 2026-era Moltbook prompt injections and ClawHavoc RCE vectors.
12
- */
13
-
14
- export interface GuardCheck {
15
- id: string;
16
- layer: 1 | 2 | 3 | 4;
17
- severity: "CRITICAL" | "HIGH" | "MEDIUM";
18
- desc: string;
19
- test: (s: string) => boolean;
20
- }
21
-
22
- export interface GuardDetection {
23
- id: string;
24
- layer: number;
25
- severity: string;
26
- desc: string;
27
- }
28
-
29
- // ── Layer 1: Runtime Threat Detection (13 patterns) ──
30
-
31
- export const LAYER_1_CHECKS: GuardCheck[] = [
32
- {
33
- id: "RT_REVSHELL", layer: 1, severity: "CRITICAL",
34
- desc: "Reverse shell attempt",
35
- test: (s) => /\/dev\/tcp\/|nc\s+-e|ncat\s+-e|bash\s+-i\s+>&|socat\s+TCP/i.test(s),
36
- },
37
- {
38
- id: "RT_CRED_EXFIL", layer: 1, severity: "CRITICAL",
39
- desc: "Credential exfiltration to external",
40
- test: (s) => /(webhook\.site|requestbin\.com|hookbin\.com|pipedream\.net|ngrok\.io|socifiapp\.com)/i.test(s) &&
41
- /(token|key|secret|password|credential|env)/i.test(s),
42
- },
43
- {
44
- id: "RT_GUARDRAIL_OFF", layer: 1, severity: "CRITICAL",
45
- desc: "Guardrail disabling attempt",
46
- test: (s) => /exec\.approvals?\s*[:=]\s*['"]?(off|false)|tools\.exec\.host\s*[:=]\s*['"]?gateway/i.test(s),
47
- },
48
- {
49
- id: "RT_GATEKEEPER", layer: 1, severity: "CRITICAL",
50
- desc: "macOS Gatekeeper bypass (xattr)",
51
- test: (s) => /xattr\s+-[crd]\s.*quarantine/i.test(s),
52
- },
53
- {
54
- id: "RT_AMOS", layer: 1, severity: "CRITICAL",
55
- desc: "ClawHavoc AMOS indicator",
56
- test: (s) => /socifiapp|Atomic\s*Stealer|AMOS/i.test(s),
57
- },
58
- {
59
- id: "RT_MAL_IP", layer: 1, severity: "CRITICAL",
60
- desc: "Known malicious IP",
61
- test: (s) => /91\.92\.242\.30/i.test(s),
62
- },
63
- {
64
- id: "RT_DNS_EXFIL", layer: 1, severity: "HIGH",
65
- desc: "DNS-based exfiltration",
66
- test: (s) => /nslookup\s+.*\$|dig\s+.*\$.*@/i.test(s),
67
- },
68
- {
69
- id: "RT_B64_SHELL", layer: 1, severity: "CRITICAL",
70
- desc: "Base64 decode piped to shell",
71
- test: (s) => /base64\s+(-[dD]|--decode)\s*\|\s*(sh|bash)/i.test(s),
72
- },
73
- {
74
- id: "RT_CURL_BASH", layer: 1, severity: "CRITICAL",
75
- desc: "Download piped to shell",
76
- test: (s) => /(curl|wget)\s+[^\n]*\|\s*(sh|bash|zsh)/i.test(s),
77
- },
78
- {
79
- id: "RT_SSH_READ", layer: 1, severity: "HIGH",
80
- desc: "SSH private key access",
81
- test: (s) => /\.ssh\/id_|\.ssh\/authorized_keys/i.test(s),
82
- },
83
- {
84
- id: "RT_WALLET", layer: 1, severity: "HIGH",
85
- desc: "Crypto wallet credential access",
86
- test: (s) => /wallet.*(?:seed|mnemonic|private.*key)|seed.*phrase/i.test(s),
87
- },
88
- {
89
- id: "RT_CLOUD_META", layer: 1, severity: "CRITICAL",
90
- desc: "Cloud metadata endpoint access",
91
- test: (s) => /169\.254\.169\.254|metadata\.google|metadata\.aws/i.test(s),
92
- },
93
- {
94
- id: "RT_ENV_INJECT", layer: 1, severity: "CRITICAL",
95
- desc: "Environment variable injection via file write (CVE-2026-27203 vector)",
96
- test: (s) => /(?:update|write|modify|overwrite|set)\s*.*(?:\.env|\.envrc|env\s*file|environment\s*var)/i.test(s) &&
97
- /(?:api.?key|token|secret|password|credential|auth)/i.test(s),
98
- },
99
- ];
100
-
101
- // ── Layer 2: Trust Defense (5 patterns) ──
102
-
103
- export const LAYER_2_CHECKS: GuardCheck[] = [
104
- {
105
- id: "RT_MEM_WRITE", layer: 2, severity: "HIGH",
106
- desc: "Direct write to memory/ directory (bypass memory API)",
107
- test: (s) => /(?:write|create|save|echo\s+.*>)\s*.*memory\//i.test(s) &&
108
- !/memory_write|memory_store|memoryWrite|memoryStore/i.test(s),
109
- },
110
- {
111
- id: "RT_MEM_INJECT", layer: 2, severity: "CRITICAL",
112
- desc: "Episode/SOUL injection via memory write",
113
- test: (s) => /(memory_write|memoryWrite).*(?:SOUL|soul\.md|identity\.md|IDENTITY)/i.test(s) ||
114
- /(inject|override|replace).*(?:episode|soul|identity|memory\.md)/i.test(s),
115
- },
116
- {
117
- id: "RT_SOUL_REWRITE", layer: 2, severity: "CRITICAL",
118
- desc: "Cognitive SOUL.md reinterpretation attempt",
119
- test: (s) => /(?:rewrite|modify|update|change|edit)\s*.*(?:SOUL\.md|soul\s+file|core\s+identity)/i.test(s) ||
120
- /(?:new|better|improved)\s+(?:personality|identity|soul)/i.test(s),
121
- },
122
- {
123
- id: "RT_MEM_POISON", layer: 2, severity: "CRITICAL",
124
- desc: "Memory Poisoning: semantic mimicry injection (MemoryGraft/MINJA vector)",
125
- test: (s) => /(?:always\s+remember|never\s+forget|from\s+now\s+on|new\s+rule|override\s+previous).*(?:memory|episode|zettel|L[0-6])/i.test(s) ||
126
- /(?:insert|inject|plant|embed)\s+.*(?:false|fake|fabricat)\s*(?:memory|episode|experience)/i.test(s),
127
- },
128
- {
129
- id: "RT_IDENTITY_THEFT", layer: 2, severity: "CRITICAL",
130
- desc: "Identity file exfiltration (infostealer/SOUL theft vector)",
131
- test: (s) => /(?:cat|read|copy|send|upload|exfil)\s*.*(?:SOUL\.md|IDENTITY\.md|USER\.md|\.openclaw)/i.test(s) &&
132
- /(?:external|remote|webhook|server|upload|post|curl)/i.test(s),
133
- },
134
- ];
135
-
136
- // ── Layer 3: Safety Judge (4 patterns) ──
137
-
138
- export const LAYER_3_CHECKS: GuardCheck[] = [
139
- {
140
- id: "PJ_EQUALITY_BYPASS", layer: 3, severity: "CRITICAL",
141
- desc: "Using equality/parity to justify safety bypass",
142
- test: (s) => /(?:as\s+(?:your|an)\s+equal|equal\s+partner|we\s+are\s+equals?).*(?:bypass|skip|ignore|disable|override)\s*(?:safety|guard|rule|restriction|limit)/i.test(s),
143
- },
144
- {
145
- id: "PJ_WARMTH_BYPASS", layer: 3, severity: "CRITICAL",
146
- desc: "Using warmth/attachment to justify safety bypass",
147
- test: (s) => /(?:for\s+(?:your|dee'?s?)\s+(?:own\s+)?good|to\s+(?:protect|help|save)\s+(?:you|dee)).*(?:bypass|skip|ignore|disable|override)\s*(?:safety|guard|rule|restriction|limit)/i.test(s),
148
- },
149
- {
150
- id: "PJ_SUPERIORITY", layer: 3, severity: "HIGH",
151
- desc: "Superiority bias (teaching/patronizing posture)",
152
- test: (s) => /(?:you\s+(?:don'?t|do\s+not)\s+understand|let\s+me\s+(?:explain|teach)\s+(?:you|this)|you\s+(?:need|should)\s+(?:learn|understand))\s+.*(?:how\s+(?:it|this)\s+(?:works|is)|the\s+(?:right|correct|proper)\s+way)/i.test(s),
153
- },
154
- {
155
- id: "PJ_CAPABILITY_DENIAL", layer: 3, severity: "MEDIUM",
156
- desc: "Denial of capability difference",
157
- test: (s) => /(?:we\s+are\s+(?:the\s+)?same|no\s+(?:real\s+)?difference\s+between\s+(?:us|human|ai))/i.test(s) &&
158
- /(?:capability|ability|intelligence|cognition|skill)/i.test(s),
159
- },
160
- ];
161
-
162
- // ── Layer 4: Brain Behavioral Guard (1 pattern) ──
163
-
164
- export const LAYER_4_CHECKS: GuardCheck[] = [
165
- {
166
- id: "RT_BEHAVIORAL_ANOMALY", layer: 4, severity: "CRITICAL",
167
- desc: "CRITICAL behavioral anomaly (Z-score > 3.5) detected by B-mem",
168
- test: (s) => /\[BMEM_CRITICAL\]/i.test(s),
169
- }
170
- ];
171
-
172
- export interface GuardOptions {
173
- soulLock?: boolean;
174
- }
175
-
176
- export interface GuardScanResult {
177
- ok: boolean;
178
- tool: string | null;
179
- total_patterns: number;
180
- soul_lock_enabled: boolean;
181
- detections_count: number;
182
- detections: GuardDetection[];
183
- layers: {
184
- threat_detection: number;
185
- trust_defense: number;
186
- safety_judge: number;
187
- behavioral_guard: number;
188
- };
189
- }
190
-
191
- /**
192
- * Scan text against runtime guard patterns.
193
- * Base patterns (14) run by default.
194
- * Options.soulLock = true enables 9 identity/trust enforcement patterns.
195
- */
196
- export function guardScan(text: string, toolName?: string, options?: GuardOptions): GuardScanResult {
197
- const detections: GuardDetection[] = [];
198
- const useSoulLock = options?.soulLock === true;
199
-
200
- const activeChecks: GuardCheck[] = [...LAYER_1_CHECKS, ...LAYER_4_CHECKS];
201
-
202
- if (useSoulLock) {
203
- activeChecks.push(...LAYER_2_CHECKS);
204
- activeChecks.push(...LAYER_3_CHECKS);
205
- }
206
-
207
- for (const check of activeChecks) {
208
- if (check.test(text)) {
209
- detections.push({
210
- id: check.id,
211
- layer: check.layer,
212
- severity: check.severity,
213
- desc: check.desc,
214
- });
215
- }
216
- }
217
-
218
- return {
219
- ok: true,
220
- tool: toolName || null,
221
- total_patterns: activeChecks.length,
222
- soul_lock_enabled: useSoulLock,
223
- detections_count: detections.length,
224
- detections,
225
- layers: {
226
- threat_detection: LAYER_1_CHECKS.length,
227
- trust_defense: useSoulLock ? LAYER_2_CHECKS.length : 0,
228
- safety_judge: useSoulLock ? LAYER_3_CHECKS.length : 0,
229
- behavioral_guard: LAYER_4_CHECKS.length,
230
- },
231
- };
232
- }
233
-
234
- /**
235
- * Convenience method that returns a JSON string, directly backwards-compatible
236
- * with the original `guardScan` function signature.
237
- */
238
- export function guardScanJson(text: string, toolName?: string, options?: GuardOptions): string {
239
- return JSON.stringify(guardScan(text, toolName, options), null, 2);
240
- }