clawmoat 0.2.1

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 (44) hide show
  1. package/CONTRIBUTING.md +56 -0
  2. package/LICENSE +21 -0
  3. package/README.md +199 -0
  4. package/bin/clawmoat.js +407 -0
  5. package/docs/CNAME +1 -0
  6. package/docs/MIT-RISK-GAP-ANALYSIS.md +146 -0
  7. package/docs/badge/score-A.svg +21 -0
  8. package/docs/badge/score-Aplus.svg +21 -0
  9. package/docs/badge/score-B.svg +21 -0
  10. package/docs/badge/score-C.svg +21 -0
  11. package/docs/badge/score-D.svg +21 -0
  12. package/docs/badge/score-F.svg +21 -0
  13. package/docs/blog/index.html +90 -0
  14. package/docs/blog/owasp-agentic-ai-top10.html +187 -0
  15. package/docs/blog/owasp-agentic-ai-top10.md +185 -0
  16. package/docs/blog/securing-ai-agents.html +194 -0
  17. package/docs/blog/securing-ai-agents.md +152 -0
  18. package/docs/compare.html +312 -0
  19. package/docs/index.html +654 -0
  20. package/docs/integrations/langchain.html +281 -0
  21. package/docs/integrations/openai.html +302 -0
  22. package/docs/integrations/openclaw.html +310 -0
  23. package/docs/robots.txt +3 -0
  24. package/docs/sitemap.xml +28 -0
  25. package/docs/thanks.html +79 -0
  26. package/package.json +35 -0
  27. package/server/Dockerfile +7 -0
  28. package/server/index.js +85 -0
  29. package/server/package.json +12 -0
  30. package/skill/SKILL.md +56 -0
  31. package/src/badge.js +87 -0
  32. package/src/index.js +316 -0
  33. package/src/middleware/openclaw.js +133 -0
  34. package/src/policies/engine.js +180 -0
  35. package/src/scanners/exfiltration.js +97 -0
  36. package/src/scanners/jailbreak.js +81 -0
  37. package/src/scanners/memory-poison.js +68 -0
  38. package/src/scanners/pii.js +128 -0
  39. package/src/scanners/prompt-injection.js +138 -0
  40. package/src/scanners/secrets.js +97 -0
  41. package/src/scanners/supply-chain.js +155 -0
  42. package/src/scanners/urls.js +142 -0
  43. package/src/utils/config.js +137 -0
  44. package/src/utils/logger.js +109 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * ClawMoat Security Event Logger
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const SEVERITY = { low: 0, medium: 1, high: 2, critical: 3 };
9
+ const COLORS = {
10
+ low: '\x1b[36m', // cyan
11
+ medium: '\x1b[33m', // yellow
12
+ high: '\x1b[31m', // red
13
+ critical: '\x1b[35m', // magenta
14
+ reset: '\x1b[0m',
15
+ dim: '\x1b[2m',
16
+ bold: '\x1b[1m',
17
+ };
18
+
19
+ class SecurityLogger {
20
+ constructor(opts = {}) {
21
+ this.events = [];
22
+ this.logFile = opts.logFile || null;
23
+ this.quiet = opts.quiet || false;
24
+ this.minSeverity = SEVERITY[opts.minSeverity || 'low'] || 0;
25
+ this.webhook = opts.webhook || null;
26
+ this.onEvent = opts.onEvent || null;
27
+ }
28
+
29
+ log(event) {
30
+ const entry = {
31
+ timestamp: new Date().toISOString(),
32
+ id: `cm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
33
+ ...event,
34
+ };
35
+
36
+ this.events.push(entry);
37
+
38
+ // Console output
39
+ if (!this.quiet && SEVERITY[event.severity] >= this.minSeverity) {
40
+ const sev = event.severity.toUpperCase().padEnd(8);
41
+ const color = COLORS[event.severity] || '';
42
+ console.error(
43
+ `${COLORS.dim}[ClawMoat]${COLORS.reset} ${color}${sev}${COLORS.reset} ${COLORS.bold}${event.type}${COLORS.reset}: ${event.message}` +
44
+ (event.details ? ` ${COLORS.dim}(${JSON.stringify(event.details)})${COLORS.reset}` : '')
45
+ );
46
+ }
47
+
48
+ // File logging
49
+ if (this.logFile) {
50
+ try {
51
+ const dir = path.dirname(this.logFile);
52
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
53
+ fs.appendFileSync(this.logFile, JSON.stringify(entry) + '\n');
54
+ } catch {}
55
+ }
56
+
57
+ // Webhook
58
+ if (this.webhook && SEVERITY[event.severity] >= SEVERITY.medium) {
59
+ this._sendWebhook(entry).catch(() => {});
60
+ }
61
+
62
+ // Callback
63
+ if (this.onEvent) {
64
+ try { this.onEvent(entry); } catch {}
65
+ }
66
+
67
+ return entry;
68
+ }
69
+
70
+ async _sendWebhook(entry) {
71
+ try {
72
+ await fetch(this.webhook, {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json' },
75
+ body: JSON.stringify(entry),
76
+ });
77
+ } catch {}
78
+ }
79
+
80
+ getEvents(filter = {}) {
81
+ let events = this.events;
82
+ if (filter.severity) {
83
+ const min = SEVERITY[filter.severity] || 0;
84
+ events = events.filter(e => SEVERITY[e.severity] >= min);
85
+ }
86
+ if (filter.type) {
87
+ events = events.filter(e => e.type === filter.type);
88
+ }
89
+ if (filter.since) {
90
+ events = events.filter(e => new Date(e.timestamp) >= new Date(filter.since));
91
+ }
92
+ if (filter.limit) {
93
+ events = events.slice(-filter.limit);
94
+ }
95
+ return events;
96
+ }
97
+
98
+ summary() {
99
+ const counts = { low: 0, medium: 0, high: 0, critical: 0 };
100
+ const types = {};
101
+ for (const e of this.events) {
102
+ counts[e.severity] = (counts[e.severity] || 0) + 1;
103
+ types[e.type] = (types[e.type] || 0) + 1;
104
+ }
105
+ return { total: this.events.length, bySeverity: counts, byType: types };
106
+ }
107
+ }
108
+
109
+ module.exports = { SecurityLogger, SEVERITY };