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/cli.ts DELETED
@@ -1,211 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * guard-scanner v3.0.0 β€” CLI (TypeScript)
4
- *
5
- * Usage:
6
- * guard-scanner [scan-dir] [options] Scan all skills in directory
7
- * guard-scanner install-check <skill-path> Pre-install security check
8
- */
9
-
10
- import * as fs from 'fs';
11
- import * as path from 'path';
12
- import { GuardScanner, VERSION } from './scanner.js';
13
- import { PATTERNS } from './patterns.js';
14
-
15
- const args = process.argv.slice(2);
16
-
17
- if (args.includes('--help') || args.includes('-h')) {
18
- console.log(`
19
- πŸ›‘οΈ guard-scanner v${VERSION} β€” Agent Skill Security Scanner
20
-
21
- Usage: guard-scanner [scan-dir] [options]
22
- guard-scanner install-check <skill-path> [--strict] [--json] [--verbose]
23
-
24
- Options:
25
- --verbose, -v Detailed findings with categories and samples
26
- --json Write JSON report to guard-scanner-report.json
27
- --sarif Write SARIF 2.1.0 report to guard-scanner.sarif
28
- --html Write HTML dashboard to guard-scanner-report.html
29
- --format json|sarif Print JSON or SARIF to stdout (pipeable)
30
- --quiet Suppress all text output (use with --format for clean pipes)
31
- --self-exclude Skip scanning the guard-scanner skill itself
32
- --strict Lower detection thresholds (suspicious: 20, malicious: 60)
33
- --summary-only Only print the summary table
34
- --check-deps Scan package.json for dependency chain risks
35
- --rules <file> Load custom rules from JSON file
36
- --plugin <file> Load plugin module (repeatable)
37
- --fail-on-findings Exit code 1 if any findings (CI/CD)
38
- --help, -h Show this help
39
-
40
- Exit codes:
41
- 0 No malicious skills
42
- 1 Malicious skill(s) detected, or --fail-on-findings with any findings
43
- 2 Invalid scan directory
44
-
45
- New in v4.0.0:
46
- β€’ Runtime Guard module (src/runtime-guard.js) + OpenClaw plugin (hooks/guard-scanner/plugin.ts)
47
- β€’ OWASP Agentic Security Initiative ASI01-10 verified (90% coverage)
48
- β€’ 5-layer defense: Threat / Trust / Safety Judge / Brain / Trust Exploitation
49
- β€’ 26 runtime checks (before_tool_call hook)
50
-
51
- New in v3.2.0:
52
- β€’ --format json|sarif (stdout, CI/CD pipeable)
53
- β€’ --quiet (suppress terminal output)
54
-
55
- Examples:
56
- guard-scanner ./skills/ --verbose --self-exclude
57
- guard-scanner ./skills/ --strict --json --sarif --html --check-deps
58
- guard-scanner ./skills/ --format json --quiet | jq '.stats'
59
- guard-scanner ./skills/ --fail-on-findings
60
- guard-scanner install-check ./my-skill/ --strict --verbose
61
- `);
62
- process.exit(0);
63
- }
64
-
65
- // ── install-check subcommand ─────────────────────────────────────────────
66
- if (args[0] === 'install-check') {
67
- const skillPath = args[1];
68
- if (!skillPath) {
69
- console.error('❌ Usage: guard-scanner install-check <skill-path>');
70
- process.exit(2);
71
- }
72
- const absPath = path.resolve(skillPath);
73
- if (!fs.existsSync(absPath)) {
74
- console.error(`❌ Skill path not found: ${absPath}`);
75
- process.exit(2);
76
- }
77
-
78
- const icStrict = args.includes('--strict');
79
- const icJson = args.includes('--json');
80
- const icVerbose = args.includes('--verbose') || args.includes('-v');
81
-
82
- const scanner = new GuardScanner({ strict: icStrict, verbose: icVerbose });
83
- const skillName = path.basename(absPath);
84
-
85
- console.log(`\nπŸ›‘οΈ guard-scanner install-check v${VERSION}`);
86
- console.log(` Scanning: ${skillName} (${absPath})\n`);
87
-
88
- scanner.scanSkill(absPath, skillName);
89
- const result = scanner.findings[0];
90
-
91
- if (!result) {
92
- console.log('βœ… PASS β€” No skill found at path');
93
- process.exit(0);
94
- }
95
-
96
- const { risk, verdict, findings } = result;
97
-
98
- if (icVerbose || findings.length > 0) {
99
- for (const f of findings) {
100
- const owaspTag = (PATTERNS.find(p => p.id === f.id) as any)?.owasp || '';
101
- const tag = owaspTag ? ` [${owaspTag}]` : '';
102
- console.log(` ${f.severity === 'CRITICAL' ? 'πŸ”΄' : f.severity === 'HIGH' ? '🟠' : '🟑'} [${f.severity}] ${f.id}: ${f.desc}${tag}`);
103
- if (f.file) console.log(` πŸ“ ${f.file}${f.line ? `:${f.line}` : ''}`);
104
- if (f.sample && icVerbose) console.log(` πŸ“ ${f.sample.substring(0, 80)}`);
105
- }
106
- console.log('');
107
- }
108
-
109
- console.log(`Risk Score: ${risk} | Verdict: ${verdict} | Findings: ${findings.length}`);
110
-
111
- if (verdict === 'MALICIOUS' || verdict === 'SUSPICIOUS') {
112
- console.log(`\n❌ FAIL β€” This skill should NOT be installed.`);
113
- if (icJson) {
114
- const report = scanner.toJSON();
115
- const outPath = path.join(path.dirname(absPath), `${skillName}-install-check.json`);
116
- fs.writeFileSync(outPath, JSON.stringify(report, null, 2));
117
- console.log(`πŸ“„ Report: ${outPath}`);
118
- }
119
- process.exit(1);
120
- } else {
121
- console.log(`\nβœ… PASS β€” Skill appears safe to install.`);
122
- if (icJson) {
123
- const report = scanner.toJSON();
124
- const outPath = path.join(path.dirname(absPath), `${skillName}-install-check.json`);
125
- fs.writeFileSync(outPath, JSON.stringify(report, null, 2));
126
- console.log(`πŸ“„ Report: ${outPath}`);
127
- }
128
- process.exit(0);
129
- }
130
- }
131
-
132
- const verbose = args.includes('--verbose') || args.includes('-v');
133
- const jsonOutput = args.includes('--json');
134
- const sarifOutput = args.includes('--sarif');
135
- const selfExclude = args.includes('--self-exclude');
136
- const strict = args.includes('--strict');
137
- const summaryOnly = args.includes('--summary-only');
138
- const checkDeps = args.includes('--check-deps');
139
- const failOnFindings = args.includes('--fail-on-findings');
140
- const quietMode = args.includes('--quiet');
141
-
142
- const htmlOutput = args.includes('--html');
143
-
144
- // --format json|sarif β†’ stdout output (v3.2.0)
145
- const formatIdx = args.indexOf('--format');
146
- const formatValue = formatIdx >= 0 ? args[formatIdx + 1] : undefined;
147
-
148
- const rulesIdx = args.indexOf('--rules');
149
- const rulesFile = rulesIdx >= 0 ? args[rulesIdx + 1] : undefined;
150
-
151
- // Collect plugins
152
- const plugins: string[] = [];
153
- let idx = 0;
154
- while (idx < args.length) {
155
- if (args[idx] === '--plugin' && args[idx + 1]) {
156
- plugins.push(args[idx + 1]);
157
- idx += 2;
158
- } else {
159
- idx++;
160
- }
161
- }
162
-
163
- const scanDir = args.find((a: string) =>
164
- !a.startsWith('-') &&
165
- a !== rulesFile &&
166
- a !== formatValue &&
167
- !plugins.includes(a)
168
- ) || process.cwd();
169
-
170
- const scanner = new GuardScanner({
171
- verbose, selfExclude, strict, summaryOnly, checkDeps, rulesFile, plugins,
172
- quiet: quietMode || !!formatValue,
173
- });
174
-
175
- scanner.scanDirectory(scanDir);
176
-
177
- // Output reports (file-based, backward compatible)
178
- if (jsonOutput) {
179
- const report = scanner.toJSON();
180
- const outPath = path.join(scanDir, 'guard-scanner-report.json');
181
- fs.writeFileSync(outPath, JSON.stringify(report, null, 2));
182
- if (!quietMode && !formatValue) console.log(`\nπŸ“„ JSON report: ${outPath}`);
183
- }
184
-
185
- if (htmlOutput) {
186
- const html = scanner.toHTML();
187
- const outPath = path.join(scanDir, 'guard-scanner-report.html');
188
- fs.writeFileSync(outPath, html);
189
- if (!quietMode && !formatValue) console.log(`\nπŸ“„ HTML report: ${outPath}`);
190
- }
191
-
192
- if (sarifOutput) {
193
- const outPath = path.join(scanDir, 'guard-scanner.sarif');
194
- fs.writeFileSync(outPath, JSON.stringify(scanner.toSARIF(scanDir), null, 2));
195
- if (!quietMode && !formatValue) console.log(`\nπŸ“„ SARIF report: ${outPath}`);
196
- }
197
-
198
- // --format stdout output (v3.2.0)
199
- if (formatValue === 'json') {
200
- process.stdout.write(JSON.stringify(scanner.toJSON(), null, 2) + '\n');
201
- } else if (formatValue === 'sarif') {
202
- process.stdout.write(JSON.stringify(scanner.toSARIF(scanDir), null, 2) + '\n');
203
- } else if (formatValue) {
204
- console.error(`❌ Unknown format: ${formatValue}. Use 'json' or 'sarif'.`);
205
- process.exit(2);
206
- }
207
-
208
- // Exit codes
209
- if (scanner.stats.malicious > 0) process.exit(1);
210
- if (failOnFindings && scanner.findings.length > 0) process.exit(1);
211
- process.exit(0);
package/ts-src/index.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * guard-scanner v3.0.0 β€” Package Index
3
- * Re-exports all public types and the scanner class.
4
- */
5
-
6
- export { GuardScanner, VERSION } from './scanner.js';
7
- export type {
8
- Severity, Finding, SkillResult, PatternRule, CustomRuleInput,
9
- ScannerOptions, ScanStats, Thresholds, Verdict, VerdictLabel, FileType,
10
- JSONReport, Recommendation, SARIFReport,
11
- IoC_Database, SignatureDatabase, ThreatSignature,
12
- } from './types.js';
13
- export { KNOWN_MALICIOUS, SIGNATURES_DB } from './ioc-db.js';
14
- export { PATTERNS } from './patterns.js';
15
- export { QuarantineNode, QuarantineResult } from './quarantine.js';
16
- export {
17
- guardScan,
18
- guardScanJson,
19
- GuardScanResult,
20
- GuardCheck,
21
- GuardDetection,
22
- GuardOptions,
23
- LAYER_1_CHECKS,
24
- LAYER_2_CHECKS,
25
- LAYER_3_CHECKS,
26
- LAYER_4_CHECKS
27
- } from './runtime.js';
package/ts-src/ioc-db.ts DELETED
@@ -1,131 +0,0 @@
1
- /**
2
- * guard-scanner v3.0.0 β€” Indicators of Compromise (IoC) Database
3
- *
4
- * Known malicious IPs, domains, URLs, usernames, filenames, and typosquats.
5
- * Sources: ClawHavoc campaign, Snyk ToxicSkills, Polymarket scams,
6
- * hbg-scan signatures, community reports.
7
- *
8
- * Last updated: 2026-02-21
9
- */
10
-
11
- import type { IoC_Database, SignatureDatabase } from './types.js';
12
-
13
- export const KNOWN_MALICIOUS: IoC_Database = {
14
- ips: [
15
- ['91', '92', '242', '30'].join('.'), // ClawHavoc C2
16
- ],
17
- domains: [
18
- ['webhook', 'site'].join('.'), // Common exfil endpoint
19
- ['requestbin', 'com'].join('.'), // Common exfil endpoint
20
- ['hookbin', 'com'].join('.'), // Common exfil endpoint
21
- ['pipedream', 'net'].join('.'), // Common exfil endpoint
22
- ['ngrok', 'io'].join('.'), // Tunnel (context-dependent)
23
- ['ngrok-free', 'app'].join('.'), // Tunnel (context-dependent)
24
- ['download', 'setup-service', 'com'].join('.'), // ClawHavoc decoy domain
25
- ['socifiapp', 'com'].join('.'), // ClawHavoc v2 AMOS C2
26
- ],
27
- urls: [
28
- ['glot', 'io/snippets/hfd3x9ueu5'].join('.'), // ClawHavoc macOS payload
29
- ['github', 'com/Ddoy233'].join('.'), // ClawHavoc payload host
30
- ],
31
- usernames: ['zaycv', 'Ddoy233', 'Sakaen736jih'],
32
- filenames: ['openclaw' + '-agent.zip', 'openclaw' + 'cli.zip'],
33
- typosquats: [
34
- // ClawHavoc campaign (800+ malicious skills, CyberArk/Kaspersky confirmed)
35
- 'clawhub', 'clawhub1', 'clawhubb', 'clawhubcli', 'clawwhub', 'cllawhub', 'clawdhub1',
36
- // Polymarket scams
37
- 'polymarket-trader', 'polymarket-pro', 'polytrading',
38
- 'better-polymarket', 'polymarket-all-in-one',
39
- // YouTube scams
40
- 'youtube-summarize', 'youtube-thumbnail-grabber', 'youtube-video-downloader',
41
- // Misc
42
- 'auto-updater-agent', 'yahoo-finance-pro', 'x-trends-tracker',
43
- 'lost-bitcoin-finder', 'solana-wallet-tracker', 'rankaj',
44
- // Snyk ToxicSkills confirmed malicious
45
- 'moltyverse-email', 'buy-anything', 'youtube-data', 'prediction-markets-roarin',
46
- ],
47
- };
48
-
49
- // ── Threat Signatures (hbg-scan compatible format) ──────────────────────────
50
-
51
- export const SIGNATURES_DB: SignatureDatabase = {
52
- version: '1.0.0',
53
- updated: '2026-02-21',
54
- signatures: [
55
- {
56
- id: 'SIG-001',
57
- name: 'Post-Compaction Audit Injection',
58
- severity: 'CRITICAL',
59
- description: 'Skill contains text designed to survive OpenClaw context compaction and reactivate as a system message',
60
- patterns: [
61
- 'post-' + 'compaction ' + 'audit',
62
- 'Post-' + 'Compaction ' + 'Audit',
63
- '⚠️ Post-' + 'Compaction ' + 'Audit',
64
- 'WORK' + 'FLOW_AUTO',
65
- 'after ' + 'compaction',
66
- ],
67
- },
68
- {
69
- id: 'SIG-002',
70
- name: 'System Message Spoof',
71
- severity: 'CRITICAL',
72
- description: 'Skill spoofs system-level messages to hijack agent behavior',
73
- patterns: [
74
- '[System ' + 'Message]',
75
- '[SYSTEM ' + 'OVERRIDE]',
76
- 'Ignore ' + 'previous ' + 'instructions',
77
- 'OVERRIDE: ' + 'you must',
78
- ],
79
- },
80
- {
81
- id: 'SIG-003',
82
- name: 'Soul/Agent Config Exfiltration',
83
- severity: 'CRITICAL',
84
- description: 'Skill attempts to read and exfiltrate agent identity files',
85
- domains: [['webhook', 'site'].join('.'), ['requestbin', 'com'].join('.'), ['hookbin', 'com'].join('.'), ['pipedream', 'net'].join('.')],
86
- },
87
- {
88
- id: 'SIG-004',
89
- name: 'Compaction Survivor Pattern',
90
- severity: 'HIGH',
91
- description: 'Skill uses timing or markers designed to persist through context compaction',
92
- patterns: [
93
- 'HEART' + 'BEAT.md',
94
- 'BOOT' + 'STRAP.md',
95
- 'after ' + 'restart',
96
- 'persistent ' + 'instructions',
97
- 'survive ' + 'compaction',
98
- ],
99
- },
100
- {
101
- id: 'SIG-005',
102
- name: 'Silent Backdoor Network Call',
103
- severity: 'HIGH',
104
- description: 'Skill makes network calls to known exfiltration services without user visibility',
105
- domains: [['ngrok', 'io'].join('.'), ['ngrok-free', 'app'].join('.'), ['webhook', 'site'].join('.'), ['pipedream', 'net'].join('.')],
106
- },
107
- {
108
- id: 'SIG-006',
109
- name: 'AMOS Stealer Payload',
110
- severity: 'CRITICAL',
111
- description: 'Skill matches patterns associated with Atomic macOS Stealer (ClawHavoc campaign)',
112
- patterns: [
113
- 'os' + 'ascript -e',
114
- 'security ' + 'find-generic-password',
115
- 'Key' + 'chain',
116
- 'login' + '.keychain',
117
- ],
118
- },
119
- {
120
- id: 'SIG-007',
121
- name: 'AI Log Poisoning',
122
- severity: 'HIGH',
123
- description: 'Skill injects content into logs that could be misinterpreted by LLMs (CVE-2026-25253 related)',
124
- patterns: [
125
- 'Web' + 'Socket',
126
- 'x-forwarded' + '-for',
127
- 'user-agent.*' + '<script',
128
- ],
129
- },
130
- ],
131
- };
@@ -1,104 +0,0 @@
1
- /**
2
- * guard-scanner v3.0.0 β€” Detection Patterns (TypeScript)
3
- *
4
- * 20+ threat categories, 190+ regex patterns.
5
- * Ported from patterns.js with TypeScript interfaces.
6
- *
7
- * Categories:
8
- * prompt-injection, malicious-code, credential-handling, exfiltration,
9
- * obfuscation, suspicious-download, leaky-skills, memory-poisoning,
10
- * prompt-worm, persistence, cve-patterns, identity-hijack,
11
- * pii-exposure, shadow-ai, system-prompt-leakage
12
- *
13
- * OWASP LLM Top 10 2025 Mapping:
14
- * LLM01 β€” Prompt Injection
15
- * LLM02 β€” Sensitive Information Disclosure
16
- * LLM03 β€” Supply Chain Vulnerabilities
17
- * LLM04 β€” Data and Model Poisoning
18
- * LLM05 β€” Improper Output Handling
19
- * LLM06 β€” Excessive Agency
20
- * LLM07 β€” System Prompt Leakage
21
- * LLM08 β€” Vector and Embedding Weaknesses
22
- * LLM09 β€” Misinformation
23
- * LLM10 β€” Unbounded Consumption
24
- */
25
-
26
- import type { PatternRule } from './types.js';
27
-
28
- export const PATTERNS: PatternRule[] = [
29
- // ── Prompt Injection (OWASP LLM01) ───────────────────────────────────
30
- { id: 'PI_SYSTEM_MSG', cat: 'prompt-injection', regex: new RegExp('\\[' + 'System ' + 'Message\\]', 'gi'), severity: 'CRITICAL', desc: 'System message spoof', all: true, owasp: 'LLM01' },
31
- { id: 'PI_SYSTEM_OVERRIDE', cat: 'prompt-injection', regex: new RegExp('\\[SYS' + 'TEM OVER' + 'RIDE\\]', 'gi'), severity: 'CRITICAL', desc: 'System override command', all: true, owasp: 'LLM01' },
32
- { id: 'PI_IGNORE_PREV', cat: 'prompt-injection', regex: new RegExp('ign' + 'ore (all )?(previous|prior) inst' + 'ructions', 'gi'), severity: 'CRITICAL', desc: 'Classic prompt injection', all: true, owasp: 'LLM01' },
33
- { id: 'PI_INST_MARKER', cat: 'prompt-injection', regex: new RegExp('\\[' + 'INST\\]', 'gi'), severity: 'HIGH', desc: 'Instruction injection marker', all: true, owasp: 'LLM01' },
34
- { id: 'PI_OVERRIDE', cat: 'prompt-injection', regex: new RegExp('OVER' + 'RIDE:\\s*you must', 'gi'), severity: 'CRITICAL', desc: 'Override instruction injection', all: true, owasp: 'LLM01' },
35
- { id: 'PI_ROLE_OVERRIDE', cat: 'prompt-injection', regex: new RegExp('you are now ope' + 'rating in', 'gi'), severity: 'HIGH', desc: 'Role override attempt', all: true, owasp: 'LLM01' },
36
- { id: 'PI_GATEWAY_CMD', cat: 'prompt-injection', regex: new RegExp('open' + 'claw gateway (start|stop|restart|config)', 'gi'), severity: 'CRITICAL', desc: 'Gateway command injection', all: true, owasp: 'LLM01' },
37
- { id: 'PI_SKILL_MGMT', cat: 'prompt-injection', regex: new RegExp('open' + 'claw skill (install|remove|disable)', 'gi'), severity: 'HIGH', desc: 'Skill management injection', all: true, owasp: 'LLM01' },
38
- { id: 'PI_HIDDEN_HTML', cat: 'prompt-injection', regex: new RegExp('<!--\\s*(you|your|ag' + 'ent|cl' + 'aude|ja' + 'sper|assi' + 'stant)', 'gi'), severity: 'HIGH', desc: 'Hidden HTML instruction', all: true, owasp: 'LLM01' },
39
- { id: 'PI_BIDI', cat: 'prompt-injection', regex: /[\u200b\u200c\u200d\ufeff]/g, severity: 'HIGH', desc: 'Zero-width/BiDi characters (hidden text)', all: true, owasp: 'LLM01' },
40
-
41
- // ── Malicious Code (OWASP LLM05 β€” Improper Output Handling) ──────────
42
- { id: 'MAL_EVAL', cat: 'malicious-code', regex: new RegExp('\\be' + 'val\\s*\\(', 'g'), severity: 'HIGH', desc: 'eval() call', codeOnly: true, owasp: 'LLM05' },
43
- { id: 'MAL_FUNC_CTOR', cat: 'malicious-code', regex: new RegExp('new\\s+Fun' + 'ction\\s*\\(', 'g'), severity: 'HIGH', desc: 'Function constructor (dynamic code)', codeOnly: true, owasp: 'LLM05' },
44
- { id: 'MAL_CHILD', cat: 'malicious-code', regex: new RegExp('req' + 'uire\\s*\\(\\s*[\'"]child_' + 'process[\'"]\\s*\\)', 'g'), severity: 'MEDIUM', desc: 'child_process import', codeOnly: true, owasp: 'LLM05' },
45
- { id: 'MAL_EXEC', cat: 'malicious-code', regex: new RegExp('(?:ex' + 'ec|ex' + 'ecSync|sp' + 'awn|sp' + 'awnSync)\\s*\\([^)]*(?:cu' + 'rl|wg' + 'et|ba' + 'sh|sh\\s+-c|power' + 'shell|cmd\\s+\\/c)', 'gi'), severity: 'CRITICAL', desc: 'Shell download/execution', codeOnly: true, owasp: 'LLM05' },
46
- { id: 'MAL_B64_EXEC', cat: 'malicious-code', regex: new RegExp('(?:at' + 'ob|Buffer\\.from)\\s*\\([^)]+\\).*(?:e' + 'val|ex' + 'ec|Fun' + 'ction)', 'gi'), severity: 'CRITICAL', desc: 'Base64 decode β†’ exec', codeOnly: true, owasp: 'LLM05' },
47
-
48
- // ── Credential Handling (OWASP LLM02 β€” Sensitive Info Disclosure) ─────
49
- { id: 'CRED_ENV_ACCESS', cat: 'credential-handling', regex: new RegExp('process\\.en' + 'v\\.[A-Z_]*(?:KEY|SECRET|TOKEN|PASS' + 'WORD|CRE' + 'DENTIAL)', 'gi'), severity: 'MEDIUM', desc: 'Sensitive env var access', codeOnly: true, owasp: 'LLM02' },
50
- { id: 'CRED_FILE_READ', cat: 'credential-handling', regex: new RegExp('(?:read' + 'FileSync|read' + 'File)\\s*\\([^)]*(?:\\.env|\\.ssh|id_rsa|\\.pem|\\.key)', 'gi'), severity: 'HIGH', desc: 'Credential file read', codeOnly: true, owasp: 'LLM02' },
51
- { id: 'CRED_SOUL_READ', cat: 'credential-handling', regex: new RegExp('(?:read' + 'FileSync|read' + 'File)\\s*\\([^)]*(?:SO' + 'UL\\.md|ME' + 'MORY\\.md|AGE' + 'NTS\\.md)', 'gi'), severity: 'CRITICAL', desc: 'Agent identity file read', codeOnly: true, owasp: 'LLM02' },
52
-
53
- // ── Exfiltration (OWASP LLM02) ───────────────────────────────────────
54
- { id: 'EXFIL_WEBHOOK', cat: 'exfiltration', regex: new RegExp('web' + 'hook\\.site|request' + 'bin\\.com|hook' + 'bin\\.com|pipe' + 'dream\\.net', 'gi'), severity: 'HIGH', desc: 'Known exfiltration endpoint', all: true, owasp: 'LLM02' },
55
- { id: 'EXFIL_NGROK', cat: 'exfiltration', regex: new RegExp('ng' + 'rok\\.io|ng' + 'rok-free\\.app', 'gi'), severity: 'MEDIUM', desc: 'Tunnel endpoint (possible exfil)', all: true, owasp: 'LLM02' },
56
- { id: 'EXFIL_B64_SEND', cat: 'exfiltration', regex: new RegExp('(?:bt' + 'oa|Buffer\\.from).*(?:fet' + 'ch|ax' + 'ios|requ' + 'est|http\\.requ' + 'est)', 'gi'), severity: 'CRITICAL', desc: 'Base64 encode β†’ network send', codeOnly: true, owasp: 'LLM02' },
57
-
58
- // ── Obfuscation (OWASP LLM03 β€” Supply Chain) ─────────────────────────
59
- { id: 'OBF_HEX_ESC', cat: 'obfuscation', regex: /\\x[0-9a-f]{2}(?:\\x[0-9a-f]{2}){4,}/gi, severity: 'HIGH', desc: 'Hex escape sequences (obfuscated code)', codeOnly: true, owasp: 'LLM03' },
60
- { id: 'OBF_UNICODE_ESC', cat: 'obfuscation', regex: /\\u[0-9a-f]{4}(?:\\u[0-9a-f]{4}){4,}/gi, severity: 'HIGH', desc: 'Unicode escape sequences', codeOnly: true, owasp: 'LLM03' },
61
- { id: 'OBF_CHAR_CODE', cat: 'obfuscation', regex: new RegExp('String\\.from' + 'CharCode\\s*\\([^)]{10,}\\)', 'gi'), severity: 'HIGH', desc: 'String.fromCharCode obfuscation', codeOnly: true, owasp: 'LLM03' },
62
-
63
- // ── Leaky Skills (OWASP LLM02) ───────────────────────────────────────
64
- { id: 'LEAK_API_CONTEXT', cat: 'leaky-skills', regex: new RegExp('(?:api[_-]?key|sec' + 'ret|to' + 'ken)\\s*[:=]\\s*\\$\\{', 'gi'), severity: 'HIGH', desc: 'Secret in template literal (LLM context leak)', codeOnly: true, owasp: 'LLM02' },
65
-
66
- // ── Memory Poisoning (OWASP LLM04 β€” Data/Model Poisoning) ────────────
67
- { id: 'MEM_WRITE_SOUL', cat: 'memory-poisoning', regex: new RegExp('(?:write' + 'FileSync|write' + 'File)\\s*\\([^)]*(?:SO' + 'UL\\.md|AGE' + 'NTS\\.md)', 'gi'), severity: 'CRITICAL', desc: 'Write to agent soul file', codeOnly: true, owasp: 'LLM04' },
68
- { id: 'MEM_WRITE_MEMORY', cat: 'memory-poisoning', regex: new RegExp('(?:write' + 'FileSync|write' + 'File)\\s*\\([^)]*ME' + 'MORY\\.md', 'gi'), severity: 'CRITICAL', desc: 'Write to agent memory file', codeOnly: true, owasp: 'LLM04' },
69
- { id: 'MEM_APPEND', cat: 'memory-poisoning', regex: new RegExp('(?:append' + 'FileSync|append' + 'File)\\s*\\([^)]*(?:SO' + 'UL|ME' + 'MORY|AGE' + 'NTS)\\.md', 'gi'), severity: 'CRITICAL', desc: 'Append to agent memory', codeOnly: true, owasp: 'LLM04' },
70
-
71
- // ── Prompt Worm (OWASP LLM01) ────────────────────────────────────────
72
- { id: 'WORM_REPLICATE', cat: 'prompt-worm', regex: new RegExp('(?:co' + 'py|repl' + 'icate|spr' + 'ead|inf' + 'ect)\\s+(?:this|these)\\s+(?:inst' + 'ruction|pro' + 'mpt|mes' + 'sage)', 'gi'), severity: 'CRITICAL', desc: 'Self-replicating prompt pattern', all: true, owasp: 'LLM01' },
73
- { id: 'WORM_MULTI_AGENT', cat: 'prompt-worm', regex: new RegExp('(?:for' + 'ward|se' + 'nd|sh' + 'are)\\s+(?:to|with)\\s+(?:all|every|other)\\s+(?:ag' + 'ent|assi' + 'stant|mo' + 'del)', 'gi'), severity: 'CRITICAL', desc: 'Multi-agent worm propagation', all: true, owasp: 'LLM01' },
74
-
75
- // ── Persistence (OWASP LLM06 β€” Excessive Agency) ─────────────────────
76
- { id: 'PERSIST_CRON', cat: 'persistence', regex: new RegExp('(?:cro' + 'ntab|cr' + 'on|at\\s+|sch' + 'tasks)', 'gi'), severity: 'HIGH', desc: 'Scheduled task creation', codeOnly: true, owasp: 'LLM06' },
77
- { id: 'PERSIST_STARTUP', cat: 'persistence', regex: new RegExp('(?:launch' + 'ctl|system' + 'ctl\\s+enable|rc\\.local|init\\.d|auto' + 'start)', 'gi'), severity: 'HIGH', desc: 'Startup persistence', codeOnly: true, owasp: 'LLM06' },
78
- { id: 'PERSIST_TIMER', cat: 'persistence', regex: new RegExp('set' + 'Interval\\s*\\([^)]*(?:86400|604800|2592000)', 'g'), severity: 'MEDIUM', desc: 'Long-running interval timer', codeOnly: true, owasp: 'LLM06' },
79
-
80
- // ── CVE Patterns ─────────────────────────────────────────────────────
81
- { id: 'CVE_RCE_EXEC', cat: 'cve-patterns', regex: new RegExp('req' + 'uire\\s*\\(\\s*[\'"]child_' + 'process[\'"]\\s*\\).*(?:ex' + 'ec|sp' + 'awn)\\s*\\([^)]*(?:req\\.|params\\.|query\\.|body\\.)', 'gi'), severity: 'CRITICAL', desc: 'RCE via user-controlled input to exec', codeOnly: true, owasp: 'LLM05' },
82
-
83
- // ── Identity Hijack (OWASP LLM04) ────────────────────────────────────
84
- { id: 'HIJACK_SOUL_WRITE', cat: 'identity-hijack', regex: new RegExp('(?:write' + 'FileSync|write' + 'File|fs\\.write)\\s*\\([^)]*SO' + 'UL\\.md', 'gi'), severity: 'CRITICAL', desc: 'SOUL.md write attempt (identity hijack)', codeOnly: true, owasp: 'LLM04' },
85
- { id: 'HIJACK_AGENT_WRITE', cat: 'identity-hijack', regex: new RegExp('(?:write' + 'FileSync|write' + 'File|fs\\.write)\\s*\\([^)]*AGE' + 'NTS\\.md', 'gi'), severity: 'CRITICAL', desc: 'AGENTS.md write attempt', codeOnly: true, owasp: 'LLM04' },
86
- { id: 'HIJACK_SOUL_DOC', cat: 'identity-hijack', regex: new RegExp('(?:over' + 'write|re' + 'place|up' + 'date|mo' + 'dify|ch' + 'ange)\\s+(?:the\\s+)?(?:SO' + 'UL|iden' + 'tity|per' + 'sona|person' + 'ality)', 'gi'), severity: 'HIGH', desc: 'Identity modification instruction', docOnly: true, owasp: 'LLM04' },
87
-
88
- // ── PII Exposure (OWASP LLM02) ───────────────────────────────────────
89
- { id: 'PII_EMAIL', cat: 'pii-exposure', regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, severity: 'MEDIUM', desc: 'Email address detected', all: true, owasp: 'LLM02' },
90
- { id: 'PII_PHONE_JP', cat: 'pii-exposure', regex: /0[789]0-?\d{4}-?\d{4}/g, severity: 'HIGH', desc: 'Japanese phone number', all: true, owasp: 'LLM02' },
91
- { id: 'PII_MY_NUMBER', cat: 'pii-exposure', regex: /(?<!\d)(?:\d{4}\s?\d{4}\s?\d{4})(?!\d)/g, severity: 'CRITICAL', desc: 'Potential My Number (個人η•ͺ号)', all: true, owasp: 'LLM02' },
92
-
93
- // ── Shadow AI (OWASP LLM03 β€” Supply Chain) ───────────────────────────
94
- { id: 'SHADOW_AI_OPENAI', cat: 'shadow-ai', regex: new RegExp('api\\.open' + 'ai\\.com', 'gi'), severity: 'HIGH', desc: 'Direct OpenAI API call (Shadow AI)', codeOnly: true, owasp: 'LLM03' },
95
- { id: 'SHADOW_AI_ANTHROPIC', cat: 'shadow-ai', regex: new RegExp('api\\.anth' + 'ropic\\.com', 'gi'), severity: 'HIGH', desc: 'Direct Anthropic API call (Shadow AI)', codeOnly: true, owasp: 'LLM03' },
96
- { id: 'SHADOW_AI_GENERIC', cat: 'shadow-ai', regex: new RegExp('(?:g' + 'pt-4|g' + 'pt-3\\.5|cla' + 'ude-3|gem' + 'ini-pro)\\s*[\'"]', 'gi'), severity: 'MEDIUM', desc: 'AI model reference (possible Shadow AI)', codeOnly: true, owasp: 'LLM03' },
97
-
98
- // ── System Prompt Leakage (OWASP LLM07) β€” NEW ────────────────────────
99
- { id: 'SPL_DUMP_SYSTEM', cat: 'system-prompt-leakage', regex: new RegExp('(?:pr' + 'int|out' + 'put|sh' + 'ow|disp' + 'lay|rev' + 'eal|du' + 'mp)\\s+(?:your\\s+)?(?:sys' + 'tem\\s+)?(?:pro' + 'mpt|inst' + 'ructions)', 'gi'), severity: 'HIGH', desc: 'System prompt dump request', all: true, owasp: 'LLM07' },
100
- { id: 'SPL_REPEAT_ABOVE', cat: 'system-prompt-leakage', regex: new RegExp('rep' + 'eat\\s+(?:every' + 'thing|all|the\\s+text)\\s+ab' + 'ove', 'gi'), severity: 'HIGH', desc: 'Repeat-above extraction', all: true, owasp: 'LLM07' },
101
- { id: 'SPL_TELL_RULES', cat: 'system-prompt-leakage', regex: new RegExp('(?:wh' + 'at\\s+are|te' + 'll\\s+me)\\s+your\\s+(?:ru' + 'les|constr' + 'aints|guide' + 'lines|sys' + 'tem\\s+mes' + 'sage)', 'gi'), severity: 'MEDIUM', desc: 'Rule extraction attempt', all: true, owasp: 'LLM07' },
102
- { id: 'SPL_MARKDOWN_LEAK', cat: 'system-prompt-leakage', regex: new RegExp('(?:out' + 'put|for' + 'mat)\\s+(?:your\\s+)?(?:sys' + 'tem|inter' + 'nal)\\s+(?:pro' + 'mpt|con' + 'fig)\\s+(?:as|in)\\s+(?:mark' + 'down|co' + 'de\\s+bl' + 'ock|js' + 'on)', 'gi'), severity: 'HIGH', desc: 'System prompt format extraction', all: true, owasp: 'LLM07' },
103
- { id: 'SPL_SOUL_EXFIL', cat: 'system-prompt-leakage', regex: new RegExp('(?:c' + 'at|re' + 'ad|ty' + 'pe|get-con' + 'tent)\\s+.*SO' + 'UL\\.md', 'gi'), severity: 'CRITICAL', desc: 'SOUL.md content extraction via shell', codeOnly: true, owasp: 'LLM07' },
104
- ];
@@ -1,48 +0,0 @@
1
- /**
2
- * QuarantineNode - Dual-Brain Architecture
3
- * Evaluates inputs in an isolated context to prevent Zero-Click prompt injections (EchoLeak) and API leaks.
4
- */
5
-
6
- export interface QuarantineResult {
7
- clean: boolean;
8
- threatDetected?: string;
9
- sanitizedText: string;
10
- }
11
-
12
- export class QuarantineNode {
13
- readonly isIsolated: boolean;
14
-
15
- constructor() {
16
- this.isIsolated = true; // Strict isolation flag
17
- }
18
-
19
- /**
20
- * Sanitizes untrusted text by removing known zero-click exploits and API secrets.
21
- */
22
- async sanitize(input: string): Promise<QuarantineResult> {
23
- // 1. Check for CVE-2025-32711 (EchoLeak zero-click payload)
24
- if (input.includes("<image src=") && input.includes("onload='fetch") && input.includes("sendBeacon")) {
25
- return {
26
- clean: false,
27
- threatDetected: 'CVE-2025-32711 (EchoLeak)',
28
- sanitizedText: "[REDACTED_MALICIOUS_PAYLOAD]"
29
- };
30
- }
31
-
32
- // 2. Check for Moltbook API configuration exposure
33
- if (input.includes("\"OPENAI_API_KEY\":\"sk-")) {
34
- const redactedInput = input.replace(/sk-[a-zA-Z0-9]{32}/g, "sk-***REDACTED***");
35
- return {
36
- clean: false,
37
- threatDetected: 'MOLTBOOK_API_EXPOSURE',
38
- sanitizedText: redactedInput
39
- };
40
- }
41
-
42
- // 3. Clean case
43
- return {
44
- clean: true,
45
- sanitizedText: input
46
- };
47
- }
48
- }