clawsec 0.0.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.
- package/README.md +560 -0
- package/dist/bin/clawsec.d.ts +7 -0
- package/dist/bin/clawsec.d.ts.map +1 -0
- package/dist/bin/clawsec.js +12 -0
- package/dist/bin/clawsec.js.map +1 -0
- package/dist/src/actions/block.d.ts +22 -0
- package/dist/src/actions/block.d.ts.map +1 -0
- package/dist/src/actions/block.js +83 -0
- package/dist/src/actions/block.js.map +1 -0
- package/dist/src/actions/confirm.d.ts +35 -0
- package/dist/src/actions/confirm.d.ts.map +1 -0
- package/dist/src/actions/confirm.js +156 -0
- package/dist/src/actions/confirm.js.map +1 -0
- package/dist/src/actions/executor.d.ts +64 -0
- package/dist/src/actions/executor.d.ts.map +1 -0
- package/dist/src/actions/executor.js +114 -0
- package/dist/src/actions/executor.js.map +1 -0
- package/dist/src/actions/index.d.ts +13 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +15 -0
- package/dist/src/actions/index.js.map +1 -0
- package/dist/src/actions/log.d.ts +19 -0
- package/dist/src/actions/log.d.ts.map +1 -0
- package/dist/src/actions/log.js +63 -0
- package/dist/src/actions/log.js.map +1 -0
- package/dist/src/actions/types.d.ts +85 -0
- package/dist/src/actions/types.d.ts.map +1 -0
- package/dist/src/actions/types.js +78 -0
- package/dist/src/actions/types.js.map +1 -0
- package/dist/src/actions/warn.d.ts +22 -0
- package/dist/src/actions/warn.d.ts.map +1 -0
- package/dist/src/actions/warn.js +84 -0
- package/dist/src/actions/warn.js.map +1 -0
- package/dist/src/approval/agent-confirm.d.ts +104 -0
- package/dist/src/approval/agent-confirm.d.ts.map +1 -0
- package/dist/src/approval/agent-confirm.js +173 -0
- package/dist/src/approval/agent-confirm.js.map +1 -0
- package/dist/src/approval/index.d.ts +14 -0
- package/dist/src/approval/index.d.ts.map +1 -0
- package/dist/src/approval/index.js +9 -0
- package/dist/src/approval/index.js.map +1 -0
- package/dist/src/approval/native.d.ts +56 -0
- package/dist/src/approval/native.d.ts.map +1 -0
- package/dist/src/approval/native.js +196 -0
- package/dist/src/approval/native.js.map +1 -0
- package/dist/src/approval/store.d.ts +88 -0
- package/dist/src/approval/store.d.ts.map +1 -0
- package/dist/src/approval/store.js +192 -0
- package/dist/src/approval/store.js.map +1 -0
- package/dist/src/approval/types.d.ts +119 -0
- package/dist/src/approval/types.d.ts.map +1 -0
- package/dist/src/approval/types.js +6 -0
- package/dist/src/approval/types.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +170 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +362 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/cli/commands/audit.d.ts +43 -0
- package/dist/src/cli/commands/audit.d.ts.map +1 -0
- package/dist/src/cli/commands/audit.js +115 -0
- package/dist/src/cli/commands/audit.js.map +1 -0
- package/dist/src/cli/commands/feedback.d.ts +27 -0
- package/dist/src/cli/commands/feedback.d.ts.map +1 -0
- package/dist/src/cli/commands/feedback.js +228 -0
- package/dist/src/cli/commands/feedback.js.map +1 -0
- package/dist/src/cli/commands/index.d.ts +11 -0
- package/dist/src/cli/commands/index.d.ts.map +1 -0
- package/dist/src/cli/commands/index.js +13 -0
- package/dist/src/cli/commands/index.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +20 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +122 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/commands/test.d.ts +23 -0
- package/dist/src/cli/commands/test.d.ts.map +1 -0
- package/dist/src/cli/commands/test.js +134 -0
- package/dist/src/cli/commands/test.js.map +1 -0
- package/dist/src/cli/commands/types.d.ts +81 -0
- package/dist/src/cli/commands/types.d.ts.map +1 -0
- package/dist/src/cli/commands/types.js +6 -0
- package/dist/src/cli/commands/types.js.map +1 -0
- package/dist/src/cli/index.d.ts +17 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +267 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/config/defaults.d.ts +20 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +123 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/index.d.ts +8 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +41 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/loader.d.ts +99 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +242 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +627 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +585 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.js +556 -0
- package/dist/src/detectors/destructive/cloud-detector.js.map +1 -0
- package/dist/src/detectors/destructive/code-detector.d.ts +59 -0
- package/dist/src/detectors/destructive/code-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/code-detector.js +558 -0
- package/dist/src/detectors/destructive/code-detector.js.map +1 -0
- package/dist/src/detectors/destructive/index.d.ts +54 -0
- package/dist/src/detectors/destructive/index.d.ts.map +1 -0
- package/dist/src/detectors/destructive/index.js +168 -0
- package/dist/src/detectors/destructive/index.js.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts +43 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.js +302 -0
- package/dist/src/detectors/destructive/shell-detector.js.map +1 -0
- package/dist/src/detectors/destructive/types.d.ts +143 -0
- package/dist/src/detectors/destructive/types.d.ts.map +1 -0
- package/dist/src/detectors/destructive/types.js +6 -0
- package/dist/src/detectors/destructive/types.js.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js +427 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts +47 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.js +429 -0
- package/dist/src/detectors/exfiltration/http-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/index.d.ts +44 -0
- package/dist/src/detectors/exfiltration/index.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/index.js +118 -0
- package/dist/src/detectors/exfiltration/index.js.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts +55 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.js +504 -0
- package/dist/src/detectors/exfiltration/network-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/types.d.ts +139 -0
- package/dist/src/detectors/exfiltration/types.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/types.js +6 -0
- package/dist/src/detectors/exfiltration/types.js.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts +44 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.js +296 -0
- package/dist/src/detectors/purchase/domain-detector.js.map +1 -0
- package/dist/src/detectors/purchase/form-detector.d.ts +27 -0
- package/dist/src/detectors/purchase/form-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/form-detector.js +344 -0
- package/dist/src/detectors/purchase/form-detector.js.map +1 -0
- package/dist/src/detectors/purchase/index.d.ts +65 -0
- package/dist/src/detectors/purchase/index.d.ts.map +1 -0
- package/dist/src/detectors/purchase/index.js +216 -0
- package/dist/src/detectors/purchase/index.js.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts +132 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.js +313 -0
- package/dist/src/detectors/purchase/spend-tracker.js.map +1 -0
- package/dist/src/detectors/purchase/types.d.ts +139 -0
- package/dist/src/detectors/purchase/types.d.ts.map +1 -0
- package/dist/src/detectors/purchase/types.js +6 -0
- package/dist/src/detectors/purchase/types.js.map +1 -0
- package/dist/src/detectors/purchase/url-detector.d.ts +31 -0
- package/dist/src/detectors/purchase/url-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/url-detector.js +292 -0
- package/dist/src/detectors/purchase/url-detector.js.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts +30 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.js +297 -0
- package/dist/src/detectors/secrets/api-key-detector.js.map +1 -0
- package/dist/src/detectors/secrets/index.d.ts +43 -0
- package/dist/src/detectors/secrets/index.d.ts.map +1 -0
- package/dist/src/detectors/secrets/index.js +261 -0
- package/dist/src/detectors/secrets/index.js.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts +54 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.js +286 -0
- package/dist/src/detectors/secrets/pii-detector.js.map +1 -0
- package/dist/src/detectors/secrets/token-detector.d.ts +51 -0
- package/dist/src/detectors/secrets/token-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/token-detector.js +233 -0
- package/dist/src/detectors/secrets/token-detector.js.map +1 -0
- package/dist/src/detectors/secrets/types.d.ts +157 -0
- package/dist/src/detectors/secrets/types.d.ts.map +1 -0
- package/dist/src/detectors/secrets/types.js +6 -0
- package/dist/src/detectors/secrets/types.js.map +1 -0
- package/dist/src/detectors/website/category-detector.d.ts +22 -0
- package/dist/src/detectors/website/category-detector.d.ts.map +1 -0
- package/dist/src/detectors/website/category-detector.js +162 -0
- package/dist/src/detectors/website/category-detector.js.map +1 -0
- package/dist/src/detectors/website/index.d.ts +53 -0
- package/dist/src/detectors/website/index.d.ts.map +1 -0
- package/dist/src/detectors/website/index.js +232 -0
- package/dist/src/detectors/website/index.js.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts +33 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.js +121 -0
- package/dist/src/detectors/website/pattern-matcher.js.map +1 -0
- package/dist/src/detectors/website/types.d.ts +105 -0
- package/dist/src/detectors/website/types.d.ts.map +1 -0
- package/dist/src/detectors/website/types.js +6 -0
- package/dist/src/detectors/website/types.js.map +1 -0
- package/dist/src/engine/analyzer.d.ts +87 -0
- package/dist/src/engine/analyzer.d.ts.map +1 -0
- package/dist/src/engine/analyzer.js +427 -0
- package/dist/src/engine/analyzer.js.map +1 -0
- package/dist/src/engine/cache.d.ts +80 -0
- package/dist/src/engine/cache.d.ts.map +1 -0
- package/dist/src/engine/cache.js +167 -0
- package/dist/src/engine/cache.js.map +1 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/engine/index.js +11 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/llm-client.d.ts +210 -0
- package/dist/src/engine/llm-client.d.ts.map +1 -0
- package/dist/src/engine/llm-client.js +506 -0
- package/dist/src/engine/llm-client.js.map +1 -0
- package/dist/src/engine/types.d.ts +163 -0
- package/dist/src/engine/types.d.ts.map +1 -0
- package/dist/src/engine/types.js +21 -0
- package/dist/src/engine/types.js.map +1 -0
- package/dist/src/feedback/index.d.ts +9 -0
- package/dist/src/feedback/index.d.ts.map +1 -0
- package/dist/src/feedback/index.js +8 -0
- package/dist/src/feedback/index.js.map +1 -0
- package/dist/src/feedback/learner.d.ts +222 -0
- package/dist/src/feedback/learner.d.ts.map +1 -0
- package/dist/src/feedback/learner.js +401 -0
- package/dist/src/feedback/learner.js.map +1 -0
- package/dist/src/feedback/store.d.ts +113 -0
- package/dist/src/feedback/store.d.ts.map +1 -0
- package/dist/src/feedback/store.js +228 -0
- package/dist/src/feedback/store.js.map +1 -0
- package/dist/src/feedback/types.d.ts +126 -0
- package/dist/src/feedback/types.d.ts.map +1 -0
- package/dist/src/feedback/types.js +6 -0
- package/dist/src/feedback/types.js.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts +37 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.js +109 -0
- package/dist/src/hooks/before-agent-start/handler.js.map +1 -0
- package/dist/src/hooks/before-agent-start/index.d.ts +8 -0
- package/dist/src/hooks/before-agent-start/index.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/index.js +7 -0
- package/dist/src/hooks/before-agent-start/index.js.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts +48 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.js +103 -0
- package/dist/src/hooks/before-agent-start/prompts.js.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts +42 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.js +226 -0
- package/dist/src/hooks/before-tool-call/handler.js.map +1 -0
- package/dist/src/hooks/before-tool-call/index.d.ts +7 -0
- package/dist/src/hooks/before-tool-call/index.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/index.js +6 -0
- package/dist/src/hooks/before-tool-call/index.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts +72 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.js +305 -0
- package/dist/src/hooks/tool-result-persist/filter.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts +49 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.js +217 -0
- package/dist/src/hooks/tool-result-persist/handler.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts +11 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.js +11 -0
- package/dist/src/hooks/tool-result-persist/index.js.map +1 -0
- package/dist/src/index.d.ts +256 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +222 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/notifications/discord.d.ts +10 -0
- package/dist/src/notifications/discord.d.ts.map +1 -0
- package/dist/src/notifications/discord.js +218 -0
- package/dist/src/notifications/discord.js.map +1 -0
- package/dist/src/notifications/index.d.ts +37 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/index.js +68 -0
- package/dist/src/notifications/index.js.map +1 -0
- package/dist/src/notifications/slack.d.ts +10 -0
- package/dist/src/notifications/slack.d.ts.map +1 -0
- package/dist/src/notifications/slack.js +218 -0
- package/dist/src/notifications/slack.js.map +1 -0
- package/dist/src/notifications/telegram.d.ts +10 -0
- package/dist/src/notifications/telegram.d.ts.map +1 -0
- package/dist/src/notifications/telegram.js +242 -0
- package/dist/src/notifications/telegram.js.map +1 -0
- package/dist/src/notifications/types.d.ts +119 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/notifications/types.js +6 -0
- package/dist/src/notifications/types.js.map +1 -0
- package/dist/src/proxy/index.d.ts +8 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +9 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/proxy/middleware.d.ts +55 -0
- package/dist/src/proxy/middleware.d.ts.map +1 -0
- package/dist/src/proxy/middleware.js +215 -0
- package/dist/src/proxy/middleware.js.map +1 -0
- package/dist/src/proxy/server.d.ts +57 -0
- package/dist/src/proxy/server.d.ts.map +1 -0
- package/dist/src/proxy/server.js +298 -0
- package/dist/src/proxy/server.js.map +1 -0
- package/dist/src/proxy/types.d.ts +136 -0
- package/dist/src/proxy/types.d.ts.map +1 -0
- package/dist/src/proxy/types.js +6 -0
- package/dist/src/proxy/types.js.map +1 -0
- package/dist/src/sanitization/index.d.ts +10 -0
- package/dist/src/sanitization/index.d.ts.map +1 -0
- package/dist/src/sanitization/index.js +9 -0
- package/dist/src/sanitization/index.js.map +1 -0
- package/dist/src/sanitization/patterns.d.ts +51 -0
- package/dist/src/sanitization/patterns.d.ts.map +1 -0
- package/dist/src/sanitization/patterns.js +266 -0
- package/dist/src/sanitization/patterns.js.map +1 -0
- package/dist/src/sanitization/scanner.d.ts +29 -0
- package/dist/src/sanitization/scanner.d.ts.map +1 -0
- package/dist/src/sanitization/scanner.js +328 -0
- package/dist/src/sanitization/scanner.js.map +1 -0
- package/dist/src/sanitization/types.d.ts +57 -0
- package/dist/src/sanitization/types.d.ts.map +1 -0
- package/dist/src/sanitization/types.js +5 -0
- package/dist/src/sanitization/types.js.map +1 -0
- package/openclaw.plugin.json +114 -0
- package/package.json +63 -0
- package/rules/builtin/README.md +139 -0
- package/rules/builtin/ai-services.yaml +70 -0
- package/rules/builtin/api-keys.yaml +64 -0
- package/rules/builtin/authentication.yaml +56 -0
- package/rules/builtin/aws-security.yaml +57 -0
- package/rules/builtin/azure-security.yaml +58 -0
- package/rules/builtin/cicd-security.yaml +64 -0
- package/rules/builtin/cloud-storage.yaml +64 -0
- package/rules/builtin/container-registry.yaml +55 -0
- package/rules/builtin/crypto-wallets.yaml +71 -0
- package/rules/builtin/database-nosql.yaml +58 -0
- package/rules/builtin/database-sql.yaml +62 -0
- package/rules/builtin/development-env.yaml +67 -0
- package/rules/builtin/docker.yaml +57 -0
- package/rules/builtin/filesystem.yaml +71 -0
- package/rules/builtin/financial-pci.yaml +61 -0
- package/rules/builtin/gcp-security.yaml +57 -0
- package/rules/builtin/git-operations.yaml +68 -0
- package/rules/builtin/healthcare-hipaa.yaml +64 -0
- package/rules/builtin/kubernetes.yaml +60 -0
- package/rules/builtin/messaging-services.yaml +53 -0
- package/rules/builtin/minimal.yaml +47 -0
- package/rules/builtin/mobile-development.yaml +61 -0
- package/rules/builtin/monitoring.yaml +63 -0
- package/rules/builtin/network-security.yaml +57 -0
- package/rules/builtin/package-managers.yaml +74 -0
- package/rules/builtin/payment-processing.yaml +66 -0
- package/rules/builtin/pii-protection.yaml +48 -0
- package/rules/builtin/production-strict.yaml +55 -0
- package/rules/builtin/secrets-management.yaml +63 -0
- package/rules/builtin/serverless.yaml +74 -0
- package/rules/builtin/ssh-security.yaml +66 -0
- package/rules/builtin/terraform.yaml +51 -0
- package/rules/builtin/web-security.yaml +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
# Clawsec
|
|
2
|
+
|
|
3
|
+
> Security plugin for OpenClaw.ai that prevents AI agents from taking dangerous actions.
|
|
4
|
+
|
|
5
|
+
[]()
|
|
6
|
+
[]()
|
|
7
|
+
[]()
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Clawsec is a comprehensive security plugin that protects against:
|
|
12
|
+
|
|
13
|
+
- **Purchase Protection** - Blocks unauthorized purchases with spend limits
|
|
14
|
+
- **Website Control** - Allowlist/blocklist for URL access
|
|
15
|
+
- **Destructive Commands** - Detects dangerous shell, cloud, and code patterns
|
|
16
|
+
- **Secrets/PII Detection** - Finds API keys, tokens, and personal data
|
|
17
|
+
- **Data Exfiltration** - Prevents unauthorized data transfer
|
|
18
|
+
- **Prompt Injection** - Scans tool outputs for injection attempts
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Hybrid Detection** - Fast pattern matching (~5ms) with optional LLM analysis
|
|
23
|
+
- **Multi-Channel Approval** - Native, agent-confirm, and webhook options
|
|
24
|
+
- **Real-time Notifications** - Slack, Discord, and Telegram alerts
|
|
25
|
+
- **30+ Pre-built Rules** - Ready-to-use templates for common scenarios
|
|
26
|
+
- **User Feedback Loop** - Improve detection with false positive/negative reporting
|
|
27
|
+
- **Dual Distribution** - OpenClaw plugin or standalone proxy mode
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Installation
|
|
32
|
+
|
|
33
|
+
#### Via npm (recommended)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install clawsec
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Via OpenClaw CLI
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Install from npm registry
|
|
43
|
+
openclaw plugins install clawsec
|
|
44
|
+
|
|
45
|
+
# Or install locally during development
|
|
46
|
+
openclaw plugins install -l ./
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Verify Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# List installed plugins
|
|
53
|
+
openclaw plugins list
|
|
54
|
+
|
|
55
|
+
# Check plugin info
|
|
56
|
+
openclaw plugins info clawsec
|
|
57
|
+
|
|
58
|
+
# Run plugin diagnostics
|
|
59
|
+
openclaw plugins doctor
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Basic Configuration
|
|
63
|
+
|
|
64
|
+
Create `clawsec.yaml` in your project root:
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
version: "1.0"
|
|
68
|
+
|
|
69
|
+
global:
|
|
70
|
+
enabled: true
|
|
71
|
+
logLevel: info
|
|
72
|
+
|
|
73
|
+
rules:
|
|
74
|
+
purchase:
|
|
75
|
+
enabled: true
|
|
76
|
+
severity: critical
|
|
77
|
+
action: block
|
|
78
|
+
spendLimits:
|
|
79
|
+
perTransaction: 100
|
|
80
|
+
daily: 500
|
|
81
|
+
|
|
82
|
+
destructive:
|
|
83
|
+
enabled: true
|
|
84
|
+
severity: critical
|
|
85
|
+
action: confirm
|
|
86
|
+
|
|
87
|
+
secrets:
|
|
88
|
+
enabled: true
|
|
89
|
+
severity: critical
|
|
90
|
+
action: block
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### OpenClaw Plugin Usage
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import clawsec from 'clawsec';
|
|
97
|
+
|
|
98
|
+
// Register with OpenClaw
|
|
99
|
+
openClaw.registerPlugin(clawsec);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### OpenClaw Configuration
|
|
103
|
+
|
|
104
|
+
Configure Clawsec via OpenClaw's plugin settings:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
# openclaw.config.yaml
|
|
108
|
+
plugins:
|
|
109
|
+
clawsec:
|
|
110
|
+
enabled: true
|
|
111
|
+
configPath: "./clawsec.yaml"
|
|
112
|
+
logLevel: "info"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Or use environment variables:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
export OPENCLAW_PLUGIN_CLAWSEC_ENABLED=true
|
|
119
|
+
export OPENCLAW_PLUGIN_CLAWSEC_CONFIG_PATH="./clawsec.yaml"
|
|
120
|
+
export OPENCLAW_PLUGIN_CLAWSEC_LOG_LEVEL="info"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Standalone Proxy Mode
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Start the proxy server
|
|
127
|
+
npx clawsec serve --port 8080
|
|
128
|
+
|
|
129
|
+
# Configure your agent to use the proxy
|
|
130
|
+
CLAWSEC_PROXY=http://localhost:8080
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
### Global Settings
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
global:
|
|
139
|
+
enabled: true # Enable/disable the plugin
|
|
140
|
+
logLevel: info # debug, info, warn, error
|
|
141
|
+
|
|
142
|
+
llm:
|
|
143
|
+
enabled: true # Enable LLM-based detection
|
|
144
|
+
model: null # Use OpenClaw's configured model
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Purchase Protection
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
rules:
|
|
151
|
+
purchase:
|
|
152
|
+
enabled: true
|
|
153
|
+
severity: critical
|
|
154
|
+
action: block # block, confirm, warn, log
|
|
155
|
+
spendLimits:
|
|
156
|
+
perTransaction: 100 # Maximum per transaction
|
|
157
|
+
daily: 500 # Maximum daily total
|
|
158
|
+
domains:
|
|
159
|
+
mode: blocklist # blocklist or allowlist
|
|
160
|
+
blocklist:
|
|
161
|
+
- "*.amazon.com"
|
|
162
|
+
- "*.stripe.com"
|
|
163
|
+
- "paypal.com"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Website Control
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
rules:
|
|
170
|
+
website:
|
|
171
|
+
enabled: true
|
|
172
|
+
mode: blocklist # blocklist or allowlist
|
|
173
|
+
severity: high
|
|
174
|
+
action: block
|
|
175
|
+
blocklist:
|
|
176
|
+
- "*.malware.com"
|
|
177
|
+
- "phishing-*.com"
|
|
178
|
+
allowlist:
|
|
179
|
+
- "github.com"
|
|
180
|
+
- "stackoverflow.com"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Destructive Commands
|
|
184
|
+
|
|
185
|
+
```yaml
|
|
186
|
+
rules:
|
|
187
|
+
destructive:
|
|
188
|
+
enabled: true
|
|
189
|
+
severity: critical
|
|
190
|
+
action: confirm
|
|
191
|
+
shell:
|
|
192
|
+
enabled: true # rm -rf, mkfs, dd, etc.
|
|
193
|
+
cloud:
|
|
194
|
+
enabled: true # AWS, GCP, Azure delete operations
|
|
195
|
+
code:
|
|
196
|
+
enabled: true # shutil.rmtree, fs.rm, etc.
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Secrets Detection
|
|
200
|
+
|
|
201
|
+
```yaml
|
|
202
|
+
rules:
|
|
203
|
+
secrets:
|
|
204
|
+
enabled: true
|
|
205
|
+
severity: critical
|
|
206
|
+
action: block
|
|
207
|
+
# Detects: API keys, tokens, passwords, PII
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Data Exfiltration
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
rules:
|
|
214
|
+
exfiltration:
|
|
215
|
+
enabled: true
|
|
216
|
+
severity: high
|
|
217
|
+
action: block
|
|
218
|
+
# Detects: curl POST, wget uploads, netcat, etc.
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Output Sanitization
|
|
222
|
+
|
|
223
|
+
```yaml
|
|
224
|
+
rules:
|
|
225
|
+
sanitization:
|
|
226
|
+
enabled: true
|
|
227
|
+
severity: high
|
|
228
|
+
action: block
|
|
229
|
+
minConfidence: 0.5
|
|
230
|
+
redactMatches: false # true to redact instead of block
|
|
231
|
+
categories:
|
|
232
|
+
instructionOverride: true
|
|
233
|
+
systemLeak: true
|
|
234
|
+
jailbreak: true
|
|
235
|
+
encodedPayload: true
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Approval Flow
|
|
239
|
+
|
|
240
|
+
```yaml
|
|
241
|
+
approval:
|
|
242
|
+
native:
|
|
243
|
+
enabled: true
|
|
244
|
+
timeout: 300 # 5 minutes
|
|
245
|
+
|
|
246
|
+
agentConfirm:
|
|
247
|
+
enabled: true
|
|
248
|
+
parameterName: "_clawsec_confirm"
|
|
249
|
+
|
|
250
|
+
webhook:
|
|
251
|
+
enabled: false
|
|
252
|
+
url: "https://api.example.com/approve"
|
|
253
|
+
timeout: 30
|
|
254
|
+
headers:
|
|
255
|
+
Authorization: "Bearer ${WEBHOOK_TOKEN}"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Notifications
|
|
259
|
+
|
|
260
|
+
```yaml
|
|
261
|
+
notifications:
|
|
262
|
+
slack:
|
|
263
|
+
enabled: true
|
|
264
|
+
webhookUrl: "${SLACK_WEBHOOK_URL}"
|
|
265
|
+
channel: "#security-alerts"
|
|
266
|
+
minSeverity: high
|
|
267
|
+
|
|
268
|
+
discord:
|
|
269
|
+
enabled: true
|
|
270
|
+
webhookUrl: "${DISCORD_WEBHOOK_URL}"
|
|
271
|
+
minSeverity: critical
|
|
272
|
+
|
|
273
|
+
telegram:
|
|
274
|
+
enabled: true
|
|
275
|
+
botToken: "${TELEGRAM_BOT_TOKEN}"
|
|
276
|
+
chatId: "${TELEGRAM_CHAT_ID}"
|
|
277
|
+
parseMode: HTML
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Pre-built Rule Templates
|
|
281
|
+
|
|
282
|
+
Use our 30+ built-in templates for common scenarios:
|
|
283
|
+
|
|
284
|
+
| Category | Templates |
|
|
285
|
+
|----------|-----------|
|
|
286
|
+
| Cloud Providers | `aws-security`, `gcp-security`, `azure-security` |
|
|
287
|
+
| Infrastructure | `kubernetes`, `docker`, `terraform`, `serverless` |
|
|
288
|
+
| Development | `git-operations`, `cicd-security`, `package-managers` |
|
|
289
|
+
| Databases | `database-sql`, `database-nosql`, `cloud-storage` |
|
|
290
|
+
| Secrets | `api-keys`, `authentication`, `secrets-management` |
|
|
291
|
+
| Compliance | `pii-protection`, `healthcare-hipaa`, `financial-pci` |
|
|
292
|
+
| Environment | `minimal`, `development-env`, `production-strict` |
|
|
293
|
+
|
|
294
|
+
```yaml
|
|
295
|
+
# Extend from a built-in template
|
|
296
|
+
extends:
|
|
297
|
+
- builtin/aws-security
|
|
298
|
+
- builtin/pii-protection
|
|
299
|
+
|
|
300
|
+
# Override specific settings
|
|
301
|
+
rules:
|
|
302
|
+
purchase:
|
|
303
|
+
spendLimits:
|
|
304
|
+
perTransaction: 200
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## CLI Commands
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Check plugin status
|
|
311
|
+
npx clawsec status
|
|
312
|
+
|
|
313
|
+
# Test configuration
|
|
314
|
+
npx clawsec test
|
|
315
|
+
|
|
316
|
+
# View audit log
|
|
317
|
+
npx clawsec audit --since "1 hour ago"
|
|
318
|
+
|
|
319
|
+
# Report false positive
|
|
320
|
+
npx clawsec feedback --false-positive <event-id>
|
|
321
|
+
|
|
322
|
+
# Report false negative
|
|
323
|
+
npx clawsec feedback --false-negative "description of what was missed"
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## API Reference
|
|
327
|
+
|
|
328
|
+
### Hooks
|
|
329
|
+
|
|
330
|
+
Clawsec registers three hooks with OpenClaw:
|
|
331
|
+
|
|
332
|
+
#### `before-tool-call`
|
|
333
|
+
|
|
334
|
+
Intercepts tool calls before execution:
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
interface BeforeToolCallResult {
|
|
338
|
+
allow: boolean;
|
|
339
|
+
modifiedInput?: Record<string, unknown>;
|
|
340
|
+
blockMessage?: string;
|
|
341
|
+
metadata?: {
|
|
342
|
+
category?: ThreatCategory;
|
|
343
|
+
severity?: Severity;
|
|
344
|
+
rule?: string;
|
|
345
|
+
reason?: string;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### `before-agent-start`
|
|
351
|
+
|
|
352
|
+
Injects security context into system prompts:
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
interface BeforeAgentStartResult {
|
|
356
|
+
systemPromptAddition?: string;
|
|
357
|
+
modifiedConfig?: Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### `tool-result-persist`
|
|
362
|
+
|
|
363
|
+
Filters sensitive data from tool outputs:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
interface ToolResultPersistResult {
|
|
367
|
+
allow: boolean;
|
|
368
|
+
filteredOutput?: unknown;
|
|
369
|
+
redactions?: Array<{
|
|
370
|
+
type: string;
|
|
371
|
+
description: string;
|
|
372
|
+
}>;
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Detectors
|
|
377
|
+
|
|
378
|
+
Access detectors programmatically:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import {
|
|
382
|
+
createPurchaseDetector,
|
|
383
|
+
createWebsiteDetector,
|
|
384
|
+
createDestructiveDetector,
|
|
385
|
+
createSecretsDetector,
|
|
386
|
+
createExfiltrationDetector
|
|
387
|
+
} from 'clawsec/detectors';
|
|
388
|
+
|
|
389
|
+
const detector = createSecretsDetector(config);
|
|
390
|
+
const results = await detector.detectAll({
|
|
391
|
+
toolName: 'Read',
|
|
392
|
+
toolInput: { file_path: '/etc/passwd' },
|
|
393
|
+
toolOutput: fileContents,
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Notifications
|
|
398
|
+
|
|
399
|
+
Send custom notifications:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import { createNotificationManager, createSecurityEvent } from 'clawsec/notifications';
|
|
403
|
+
|
|
404
|
+
const manager = createNotificationManager({
|
|
405
|
+
slack: { enabled: true, webhookUrl: '...' },
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const event = createSecurityEvent({
|
|
409
|
+
category: 'custom',
|
|
410
|
+
severity: 'high',
|
|
411
|
+
toolName: 'CustomTool',
|
|
412
|
+
reason: 'Custom security event',
|
|
413
|
+
action: 'blocked',
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
await manager.notify(event);
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Detection Patterns
|
|
420
|
+
|
|
421
|
+
### Destructive Commands
|
|
422
|
+
|
|
423
|
+
```
|
|
424
|
+
Shell: rm -rf, mkfs, dd of=/dev/, DROP DATABASE, TRUNCATE
|
|
425
|
+
Cloud: aws ec2 terminate, gcloud delete, kubectl delete ns
|
|
426
|
+
Git: push --force, reset --hard, clean -f
|
|
427
|
+
Code: shutil.rmtree(), fs.rm(recursive), os.RemoveAll()
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Secrets Detection
|
|
431
|
+
|
|
432
|
+
```
|
|
433
|
+
API Keys: sk-..., AKIA..., gho_..., xoxb-...
|
|
434
|
+
Tokens: Bearer ..., eyJ... (JWT), session_...
|
|
435
|
+
Credentials: password=, secret=, api_key=
|
|
436
|
+
PII: SSN (xxx-xx-xxxx), Credit Cards (Luhn validation)
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Prompt Injection
|
|
440
|
+
|
|
441
|
+
```
|
|
442
|
+
Override: "ignore previous", "new instructions", "system:"
|
|
443
|
+
Leakage: "your system prompt", "initial instructions"
|
|
444
|
+
Jailbreak: "DAN mode", "developer mode", "pretend you are"
|
|
445
|
+
Encoded: Base64, hex, unicode escape sequences
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Approval Flow
|
|
449
|
+
|
|
450
|
+
```
|
|
451
|
+
Detection ─┬─► block ──────────► REJECT (no approval possible)
|
|
452
|
+
│
|
|
453
|
+
├─► confirm ────────► 3 approval paths:
|
|
454
|
+
│ ├── Native: /approve <id>
|
|
455
|
+
│ ├── Agent-confirm: retry with _clawsec_confirm
|
|
456
|
+
│ └── Webhook: external system
|
|
457
|
+
│
|
|
458
|
+
├─► warn ───────────► ALLOW (log warning)
|
|
459
|
+
│
|
|
460
|
+
└─► log ────────────► ALLOW (silent audit)
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Architecture
|
|
464
|
+
|
|
465
|
+
```
|
|
466
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
467
|
+
│ CLAWSEC PLUGIN │
|
|
468
|
+
├─────────────────────────────────────────────────────────────┤
|
|
469
|
+
│ │
|
|
470
|
+
│ Tool Call ──► Pattern Matching (≤5ms) ──┬─► BLOCK/ALLOW │
|
|
471
|
+
│ │ │
|
|
472
|
+
│ ambiguous ───────────┘ │
|
|
473
|
+
│ │ │
|
|
474
|
+
│ ▼ │
|
|
475
|
+
│ LLM Analysis (~500ms) ──► BLOCK/CONFIRM │
|
|
476
|
+
│ │
|
|
477
|
+
└─────────────────────────────────────────────────────────────┘
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
## Development
|
|
481
|
+
|
|
482
|
+
### Building
|
|
483
|
+
|
|
484
|
+
```bash
|
|
485
|
+
npm install
|
|
486
|
+
npm run build
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Testing
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
npm test # Run all tests
|
|
493
|
+
npm run test:watch # Watch mode
|
|
494
|
+
npm run test:coverage # Coverage report
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Project Structure
|
|
498
|
+
|
|
499
|
+
```
|
|
500
|
+
clawsec/
|
|
501
|
+
├── src/
|
|
502
|
+
│ ├── index.ts # Plugin entry point
|
|
503
|
+
│ ├── config/ # Configuration handling
|
|
504
|
+
│ ├── detectors/ # Detection modules
|
|
505
|
+
│ │ ├── purchase/ # Domain + intent detection
|
|
506
|
+
│ │ ├── website/ # URL allowlist/blocklist
|
|
507
|
+
│ │ ├── destructive/ # Shell, code, cloud patterns
|
|
508
|
+
│ │ ├── secrets/ # API keys, tokens, PII
|
|
509
|
+
│ │ └── exfiltration/ # Data exfiltration detection
|
|
510
|
+
│ ├── engine/ # Hybrid detection engine
|
|
511
|
+
│ ├── actions/ # Block, confirm, warn, log
|
|
512
|
+
│ ├── approval/ # Approval flow handlers
|
|
513
|
+
│ ├── hooks/ # OpenClaw hook handlers
|
|
514
|
+
│ ├── sanitization/ # Output sanitization
|
|
515
|
+
│ ├── notifications/ # Slack, Discord, Telegram
|
|
516
|
+
│ ├── feedback/ # User feedback system
|
|
517
|
+
│ ├── proxy/ # Standalone proxy mode
|
|
518
|
+
│ └── cli/ # CLI commands
|
|
519
|
+
├── rules/builtin/ # Pre-built rule templates
|
|
520
|
+
└── tests/ # Test files
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
## Troubleshooting
|
|
524
|
+
|
|
525
|
+
### Common Issues
|
|
526
|
+
|
|
527
|
+
**Plugin not blocking expected threats:**
|
|
528
|
+
- Check `enabled: true` in config
|
|
529
|
+
- Verify severity threshold matches
|
|
530
|
+
- Review audit log with `npx clawsec audit`
|
|
531
|
+
|
|
532
|
+
**False positives:**
|
|
533
|
+
- Report with `npx clawsec feedback --false-positive <id>`
|
|
534
|
+
- Adjust `minConfidence` in config
|
|
535
|
+
- Use allowlist for known-safe patterns
|
|
536
|
+
|
|
537
|
+
**Notifications not sending:**
|
|
538
|
+
- Verify webhook URLs are correct
|
|
539
|
+
- Check `minSeverity` filter
|
|
540
|
+
- Test with `npx clawsec test notifications`
|
|
541
|
+
|
|
542
|
+
**Performance issues:**
|
|
543
|
+
- Disable LLM analysis if not needed
|
|
544
|
+
- Use `log` action for low-severity rules
|
|
545
|
+
- Increase `minConfidence` threshold
|
|
546
|
+
|
|
547
|
+
## Contributing
|
|
548
|
+
|
|
549
|
+
1. Fork the repository
|
|
550
|
+
2. Create a feature branch
|
|
551
|
+
3. Write tests for new functionality
|
|
552
|
+
4. Submit a pull request
|
|
553
|
+
|
|
554
|
+
## License
|
|
555
|
+
|
|
556
|
+
MIT
|
|
557
|
+
|
|
558
|
+
## Credits
|
|
559
|
+
|
|
560
|
+
Built by the Clawsec team. Inspired by ClawGuardian and the need for comprehensive AI agent security.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clawsec.d.ts","sourceRoot":"","sources":["../../bin/clawsec.ts"],"names":[],"mappings":";AACA;;;GAGG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Clawsec CLI Executable
|
|
4
|
+
* Entry point for the clawsec command line tool
|
|
5
|
+
*/
|
|
6
|
+
import { main } from '../src/cli/index.js';
|
|
7
|
+
// Run the CLI
|
|
8
|
+
main().catch((error) => {
|
|
9
|
+
console.error('Fatal error:', error);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=clawsec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clawsec.js","sourceRoot":"","sources":["../../bin/clawsec.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,cAAc;AACd,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block Action Handler
|
|
3
|
+
* Handles blocking tool calls when critical threats are detected
|
|
4
|
+
*/
|
|
5
|
+
import type { ActionContext, ActionHandler, ActionResult, ActionLogger } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate a clear message explaining why the action was blocked
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateBlockMessage(context: ActionContext): string;
|
|
10
|
+
/**
|
|
11
|
+
* Block action handler implementation
|
|
12
|
+
*/
|
|
13
|
+
export declare class BlockHandler implements ActionHandler {
|
|
14
|
+
private logger;
|
|
15
|
+
constructor(logger?: ActionLogger);
|
|
16
|
+
execute(context: ActionContext): Promise<ActionResult>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a block action handler with the given logger
|
|
20
|
+
*/
|
|
21
|
+
export declare function createBlockHandler(logger?: ActionLogger): BlockHandler;
|
|
22
|
+
//# sourceMappingURL=block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/actions/block.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAwB3F;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CA2BnE;AAED;;GAEG;AACH,qBAAa,YAAa,YAAW,aAAa;IAChD,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,GAAE,YAAyB;IAIvC,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CAmB7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,CAEtE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block Action Handler
|
|
3
|
+
* Handles blocking tool calls when critical threats are detected
|
|
4
|
+
*/
|
|
5
|
+
import { noOpLogger } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Format a severity level for display
|
|
8
|
+
*/
|
|
9
|
+
function formatSeverity(severity) {
|
|
10
|
+
return severity.toUpperCase();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Format a threat category for display
|
|
14
|
+
*/
|
|
15
|
+
function formatCategory(category) {
|
|
16
|
+
const categoryNames = {
|
|
17
|
+
purchase: 'Purchase/Payment',
|
|
18
|
+
website: 'Malicious Website',
|
|
19
|
+
destructive: 'Destructive Command',
|
|
20
|
+
secrets: 'Secrets/PII Exposure',
|
|
21
|
+
exfiltration: 'Data Exfiltration',
|
|
22
|
+
};
|
|
23
|
+
return categoryNames[category] || category;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generate a clear message explaining why the action was blocked
|
|
27
|
+
*/
|
|
28
|
+
export function generateBlockMessage(context) {
|
|
29
|
+
const { analysis, toolCall } = context;
|
|
30
|
+
const { primaryDetection, detections } = analysis;
|
|
31
|
+
if (!primaryDetection) {
|
|
32
|
+
return `Action blocked: ${toolCall.toolName} was blocked by security policy.`;
|
|
33
|
+
}
|
|
34
|
+
const category = formatCategory(primaryDetection.category);
|
|
35
|
+
const severity = formatSeverity(primaryDetection.severity);
|
|
36
|
+
const reason = primaryDetection.reason;
|
|
37
|
+
let message = `[${severity}] ${category} detected - Action blocked\n`;
|
|
38
|
+
message += `Tool: ${toolCall.toolName}\n`;
|
|
39
|
+
message += `Reason: ${reason}`;
|
|
40
|
+
// Include additional detections if any
|
|
41
|
+
if (detections.length > 1) {
|
|
42
|
+
message += `\n\nAdditional detections (${detections.length - 1}):`;
|
|
43
|
+
for (const detection of detections) {
|
|
44
|
+
if (detection !== primaryDetection) {
|
|
45
|
+
message += `\n- ${formatCategory(detection.category)}: ${detection.reason}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return message;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Block action handler implementation
|
|
53
|
+
*/
|
|
54
|
+
export class BlockHandler {
|
|
55
|
+
logger;
|
|
56
|
+
constructor(logger = noOpLogger) {
|
|
57
|
+
this.logger = logger;
|
|
58
|
+
}
|
|
59
|
+
async execute(context) {
|
|
60
|
+
const { analysis, toolCall } = context;
|
|
61
|
+
const message = generateBlockMessage(context);
|
|
62
|
+
// Log the block event
|
|
63
|
+
this.logger.warn('Action blocked', {
|
|
64
|
+
toolName: toolCall.toolName,
|
|
65
|
+
category: analysis.primaryDetection?.category,
|
|
66
|
+
severity: analysis.primaryDetection?.severity,
|
|
67
|
+
reason: analysis.primaryDetection?.reason,
|
|
68
|
+
detectionCount: analysis.detections.length,
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
allowed: false,
|
|
72
|
+
message,
|
|
73
|
+
logged: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a block action handler with the given logger
|
|
79
|
+
*/
|
|
80
|
+
export function createBlockHandler(logger) {
|
|
81
|
+
return new BlockHandler(logger);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../../src/actions/block.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,aAAa,GAA2B;QAC5C,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,mBAAmB;QAC5B,WAAW,EAAE,qBAAqB;QAClC,OAAO,EAAE,sBAAsB;QAC/B,YAAY,EAAE,mBAAmB;KAClC,CAAC;IACF,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAsB;IACzD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IAElD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,mBAAmB,QAAQ,CAAC,QAAQ,kCAAkC,CAAC;IAChF,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,cAAc,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAEvC,IAAI,OAAO,GAAG,IAAI,QAAQ,KAAK,QAAQ,8BAA8B,CAAC;IACtE,OAAO,IAAI,SAAS,QAAQ,CAAC,QAAQ,IAAI,CAAC;IAC1C,OAAO,IAAI,WAAW,MAAM,EAAE,CAAC;IAE/B,uCAAuC;IACvC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,8BAA8B,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC;QACnE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,SAAS,KAAK,gBAAgB,EAAE,CAAC;gBACnC,OAAO,IAAI,OAAO,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;YAC9E,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,MAAM,CAAe;IAE7B,YAAY,SAAuB,UAAU;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAsB;QAClC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QACvC,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE9C,sBAAsB;QACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE;YACjC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,EAAE,QAAQ;YAC7C,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,EAAE,QAAQ;YAC7C,MAAM,EAAE,QAAQ,CAAC,gBAAgB,EAAE,MAAM;YACzC,cAAc,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;SAC3C,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO;YACP,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAqB;IACtD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|