@mcpolyglot/security 0.0.3 → 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.
Files changed (43) hide show
  1. package/README.md +40 -3
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/__tests__/audit.test.d.ts +2 -0
  4. package/dist/__tests__/audit.test.d.ts.map +1 -0
  5. package/dist/__tests__/audit.test.js +96 -0
  6. package/dist/__tests__/audit.test.js.map +1 -0
  7. package/dist/__tests__/rate-limiter.test.js +26 -0
  8. package/dist/__tests__/rate-limiter.test.js.map +1 -1
  9. package/dist/__tests__/redactor.test.js +17 -0
  10. package/dist/__tests__/redactor.test.js.map +1 -1
  11. package/dist/__tests__/scope-guard.test.js +5 -6
  12. package/dist/__tests__/scope-guard.test.js.map +1 -1
  13. package/dist/__tests__/wrap.test.js +2 -2
  14. package/dist/__tests__/wrap.test.js.map +1 -1
  15. package/dist/audit.d.ts +27 -1
  16. package/dist/audit.d.ts.map +1 -1
  17. package/dist/audit.js +73 -5
  18. package/dist/audit.js.map +1 -1
  19. package/dist/hooks.d.ts +0 -6
  20. package/dist/hooks.d.ts.map +1 -1
  21. package/dist/hooks.js +4 -50
  22. package/dist/hooks.js.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/rate-limiter.d.ts +2 -1
  28. package/dist/rate-limiter.d.ts.map +1 -1
  29. package/dist/rate-limiter.js +9 -7
  30. package/dist/rate-limiter.js.map +1 -1
  31. package/dist/redactor.d.ts +2 -0
  32. package/dist/redactor.d.ts.map +1 -1
  33. package/dist/redactor.js +4 -0
  34. package/dist/redactor.js.map +1 -1
  35. package/dist/scope-guard.d.ts +1 -3
  36. package/dist/scope-guard.d.ts.map +1 -1
  37. package/dist/scope-guard.js +9 -11
  38. package/dist/scope-guard.js.map +1 -1
  39. package/dist/wrap.d.ts +1 -1
  40. package/dist/wrap.d.ts.map +1 -1
  41. package/dist/wrap.js +4 -8
  42. package/dist/wrap.js.map +1 -1
  43. package/package.json +2 -2
package/README.md CHANGED
@@ -4,13 +4,50 @@ The non-bypassable security middleware for [mcpolyglot](https://github.com/ishay
4
4
 
5
5
  ## What's in here
6
6
 
7
- - **`ScopeGuard`** — refuses tools whose required scopes aren't in the granted set.
7
+ - **`checkScopes`** — refuses tools whose required scopes aren't in the granted set.
8
8
  - **`RateLimiter`** — token bucket per session per tool, plus a max-concurrent gate.
9
9
  - **`Redactor`** — built-in regex set (emails, JWTs, AWS access keys, GitHub tokens, SSNs, credit-card numbers) plus per-table column deny lists.
10
- - **`AuditLogger`** — JSONL appender for `~/.mcpolyglot/audit.log`. Logs argshash + metadata; never raw args or results.
10
+ - **`AuditLogger`**: append-only JSONL audit sink. See [Audit log](#audit-log).
11
+
12
+ ## Audit log
13
+
14
+ Every tool call writes one entry, including calls that were denied or failed:
15
+
16
+ ```json
17
+ {
18
+ "ts": "…",
19
+ "sessionId": "…",
20
+ "agentId": "claude-code",
21
+ "tool": "pg.main.query",
22
+ "decision": "deny",
23
+ "reason": "Table \"secrets\" is not accessible under this policy.",
24
+ "argsHash": "3f9c…",
25
+ "scopes": ["…"],
26
+ "durationMs": 4,
27
+ "rows": 0,
28
+ "error": { "code": "forbidden.policy", "message": "…" }
29
+ }
30
+ ```
31
+
32
+ - `agentId` is the `x-mcpolyglot-agent` request header (HTTP), else the MCP client's `clientInfo.name`.
33
+ - `decision`: `allow`, `deny` (policy, scope, rate limit or timeout), or `error` (anything else).
34
+ - Sinks:
35
+ - console, on by default: stdout, or stderr under stdio (where stdout is the protocol).
36
+ - `audit.path`: an append-only file.
37
+ - `audit.webhookUrl`: a best-effort POST. Failures go to stderr, never fail the call, and never echo the URL.
38
+ - Never logged: raw args (only a 16-char sha256 prefix) and result rows. `reason` and error text are scrubbed of `scheme://user:pass@` credentials and the built-in redaction patterns (email, JWT, keys, …), then truncated to 500 chars.
39
+ - Limits:
40
+ - "Append-only" means the process only opens the file with `O_APPEND`. Tamper-evidence (hash chains, WORM storage) is out of scope; ship to a webhook or your log pipeline for that.
41
+ - Webhook posts still in flight when the process is killed are lost.
42
+
43
+ ```ts
44
+ audit: { console: true, path: '~/.mcpolyglot/audit.log', webhookUrl: '${env:AUDIT_WEBHOOK}' }
45
+ ```
46
+
47
+ Tests: `src/__tests__/audit.test.ts` (sinks, scrubbing) and `packages/core/src/__tests__/audit.test.ts` (decision, agent id, no raw args or rows).
48
+
11
49
  - **`wrapUntrusted` / `enforceSize`** — `<mcpolyglot-data>` prompt-injection wrapper and a hard byte cap on serialized output.
12
50
  - **`defaultSecurityHooks(opts)`** — composes all of the above into the `SecurityHooks` shape `McpolyglotServer` expects.
13
- - **`composeHooks(...hooks)`** — chain custom hooks alongside the defaults.
14
51
 
15
52
  ## Why a separate package
16
53