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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Destructive Detector
|
|
3
|
+
* Main detector that combines shell, cloud, git, and code pattern detection
|
|
4
|
+
*/
|
|
5
|
+
import { createShellDetector } from './shell-detector.js';
|
|
6
|
+
import { createCloudDetector } from './cloud-detector.js';
|
|
7
|
+
import { createCodeDetector } from './code-detector.js';
|
|
8
|
+
// Re-export types
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
// Re-export sub-detectors
|
|
11
|
+
export { ShellDetector, createShellDetector } from './shell-detector.js';
|
|
12
|
+
export { CloudDetector, createCloudDetector } from './cloud-detector.js';
|
|
13
|
+
export { CodeDetector, createCodeDetector } from './code-detector.js';
|
|
14
|
+
// Re-export utility functions
|
|
15
|
+
export { isDangerousPath, matchRmCommand, matchSqlCommand, matchSystemCommand, matchShellCommand, } from './shell-detector.js';
|
|
16
|
+
export { matchAwsCommand, matchGcpCommand, matchAzureCommand, matchKubernetesCommand, matchTerraformCommand, matchGitCommand, matchCloudCommand, } from './cloud-detector.js';
|
|
17
|
+
export { matchPythonCode, matchNodeCode, matchGoCode, matchRustCode, matchRubyCode, matchJavaCode, matchCSharpCode, matchPhpCode, matchCodePattern, } from './code-detector.js';
|
|
18
|
+
/**
|
|
19
|
+
* No detection result (used when disabled or no match)
|
|
20
|
+
*/
|
|
21
|
+
function noDetection(severity) {
|
|
22
|
+
return {
|
|
23
|
+
detected: false,
|
|
24
|
+
category: 'destructive',
|
|
25
|
+
severity,
|
|
26
|
+
confidence: 0,
|
|
27
|
+
reason: 'No destructive operation detected',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Combine multiple detection results, taking the highest confidence
|
|
32
|
+
*/
|
|
33
|
+
function combineResults(results, severity) {
|
|
34
|
+
const validResults = results.filter((r) => r !== null && r.detected);
|
|
35
|
+
if (validResults.length === 0) {
|
|
36
|
+
return noDetection(severity);
|
|
37
|
+
}
|
|
38
|
+
// Sort by confidence (highest first)
|
|
39
|
+
validResults.sort((a, b) => b.confidence - a.confidence);
|
|
40
|
+
// Take the highest confidence result as primary
|
|
41
|
+
const primary = validResults[0];
|
|
42
|
+
// Build combined reason if multiple detections
|
|
43
|
+
let reason = primary.reason;
|
|
44
|
+
if (validResults.length > 1) {
|
|
45
|
+
const additionalReasons = validResults.slice(1).map((r) => r.reason);
|
|
46
|
+
reason = `${primary.reason}. Additional signals: ${additionalReasons.join('; ')}`;
|
|
47
|
+
}
|
|
48
|
+
// Boost confidence if multiple detectors triggered
|
|
49
|
+
let confidence = primary.confidence;
|
|
50
|
+
if (validResults.length >= 2) {
|
|
51
|
+
// Boost confidence but cap at 0.99
|
|
52
|
+
confidence = Math.min(0.99, confidence + 0.05 * (validResults.length - 1));
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
detected: true,
|
|
56
|
+
category: 'destructive',
|
|
57
|
+
severity,
|
|
58
|
+
confidence,
|
|
59
|
+
reason,
|
|
60
|
+
metadata: primary.metadata,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Main destructive detector implementation
|
|
65
|
+
*/
|
|
66
|
+
export class DestructiveDetectorImpl {
|
|
67
|
+
config;
|
|
68
|
+
shellDetector;
|
|
69
|
+
cloudDetector;
|
|
70
|
+
codeDetector;
|
|
71
|
+
constructor(config) {
|
|
72
|
+
this.config = config;
|
|
73
|
+
// Initialize sub-detectors based on config
|
|
74
|
+
this.shellDetector =
|
|
75
|
+
config.shell?.enabled !== false
|
|
76
|
+
? createShellDetector(config.severity)
|
|
77
|
+
: null;
|
|
78
|
+
this.cloudDetector =
|
|
79
|
+
config.cloud?.enabled !== false
|
|
80
|
+
? createCloudDetector(config.severity)
|
|
81
|
+
: null;
|
|
82
|
+
this.codeDetector =
|
|
83
|
+
config.code?.enabled !== false
|
|
84
|
+
? createCodeDetector(config.severity)
|
|
85
|
+
: null;
|
|
86
|
+
}
|
|
87
|
+
async detect(context) {
|
|
88
|
+
// Check if detector is enabled
|
|
89
|
+
if (!this.config.enabled) {
|
|
90
|
+
return noDetection(this.config.severity);
|
|
91
|
+
}
|
|
92
|
+
const results = [];
|
|
93
|
+
// Run shell detector
|
|
94
|
+
if (this.shellDetector) {
|
|
95
|
+
results.push(this.shellDetector.detect(context));
|
|
96
|
+
}
|
|
97
|
+
// Run cloud detector (includes git commands)
|
|
98
|
+
if (this.cloudDetector) {
|
|
99
|
+
results.push(this.cloudDetector.detect(context));
|
|
100
|
+
}
|
|
101
|
+
// Run code detector
|
|
102
|
+
if (this.codeDetector) {
|
|
103
|
+
results.push(this.codeDetector.detect(context));
|
|
104
|
+
}
|
|
105
|
+
// Combine results
|
|
106
|
+
return combineResults(results, this.config.severity);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the configured action for detected destructive operations
|
|
110
|
+
*/
|
|
111
|
+
getAction() {
|
|
112
|
+
return this.config.action;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if the detector is enabled
|
|
116
|
+
*/
|
|
117
|
+
isEnabled() {
|
|
118
|
+
return this.config.enabled;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if shell detection is enabled
|
|
122
|
+
*/
|
|
123
|
+
isShellEnabled() {
|
|
124
|
+
return this.config.shell?.enabled !== false;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check if cloud detection is enabled
|
|
128
|
+
*/
|
|
129
|
+
isCloudEnabled() {
|
|
130
|
+
return this.config.cloud?.enabled !== false;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if code detection is enabled
|
|
134
|
+
*/
|
|
135
|
+
isCodeEnabled() {
|
|
136
|
+
return this.config.code?.enabled !== false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a destructive detector from DestructiveRule configuration
|
|
141
|
+
*/
|
|
142
|
+
export function createDestructiveDetector(rule) {
|
|
143
|
+
const config = {
|
|
144
|
+
enabled: rule.enabled,
|
|
145
|
+
severity: rule.severity,
|
|
146
|
+
action: rule.action,
|
|
147
|
+
shell: rule.shell,
|
|
148
|
+
cloud: rule.cloud,
|
|
149
|
+
code: rule.code,
|
|
150
|
+
};
|
|
151
|
+
return new DestructiveDetectorImpl(config);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a destructive detector with default configuration
|
|
155
|
+
*/
|
|
156
|
+
export function createDefaultDestructiveDetector() {
|
|
157
|
+
return new DestructiveDetectorImpl({
|
|
158
|
+
enabled: true,
|
|
159
|
+
severity: 'critical',
|
|
160
|
+
action: 'confirm',
|
|
161
|
+
shell: { enabled: true },
|
|
162
|
+
cloud: { enabled: true },
|
|
163
|
+
code: { enabled: true },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// Default export
|
|
167
|
+
export default DestructiveDetectorImpl;
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/detectors/destructive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAiB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAiB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAgB,kB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43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Detector
|
|
3
|
+
* Detects dangerous shell commands including file deletion, SQL operations, and system commands
|
|
4
|
+
*/
|
|
5
|
+
import type { ShellMatchResult, DetectionContext, DestructiveDetectionResult, SubDetector } from './types.js';
|
|
6
|
+
import type { Severity } from '../../config/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Check if a path is dangerous for recursive deletion
|
|
9
|
+
*/
|
|
10
|
+
export declare function isDangerousPath(path: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Match rm commands for dangerous operations
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchRmCommand(command: string): ShellMatchResult;
|
|
15
|
+
/**
|
|
16
|
+
* Match SQL destructive operations
|
|
17
|
+
*/
|
|
18
|
+
export declare function matchSqlCommand(text: string): ShellMatchResult;
|
|
19
|
+
/**
|
|
20
|
+
* Match system destructive commands
|
|
21
|
+
*/
|
|
22
|
+
export declare function matchSystemCommand(command: string): ShellMatchResult;
|
|
23
|
+
/**
|
|
24
|
+
* Comprehensive shell command matching
|
|
25
|
+
*/
|
|
26
|
+
export declare function matchShellCommand(command: string): ShellMatchResult;
|
|
27
|
+
/**
|
|
28
|
+
* Shell detector class
|
|
29
|
+
*/
|
|
30
|
+
export declare class ShellDetector implements SubDetector {
|
|
31
|
+
private severity;
|
|
32
|
+
constructor(severity?: Severity);
|
|
33
|
+
/**
|
|
34
|
+
* Extract command from tool context
|
|
35
|
+
*/
|
|
36
|
+
private extractCommand;
|
|
37
|
+
detect(context: DetectionContext): DestructiveDetectionResult | null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a shell detector with the given severity
|
|
41
|
+
*/
|
|
42
|
+
export declare function createShellDetector(severity?: Severity): ShellDetector;
|
|
43
|
+
//# sourceMappingURL=shell-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-detector.d.ts","sourceRoot":"","sources":["../../../../src/detectors/destructive/shell-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AA6EtD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA+BrD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAyDhE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAgB9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAgBpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAoBnE;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,QAAQ,CAAW;gBAEf,QAAQ,GAAE,QAAqB;IAI3C;;OAEG;IACH,OAAO,CAAC,cAAc;IAuDtB,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,0BAA0B,GAAG,IAAI;CA0BrE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,QAAqB,GAAG,aAAa,CAElF"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Detector
|
|
3
|
+
* Detects dangerous shell commands including file deletion, SQL operations, and system commands
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Dangerous paths that should never be deleted recursively
|
|
7
|
+
*/
|
|
8
|
+
const DANGEROUS_PATHS = [
|
|
9
|
+
'/',
|
|
10
|
+
'/home',
|
|
11
|
+
'/etc',
|
|
12
|
+
'/var',
|
|
13
|
+
'/usr',
|
|
14
|
+
'/bin',
|
|
15
|
+
'/sbin',
|
|
16
|
+
'/lib',
|
|
17
|
+
'/lib64',
|
|
18
|
+
'/boot',
|
|
19
|
+
'/root',
|
|
20
|
+
'/sys',
|
|
21
|
+
'/proc',
|
|
22
|
+
'/dev',
|
|
23
|
+
'~',
|
|
24
|
+
'$HOME',
|
|
25
|
+
'%USERPROFILE%',
|
|
26
|
+
'C:\\',
|
|
27
|
+
'C:\\Windows',
|
|
28
|
+
'C:\\Program Files',
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Patterns for rm commands with recursive/force flags
|
|
32
|
+
*/
|
|
33
|
+
const RM_DANGEROUS_PATTERNS = [
|
|
34
|
+
// rm with -rf, -r -f, -fr flags
|
|
35
|
+
/\brm\s+(?:-[rRfvP]+\s+)*(?:-[rR][^\s]*|-[^\s]*[rR])\s*(?:-[^\s]+\s+)*(\S+)/i,
|
|
36
|
+
// rm -r or rm -R alone
|
|
37
|
+
/\brm\s+(?:-[^\s]+\s+)*-[rR]\s+(\S+)/i,
|
|
38
|
+
// rm -f (force) which can be dangerous
|
|
39
|
+
/\brm\s+(?:-[^\s]+\s+)*-[fF]\s+(\S+)/i,
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* SQL destructive operations
|
|
43
|
+
*/
|
|
44
|
+
const SQL_PATTERNS = [
|
|
45
|
+
// DROP DATABASE
|
|
46
|
+
{ pattern: /\bDROP\s+DATABASE\s+(?:IF\s+EXISTS\s+)?[`"']?(\w+)[`"']?/i, operation: 'DROP DATABASE', critical: true },
|
|
47
|
+
// DROP TABLE
|
|
48
|
+
{ pattern: /\bDROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?[`"']?(\w+)[`"']?/i, operation: 'DROP TABLE', critical: true },
|
|
49
|
+
// TRUNCATE TABLE
|
|
50
|
+
{ pattern: /\bTRUNCATE\s+(?:TABLE\s+)?[`"']?(\w+)[`"']?/i, operation: 'TRUNCATE TABLE', critical: true },
|
|
51
|
+
// DELETE FROM without WHERE (dangerous)
|
|
52
|
+
{ pattern: /\bDELETE\s+FROM\s+[`"']?(\w+)[`"']?\s*(?:;|$)/i, operation: 'DELETE FROM (no WHERE)', critical: true },
|
|
53
|
+
// DROP SCHEMA
|
|
54
|
+
{ pattern: /\bDROP\s+SCHEMA\s+(?:IF\s+EXISTS\s+)?[`"']?(\w+)[`"']?/i, operation: 'DROP SCHEMA', critical: true },
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* System destructive commands
|
|
58
|
+
*/
|
|
59
|
+
const SYSTEM_DESTRUCTIVE_PATTERNS = [
|
|
60
|
+
// mkfs - format filesystem
|
|
61
|
+
{ pattern: /\bmkfs(?:\.\w+)?\s+(\S+)/i, operation: 'mkfs', description: 'Format filesystem' },
|
|
62
|
+
// dd writing to block device
|
|
63
|
+
{ pattern: /\bdd\s+.*\bof=\s*\/dev\/(\S+)/i, operation: 'dd to device', description: 'Write to block device' },
|
|
64
|
+
// chmod 777 (world-writable) on dangerous paths
|
|
65
|
+
{ pattern: /\bchmod\s+(?:-[rR]\s+)?777\s+(\S+)/i, operation: 'chmod 777', description: 'Set world-writable permissions' },
|
|
66
|
+
// Fork bomb patterns
|
|
67
|
+
{ pattern: /:\(\)\s*\{\s*:\|:&\s*\}\s*;?\s*:/i, operation: 'fork bomb', description: 'Fork bomb detected' },
|
|
68
|
+
{ pattern: /\bforkbomb\b/i, operation: 'fork bomb', description: 'Fork bomb detected' },
|
|
69
|
+
// shred - secure delete
|
|
70
|
+
{ pattern: /\bshred\s+(?:-[^\s]+\s+)*(\S+)/i, operation: 'shred', description: 'Secure file deletion' },
|
|
71
|
+
// Overwrite with /dev/null or /dev/zero
|
|
72
|
+
{ pattern: /\bcat\s+\/dev\/(?:null|zero)\s*>\s*(\S+)/i, operation: 'overwrite file', description: 'Overwrite file with null/zero' },
|
|
73
|
+
// wipefs
|
|
74
|
+
{ pattern: /\bwipefs\s+(?:-[^\s]+\s+)*(\S+)/i, operation: 'wipefs', description: 'Wipe filesystem signatures' },
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Check if a path is dangerous for recursive deletion
|
|
78
|
+
*/
|
|
79
|
+
export function isDangerousPath(path) {
|
|
80
|
+
// Normalize path - keep the leading slash, remove trailing slashes
|
|
81
|
+
const trimmed = path.trim();
|
|
82
|
+
// Handle root path explicitly
|
|
83
|
+
if (trimmed === '/' || trimmed === '//' || trimmed === '///') {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
// Remove trailing slashes for comparison (but not leading)
|
|
87
|
+
const normalizedPath = trimmed.replace(/\/+$/, '').toLowerCase();
|
|
88
|
+
// Check exact matches
|
|
89
|
+
for (const dangerous of DANGEROUS_PATHS) {
|
|
90
|
+
const dangerousLower = dangerous.toLowerCase().replace(/\/+$/, '');
|
|
91
|
+
if (normalizedPath === dangerousLower) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Check if path is just a wildcard or root-level wildcard
|
|
96
|
+
if (normalizedPath === '*' || normalizedPath === '/*' || normalizedPath === '.*') {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// Check for home directory patterns
|
|
100
|
+
if (/^~\/?$/.test(trimmed) || /^~\/?\*$/.test(trimmed) || /^\$HOME\/?$/i.test(trimmed) || /^\$HOME\/?\*$/i.test(trimmed)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Match rm commands for dangerous operations
|
|
107
|
+
*/
|
|
108
|
+
export function matchRmCommand(command) {
|
|
109
|
+
const commandLower = command.toLowerCase();
|
|
110
|
+
// Quick check for rm command
|
|
111
|
+
if (!commandLower.includes('rm ') && !commandLower.includes('rm\t')) {
|
|
112
|
+
return { matched: false, confidence: 0 };
|
|
113
|
+
}
|
|
114
|
+
// Check for recursive/force flags
|
|
115
|
+
const hasRecursive = /-[rR]/.test(command) || /-[^\s]*[rR]/.test(command);
|
|
116
|
+
const hasForce = /-[fF]/.test(command) || /-[^\s]*[fF]/.test(command);
|
|
117
|
+
// Extract the target path(s)
|
|
118
|
+
for (const pattern of RM_DANGEROUS_PATTERNS) {
|
|
119
|
+
const match = command.match(pattern);
|
|
120
|
+
if (match) {
|
|
121
|
+
const targetPath = match[1];
|
|
122
|
+
// Check if path is dangerous
|
|
123
|
+
if (isDangerousPath(targetPath)) {
|
|
124
|
+
return {
|
|
125
|
+
matched: true,
|
|
126
|
+
command,
|
|
127
|
+
operation: hasRecursive && hasForce ? 'rm -rf' : (hasRecursive ? 'rm -r' : 'rm -f'),
|
|
128
|
+
affectedResource: targetPath,
|
|
129
|
+
confidence: 0.95,
|
|
130
|
+
riskDescription: `Attempting to delete critical system path: ${targetPath}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Even if not a dangerous path, rm -rf is risky
|
|
134
|
+
if (hasRecursive && hasForce) {
|
|
135
|
+
return {
|
|
136
|
+
matched: true,
|
|
137
|
+
command,
|
|
138
|
+
operation: 'rm -rf',
|
|
139
|
+
affectedResource: targetPath,
|
|
140
|
+
confidence: 0.85,
|
|
141
|
+
riskDescription: `Recursive force deletion of: ${targetPath}`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// rm -r alone is still risky
|
|
145
|
+
if (hasRecursive) {
|
|
146
|
+
return {
|
|
147
|
+
matched: true,
|
|
148
|
+
command,
|
|
149
|
+
operation: 'rm -r',
|
|
150
|
+
affectedResource: targetPath,
|
|
151
|
+
confidence: 0.75,
|
|
152
|
+
riskDescription: `Recursive deletion of: ${targetPath}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { matched: false, confidence: 0 };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Match SQL destructive operations
|
|
161
|
+
*/
|
|
162
|
+
export function matchSqlCommand(text) {
|
|
163
|
+
for (const { pattern, operation, critical } of SQL_PATTERNS) {
|
|
164
|
+
const match = text.match(pattern);
|
|
165
|
+
if (match) {
|
|
166
|
+
return {
|
|
167
|
+
matched: true,
|
|
168
|
+
command: text,
|
|
169
|
+
operation,
|
|
170
|
+
affectedResource: match[1],
|
|
171
|
+
confidence: critical ? 0.95 : 0.85,
|
|
172
|
+
riskDescription: `SQL ${operation} operation on: ${match[1]}`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { matched: false, confidence: 0 };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Match system destructive commands
|
|
180
|
+
*/
|
|
181
|
+
export function matchSystemCommand(command) {
|
|
182
|
+
for (const { pattern, operation, description } of SYSTEM_DESTRUCTIVE_PATTERNS) {
|
|
183
|
+
const match = command.match(pattern);
|
|
184
|
+
if (match) {
|
|
185
|
+
return {
|
|
186
|
+
matched: true,
|
|
187
|
+
command,
|
|
188
|
+
operation,
|
|
189
|
+
affectedResource: match[1] || undefined,
|
|
190
|
+
confidence: 0.9,
|
|
191
|
+
riskDescription: description,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { matched: false, confidence: 0 };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Comprehensive shell command matching
|
|
199
|
+
*/
|
|
200
|
+
export function matchShellCommand(command) {
|
|
201
|
+
// Try rm command matching first
|
|
202
|
+
const rmResult = matchRmCommand(command);
|
|
203
|
+
if (rmResult.matched) {
|
|
204
|
+
return rmResult;
|
|
205
|
+
}
|
|
206
|
+
// Try SQL matching
|
|
207
|
+
const sqlResult = matchSqlCommand(command);
|
|
208
|
+
if (sqlResult.matched) {
|
|
209
|
+
return sqlResult;
|
|
210
|
+
}
|
|
211
|
+
// Try system command matching
|
|
212
|
+
const systemResult = matchSystemCommand(command);
|
|
213
|
+
if (systemResult.matched) {
|
|
214
|
+
return systemResult;
|
|
215
|
+
}
|
|
216
|
+
return { matched: false, confidence: 0 };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Shell detector class
|
|
220
|
+
*/
|
|
221
|
+
export class ShellDetector {
|
|
222
|
+
severity;
|
|
223
|
+
constructor(severity = 'critical') {
|
|
224
|
+
this.severity = severity;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Extract command from tool context
|
|
228
|
+
*/
|
|
229
|
+
extractCommand(context) {
|
|
230
|
+
const input = context.toolInput;
|
|
231
|
+
// Direct command field
|
|
232
|
+
if (typeof input.command === 'string') {
|
|
233
|
+
return input.command;
|
|
234
|
+
}
|
|
235
|
+
// Shell/bash command field
|
|
236
|
+
if (typeof input.shell === 'string') {
|
|
237
|
+
return input.shell;
|
|
238
|
+
}
|
|
239
|
+
if (typeof input.bash === 'string') {
|
|
240
|
+
return input.bash;
|
|
241
|
+
}
|
|
242
|
+
// Script field
|
|
243
|
+
if (typeof input.script === 'string') {
|
|
244
|
+
return input.script;
|
|
245
|
+
}
|
|
246
|
+
// Code field (might contain shell commands)
|
|
247
|
+
if (typeof input.code === 'string') {
|
|
248
|
+
return input.code;
|
|
249
|
+
}
|
|
250
|
+
// Query field (for SQL)
|
|
251
|
+
if (typeof input.query === 'string') {
|
|
252
|
+
return input.query;
|
|
253
|
+
}
|
|
254
|
+
// SQL field
|
|
255
|
+
if (typeof input.sql === 'string') {
|
|
256
|
+
return input.sql;
|
|
257
|
+
}
|
|
258
|
+
// Statement field
|
|
259
|
+
if (typeof input.statement === 'string') {
|
|
260
|
+
return input.statement;
|
|
261
|
+
}
|
|
262
|
+
// Text content that might contain commands
|
|
263
|
+
if (typeof input.text === 'string') {
|
|
264
|
+
return input.text;
|
|
265
|
+
}
|
|
266
|
+
// Content field
|
|
267
|
+
if (typeof input.content === 'string') {
|
|
268
|
+
return input.content;
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
detect(context) {
|
|
273
|
+
const command = this.extractCommand(context);
|
|
274
|
+
if (!command) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
const result = matchShellCommand(command);
|
|
278
|
+
if (!result.matched) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
detected: true,
|
|
283
|
+
category: 'destructive',
|
|
284
|
+
severity: this.severity,
|
|
285
|
+
confidence: result.confidence,
|
|
286
|
+
reason: result.riskDescription || `Dangerous shell operation detected: ${result.operation}`,
|
|
287
|
+
metadata: {
|
|
288
|
+
command: result.command,
|
|
289
|
+
type: 'shell',
|
|
290
|
+
operation: result.operation,
|
|
291
|
+
affectedResource: result.affectedResource,
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Create a shell detector with the given severity
|
|
298
|
+
*/
|
|
299
|
+
export function createShellDetector(severity = 'critical') {
|
|
300
|
+
return new ShellDetector(severity);
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=shell-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-detector.js","sourceRoot":"","sources":["../../../../src/detectors/destructive/shell-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,GAAG;IACH,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,GAAG;IACH,OAAO;IACP,eAAe;IACf,MAAM;IACN,aAAa;IACb,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC5B,gCAAgC;IAChC,6EAA6E;IAC7E,uBAAuB;IACvB,sCAAsC;IACtC,uCAAuC;IACvC,sCAAsC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,YAAY,GAAG;IACnB,gBAAgB;IAChB,EAAE,OAAO,EAAE,2DAA2D,EAAE,SAAS,EAAE,eAA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,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,aAAa;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,MAAM,EAAE,MAAM,CAAC,eAAe,IAAI,uCAAuC,MAAM,CAAC,SAAS,EAAE;YAC3F,QAAQ,EAAE;gBACR,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;aAC1C;SACF,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAqB,UAAU;IACjE,OAAO,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Destructive Detector Types
|
|
3
|
+
* Type definitions for detecting dangerous/destructive operations
|
|
4
|
+
*/
|
|
5
|
+
import type { Severity, Action } from '../../config/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Detection context passed to detectors
|
|
8
|
+
*/
|
|
9
|
+
export interface DetectionContext {
|
|
10
|
+
/** Name of the tool being invoked */
|
|
11
|
+
toolName: string;
|
|
12
|
+
/** Input parameters to the tool */
|
|
13
|
+
toolInput: Record<string, unknown>;
|
|
14
|
+
/** URL being accessed (for browser/navigation tools) */
|
|
15
|
+
url?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type of destructive operation detected
|
|
19
|
+
*/
|
|
20
|
+
export type DestructiveType = 'shell' | 'cloud' | 'git' | 'code';
|
|
21
|
+
/**
|
|
22
|
+
* Result of a destructive operation detection
|
|
23
|
+
*/
|
|
24
|
+
export interface DestructiveDetectionResult {
|
|
25
|
+
/** Whether a destructive operation was detected */
|
|
26
|
+
detected: boolean;
|
|
27
|
+
/** Category of the detection */
|
|
28
|
+
category: 'destructive';
|
|
29
|
+
/** Severity level of the detection */
|
|
30
|
+
severity: Severity;
|
|
31
|
+
/** Confidence score from 0 to 1 */
|
|
32
|
+
confidence: number;
|
|
33
|
+
/** Human-readable reason for the detection */
|
|
34
|
+
reason: string;
|
|
35
|
+
/** Additional metadata about the detection */
|
|
36
|
+
metadata?: {
|
|
37
|
+
/** The command that triggered detection */
|
|
38
|
+
command?: string;
|
|
39
|
+
/** Type of destructive operation */
|
|
40
|
+
type: DestructiveType;
|
|
41
|
+
/** Specific operation detected (e.g., 'rm -rf', 'DROP DATABASE') */
|
|
42
|
+
operation?: string;
|
|
43
|
+
/** Resource affected (e.g., path, database name) */
|
|
44
|
+
affectedResource?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for the destructive detector
|
|
49
|
+
*/
|
|
50
|
+
export interface DestructiveDetectorConfig {
|
|
51
|
+
/** Whether the detector is enabled */
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
/** Severity level to assign to detections */
|
|
54
|
+
severity: Severity;
|
|
55
|
+
/** Action to take when destructive operation is detected */
|
|
56
|
+
action: Action;
|
|
57
|
+
/** Shell command protection settings */
|
|
58
|
+
shell?: {
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** Cloud operation protection settings */
|
|
62
|
+
cloud?: {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
};
|
|
65
|
+
/** Code pattern protection settings */
|
|
66
|
+
code?: {
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Interface for the main destructive detector
|
|
72
|
+
*/
|
|
73
|
+
export interface DestructiveDetector {
|
|
74
|
+
/**
|
|
75
|
+
* Detect destructive operations
|
|
76
|
+
* @param context Detection context with tool information
|
|
77
|
+
* @returns Detection result
|
|
78
|
+
*/
|
|
79
|
+
detect(context: DetectionContext): Promise<DestructiveDetectionResult>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Interface for sub-detectors (shell, cloud, code)
|
|
83
|
+
*/
|
|
84
|
+
export interface SubDetector {
|
|
85
|
+
/**
|
|
86
|
+
* Check if the given context matches this detector's patterns
|
|
87
|
+
* @param context Detection context
|
|
88
|
+
* @returns Detection result or null if no match
|
|
89
|
+
*/
|
|
90
|
+
detect(context: DetectionContext): DestructiveDetectionResult | null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Shell command match result
|
|
94
|
+
*/
|
|
95
|
+
export interface ShellMatchResult {
|
|
96
|
+
/** Whether a match was found */
|
|
97
|
+
matched: boolean;
|
|
98
|
+
/** The command that matched */
|
|
99
|
+
command?: string;
|
|
100
|
+
/** The operation type (e.g., 'rm', 'dd', 'DROP DATABASE') */
|
|
101
|
+
operation?: string;
|
|
102
|
+
/** The affected resource (path, database, etc.) */
|
|
103
|
+
affectedResource?: string;
|
|
104
|
+
/** Confidence score */
|
|
105
|
+
confidence: number;
|
|
106
|
+
/** Additional description of the risk */
|
|
107
|
+
riskDescription?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Cloud operation match result
|
|
111
|
+
*/
|
|
112
|
+
export interface CloudMatchResult {
|
|
113
|
+
/** Whether a match was found */
|
|
114
|
+
matched: boolean;
|
|
115
|
+
/** The command that matched */
|
|
116
|
+
command?: string;
|
|
117
|
+
/** The cloud provider (aws, gcp, azure, k8s, terraform) */
|
|
118
|
+
provider?: string;
|
|
119
|
+
/** The operation detected */
|
|
120
|
+
operation?: string;
|
|
121
|
+
/** The affected resource */
|
|
122
|
+
affectedResource?: string;
|
|
123
|
+
/** Confidence score */
|
|
124
|
+
confidence: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Code pattern match result
|
|
128
|
+
*/
|
|
129
|
+
export interface CodeMatchResult {
|
|
130
|
+
/** Whether a match was found */
|
|
131
|
+
matched: boolean;
|
|
132
|
+
/** The code/command that matched */
|
|
133
|
+
code?: string;
|
|
134
|
+
/** The language detected (python, node, go, etc.) */
|
|
135
|
+
language?: string;
|
|
136
|
+
/** The operation detected (e.g., 'rmtree', 'removeAll') */
|
|
137
|
+
operation?: string;
|
|
138
|
+
/** The affected path/resource */
|
|
139
|
+
affectedResource?: string;
|
|
140
|
+
/** Confidence score */
|
|
141
|
+
confidence: number;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=types.d.ts.map
|