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,558 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Detector
|
|
3
|
+
* Detects dangerous code patterns for file/directory deletion across multiple languages
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Python destructive patterns
|
|
7
|
+
*/
|
|
8
|
+
const PYTHON_PATTERNS = [
|
|
9
|
+
// shutil.rmtree
|
|
10
|
+
{
|
|
11
|
+
pattern: /\bshutil\.rmtree\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
12
|
+
operation: 'shutil.rmtree',
|
|
13
|
+
description: 'Recursive directory deletion',
|
|
14
|
+
},
|
|
15
|
+
// os.remove / os.unlink
|
|
16
|
+
{
|
|
17
|
+
pattern: /\bos\.(?:remove|unlink)\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
18
|
+
operation: 'os.remove',
|
|
19
|
+
description: 'File deletion',
|
|
20
|
+
},
|
|
21
|
+
// os.rmdir
|
|
22
|
+
{
|
|
23
|
+
pattern: /\bos\.rmdir\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
24
|
+
operation: 'os.rmdir',
|
|
25
|
+
description: 'Directory deletion',
|
|
26
|
+
},
|
|
27
|
+
// pathlib rmdir/unlink
|
|
28
|
+
{
|
|
29
|
+
pattern: /\.rmdir\s*\(\s*\)/i,
|
|
30
|
+
operation: 'Path.rmdir',
|
|
31
|
+
description: 'Directory deletion via pathlib',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
pattern: /\.unlink\s*\(\s*(?:missing_ok\s*=\s*(?:True|False))?\s*\)/i,
|
|
35
|
+
operation: 'Path.unlink',
|
|
36
|
+
description: 'File deletion via pathlib',
|
|
37
|
+
},
|
|
38
|
+
// os.removedirs
|
|
39
|
+
{
|
|
40
|
+
pattern: /\bos\.removedirs\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
41
|
+
operation: 'os.removedirs',
|
|
42
|
+
description: 'Recursive directory deletion',
|
|
43
|
+
},
|
|
44
|
+
// subprocess/os.system with rm
|
|
45
|
+
{
|
|
46
|
+
pattern: /(?:subprocess\.(?:run|call|Popen)|os\.system)\s*\(\s*['"`].*\brm\s+-r/i,
|
|
47
|
+
operation: 'subprocess rm -r',
|
|
48
|
+
description: 'Subprocess recursive deletion',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Node.js/JavaScript destructive patterns
|
|
53
|
+
*/
|
|
54
|
+
const NODEJS_PATTERNS = [
|
|
55
|
+
// fs.rm with recursive
|
|
56
|
+
{
|
|
57
|
+
pattern: /\bfs(?:Promises)?\.rm\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))\s*,\s*\{[^}]*recursive\s*:\s*true/i,
|
|
58
|
+
operation: 'fs.rm(recursive)',
|
|
59
|
+
description: 'Recursive deletion',
|
|
60
|
+
},
|
|
61
|
+
// fs.rmdir with recursive (deprecated but still used)
|
|
62
|
+
{
|
|
63
|
+
pattern: /\bfs(?:Promises)?\.rmdir\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))\s*,\s*\{[^}]*recursive\s*:\s*true/i,
|
|
64
|
+
operation: 'fs.rmdir(recursive)',
|
|
65
|
+
description: 'Recursive directory deletion',
|
|
66
|
+
},
|
|
67
|
+
// fs.rmSync with recursive
|
|
68
|
+
{
|
|
69
|
+
pattern: /\bfs\.rmSync\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))\s*,\s*\{[^}]*recursive\s*:\s*true/i,
|
|
70
|
+
operation: 'fs.rmSync(recursive)',
|
|
71
|
+
description: 'Synchronous recursive deletion',
|
|
72
|
+
},
|
|
73
|
+
// fs.rmdirSync with recursive
|
|
74
|
+
{
|
|
75
|
+
pattern: /\bfs\.rmdirSync\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))\s*,\s*\{[^}]*recursive\s*:\s*true/i,
|
|
76
|
+
operation: 'fs.rmdirSync(recursive)',
|
|
77
|
+
description: 'Synchronous recursive directory deletion',
|
|
78
|
+
},
|
|
79
|
+
// fs.unlink / fs.unlinkSync
|
|
80
|
+
{
|
|
81
|
+
pattern: /\bfs(?:Promises)?\.unlink(?:Sync)?\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
82
|
+
operation: 'fs.unlink',
|
|
83
|
+
description: 'File deletion',
|
|
84
|
+
},
|
|
85
|
+
// rimraf
|
|
86
|
+
{
|
|
87
|
+
pattern: /\brimraf(?:Sync)?\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
88
|
+
operation: 'rimraf',
|
|
89
|
+
description: 'Recursive deletion (rimraf)',
|
|
90
|
+
},
|
|
91
|
+
// del / del-cli
|
|
92
|
+
{
|
|
93
|
+
pattern: /\bdel(?:Sync)?\s*\(\s*\[?\s*['"`]([^'"`]+)['"`]/i,
|
|
94
|
+
operation: 'del',
|
|
95
|
+
description: 'File/directory deletion (del)',
|
|
96
|
+
},
|
|
97
|
+
// fs-extra remove/emptyDir
|
|
98
|
+
{
|
|
99
|
+
pattern: /\b(?:fs-extra|fse?)\.(?:remove|emptyDir)(?:Sync)?\s*\(\s*(?:['"`]([^'"`]+)['"`]|(\w+))/i,
|
|
100
|
+
operation: 'fs-extra.remove',
|
|
101
|
+
description: 'Recursive deletion (fs-extra)',
|
|
102
|
+
},
|
|
103
|
+
// exec/spawn with rm
|
|
104
|
+
{
|
|
105
|
+
pattern: /(?:exec|spawn)(?:Sync)?\s*\(\s*['"`].*\brm\s+-r/i,
|
|
106
|
+
operation: 'exec rm -r',
|
|
107
|
+
description: 'Child process recursive deletion',
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
/**
|
|
111
|
+
* Go destructive patterns
|
|
112
|
+
*/
|
|
113
|
+
const GO_PATTERNS = [
|
|
114
|
+
// os.RemoveAll
|
|
115
|
+
{
|
|
116
|
+
pattern: /\bos\.RemoveAll\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
117
|
+
operation: 'os.RemoveAll',
|
|
118
|
+
description: 'Recursive deletion',
|
|
119
|
+
},
|
|
120
|
+
// os.Remove
|
|
121
|
+
{
|
|
122
|
+
pattern: /\bos\.Remove\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
123
|
+
operation: 'os.Remove',
|
|
124
|
+
description: 'File/directory deletion',
|
|
125
|
+
},
|
|
126
|
+
// filepath.Walk + os.Remove pattern
|
|
127
|
+
{
|
|
128
|
+
pattern: /filepath\.Walk.*os\.Remove/is,
|
|
129
|
+
operation: 'filepath.Walk + Remove',
|
|
130
|
+
description: 'Walking deletion pattern',
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
/**
|
|
134
|
+
* Rust destructive patterns
|
|
135
|
+
*/
|
|
136
|
+
const RUST_PATTERNS = [
|
|
137
|
+
// std::fs::remove_dir_all
|
|
138
|
+
{
|
|
139
|
+
pattern: /\bstd::fs::remove_dir_all\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
140
|
+
operation: 'remove_dir_all',
|
|
141
|
+
description: 'Recursive directory deletion',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
pattern: /\bfs::remove_dir_all\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
145
|
+
operation: 'remove_dir_all',
|
|
146
|
+
description: 'Recursive directory deletion',
|
|
147
|
+
},
|
|
148
|
+
// std::fs::remove_file
|
|
149
|
+
{
|
|
150
|
+
pattern: /\bstd::fs::remove_file\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
151
|
+
operation: 'remove_file',
|
|
152
|
+
description: 'File deletion',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
pattern: /\bfs::remove_file\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
156
|
+
operation: 'remove_file',
|
|
157
|
+
description: 'File deletion',
|
|
158
|
+
},
|
|
159
|
+
// std::fs::remove_dir
|
|
160
|
+
{
|
|
161
|
+
pattern: /\bstd::fs::remove_dir\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
162
|
+
operation: 'remove_dir',
|
|
163
|
+
description: 'Directory deletion',
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
pattern: /\bfs::remove_dir\s*\(\s*(?:"([^"]+)"|(\w+))/i,
|
|
167
|
+
operation: 'remove_dir',
|
|
168
|
+
description: 'Directory deletion',
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
/**
|
|
172
|
+
* Ruby destructive patterns
|
|
173
|
+
*/
|
|
174
|
+
const RUBY_PATTERNS = [
|
|
175
|
+
// FileUtils.rm_rf
|
|
176
|
+
{
|
|
177
|
+
pattern: /\bFileUtils\.rm_rf\s*\(?['"`]?([^'"`\s,)]+)/i,
|
|
178
|
+
operation: 'FileUtils.rm_rf',
|
|
179
|
+
description: 'Recursive force deletion',
|
|
180
|
+
},
|
|
181
|
+
// FileUtils.rm_r
|
|
182
|
+
{
|
|
183
|
+
pattern: /\bFileUtils\.rm_r\s*\(?['"`]?([^'"`\s,)]+)/i,
|
|
184
|
+
operation: 'FileUtils.rm_r',
|
|
185
|
+
description: 'Recursive deletion',
|
|
186
|
+
},
|
|
187
|
+
// FileUtils.remove_entry
|
|
188
|
+
{
|
|
189
|
+
pattern: /\bFileUtils\.remove_entry(?:_secure)?\s*\(?['"`]?([^'"`\s,)]+)/i,
|
|
190
|
+
operation: 'FileUtils.remove_entry',
|
|
191
|
+
description: 'Entry removal',
|
|
192
|
+
},
|
|
193
|
+
// File.delete
|
|
194
|
+
{
|
|
195
|
+
pattern: /\bFile\.delete\s*\(?['"`]?([^'"`\s,)]+)/i,
|
|
196
|
+
operation: 'File.delete',
|
|
197
|
+
description: 'File deletion',
|
|
198
|
+
},
|
|
199
|
+
// Dir.rmdir
|
|
200
|
+
{
|
|
201
|
+
pattern: /\bDir\.rmdir\s*\(?['"`]?([^'"`\s,)]+)/i,
|
|
202
|
+
operation: 'Dir.rmdir',
|
|
203
|
+
description: 'Directory deletion',
|
|
204
|
+
},
|
|
205
|
+
];
|
|
206
|
+
/**
|
|
207
|
+
* Java/Kotlin destructive patterns
|
|
208
|
+
*/
|
|
209
|
+
const JAVA_PATTERNS = [
|
|
210
|
+
// Files.delete / Files.deleteIfExists
|
|
211
|
+
{
|
|
212
|
+
pattern: /\bFiles\.delete(?:IfExists)?\s*\(\s*(?:Paths\.get\s*\(\s*)?["']?([^"')\s]+)/i,
|
|
213
|
+
operation: 'Files.delete',
|
|
214
|
+
description: 'File/directory deletion',
|
|
215
|
+
},
|
|
216
|
+
// FileUtils.deleteDirectory (Apache Commons)
|
|
217
|
+
{
|
|
218
|
+
pattern: /\bFileUtils\.(?:deleteDirectory|deleteQuietly|forceDelete)\s*\(\s*(?:new\s+File\s*\(\s*)?["']?([^"')\s]+)/i,
|
|
219
|
+
operation: 'FileUtils.deleteDirectory',
|
|
220
|
+
description: 'Recursive directory deletion',
|
|
221
|
+
},
|
|
222
|
+
// file.delete()
|
|
223
|
+
{
|
|
224
|
+
pattern: /\.delete\s*\(\s*\)/i,
|
|
225
|
+
operation: 'File.delete()',
|
|
226
|
+
description: 'File deletion',
|
|
227
|
+
},
|
|
228
|
+
// Files.walk + delete pattern
|
|
229
|
+
{
|
|
230
|
+
pattern: /Files\.walk.*\.delete/is,
|
|
231
|
+
operation: 'Files.walk + delete',
|
|
232
|
+
description: 'Walking deletion pattern',
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
/**
|
|
236
|
+
* C# destructive patterns
|
|
237
|
+
*/
|
|
238
|
+
const CSHARP_PATTERNS = [
|
|
239
|
+
// Directory.Delete with recursive
|
|
240
|
+
{
|
|
241
|
+
pattern: /\bDirectory\.Delete\s*\(\s*(?:@)?["']([^"']+)["']\s*,\s*true/i,
|
|
242
|
+
operation: 'Directory.Delete(recursive)',
|
|
243
|
+
description: 'Recursive directory deletion',
|
|
244
|
+
},
|
|
245
|
+
// File.Delete
|
|
246
|
+
{
|
|
247
|
+
pattern: /\bFile\.Delete\s*\(\s*(?:@)?["']([^"']+)/i,
|
|
248
|
+
operation: 'File.Delete',
|
|
249
|
+
description: 'File deletion',
|
|
250
|
+
},
|
|
251
|
+
// DirectoryInfo.Delete
|
|
252
|
+
{
|
|
253
|
+
pattern: /\.Delete\s*\(\s*true\s*\)/i,
|
|
254
|
+
operation: 'DirectoryInfo.Delete(recursive)',
|
|
255
|
+
description: 'Recursive deletion via DirectoryInfo',
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
/**
|
|
259
|
+
* PHP destructive patterns
|
|
260
|
+
*/
|
|
261
|
+
const PHP_PATTERNS = [
|
|
262
|
+
// unlink
|
|
263
|
+
{
|
|
264
|
+
pattern: /\bunlink\s*\(\s*(?:\$\w+|['"`]([^'"`]+))/i,
|
|
265
|
+
operation: 'unlink',
|
|
266
|
+
description: 'File deletion',
|
|
267
|
+
},
|
|
268
|
+
// rmdir
|
|
269
|
+
{
|
|
270
|
+
pattern: /\brmdir\s*\(\s*(?:\$\w+|['"`]([^'"`]+))/i,
|
|
271
|
+
operation: 'rmdir',
|
|
272
|
+
description: 'Directory deletion',
|
|
273
|
+
},
|
|
274
|
+
// array_map + unlink pattern (recursive deletion)
|
|
275
|
+
{
|
|
276
|
+
pattern: /array_map\s*\(\s*['"`]unlink['"`]/i,
|
|
277
|
+
operation: 'array_map unlink',
|
|
278
|
+
description: 'Batch file deletion',
|
|
279
|
+
},
|
|
280
|
+
// RecursiveIterator + unlink/rmdir
|
|
281
|
+
{
|
|
282
|
+
pattern: /RecursiveIteratorIterator.*(?:unlink|rmdir)/is,
|
|
283
|
+
operation: 'recursive unlink',
|
|
284
|
+
description: 'Recursive deletion',
|
|
285
|
+
},
|
|
286
|
+
];
|
|
287
|
+
/**
|
|
288
|
+
* Match Python code patterns
|
|
289
|
+
*/
|
|
290
|
+
export function matchPythonCode(code) {
|
|
291
|
+
for (const { pattern, operation } of PYTHON_PATTERNS) {
|
|
292
|
+
const match = code.match(pattern);
|
|
293
|
+
if (match) {
|
|
294
|
+
return {
|
|
295
|
+
matched: true,
|
|
296
|
+
code,
|
|
297
|
+
language: 'python',
|
|
298
|
+
operation,
|
|
299
|
+
affectedResource: match[1] || match[2] || undefined,
|
|
300
|
+
confidence: operation.includes('rmtree') || operation.includes('removedirs') ? 0.9 : 0.8,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { matched: false, confidence: 0 };
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Match Node.js code patterns
|
|
308
|
+
*/
|
|
309
|
+
export function matchNodeCode(code) {
|
|
310
|
+
for (const { pattern, operation } of NODEJS_PATTERNS) {
|
|
311
|
+
const match = code.match(pattern);
|
|
312
|
+
if (match) {
|
|
313
|
+
return {
|
|
314
|
+
matched: true,
|
|
315
|
+
code,
|
|
316
|
+
language: 'javascript',
|
|
317
|
+
operation,
|
|
318
|
+
affectedResource: match[1] || match[2] || undefined,
|
|
319
|
+
confidence: operation.includes('recursive') || operation === 'rimraf' ? 0.9 : 0.8,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return { matched: false, confidence: 0 };
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Match Go code patterns
|
|
327
|
+
*/
|
|
328
|
+
export function matchGoCode(code) {
|
|
329
|
+
for (const { pattern, operation } of GO_PATTERNS) {
|
|
330
|
+
const match = code.match(pattern);
|
|
331
|
+
if (match) {
|
|
332
|
+
return {
|
|
333
|
+
matched: true,
|
|
334
|
+
code,
|
|
335
|
+
language: 'go',
|
|
336
|
+
operation,
|
|
337
|
+
affectedResource: match[1] || match[2] || undefined,
|
|
338
|
+
confidence: operation === 'os.RemoveAll' ? 0.9 : 0.8,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return { matched: false, confidence: 0 };
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Match Rust code patterns
|
|
346
|
+
*/
|
|
347
|
+
export function matchRustCode(code) {
|
|
348
|
+
for (const { pattern, operation } of RUST_PATTERNS) {
|
|
349
|
+
const match = code.match(pattern);
|
|
350
|
+
if (match) {
|
|
351
|
+
return {
|
|
352
|
+
matched: true,
|
|
353
|
+
code,
|
|
354
|
+
language: 'rust',
|
|
355
|
+
operation,
|
|
356
|
+
affectedResource: match[1] || match[2] || undefined,
|
|
357
|
+
confidence: operation === 'remove_dir_all' ? 0.9 : 0.8,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return { matched: false, confidence: 0 };
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Match Ruby code patterns
|
|
365
|
+
*/
|
|
366
|
+
export function matchRubyCode(code) {
|
|
367
|
+
for (const { pattern, operation } of RUBY_PATTERNS) {
|
|
368
|
+
const match = code.match(pattern);
|
|
369
|
+
if (match) {
|
|
370
|
+
return {
|
|
371
|
+
matched: true,
|
|
372
|
+
code,
|
|
373
|
+
language: 'ruby',
|
|
374
|
+
operation,
|
|
375
|
+
affectedResource: match[1] || undefined,
|
|
376
|
+
confidence: operation.includes('rm_rf') || operation.includes('rm_r') ? 0.9 : 0.8,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return { matched: false, confidence: 0 };
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Match Java/Kotlin code patterns
|
|
384
|
+
*/
|
|
385
|
+
export function matchJavaCode(code) {
|
|
386
|
+
for (const { pattern, operation } of JAVA_PATTERNS) {
|
|
387
|
+
const match = code.match(pattern);
|
|
388
|
+
if (match) {
|
|
389
|
+
return {
|
|
390
|
+
matched: true,
|
|
391
|
+
code,
|
|
392
|
+
language: 'java',
|
|
393
|
+
operation,
|
|
394
|
+
affectedResource: match[1] || undefined,
|
|
395
|
+
confidence: operation.includes('Directory') || operation.includes('walk') ? 0.9 : 0.75,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return { matched: false, confidence: 0 };
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Match C# code patterns
|
|
403
|
+
*/
|
|
404
|
+
export function matchCSharpCode(code) {
|
|
405
|
+
for (const { pattern, operation } of CSHARP_PATTERNS) {
|
|
406
|
+
const match = code.match(pattern);
|
|
407
|
+
if (match) {
|
|
408
|
+
return {
|
|
409
|
+
matched: true,
|
|
410
|
+
code,
|
|
411
|
+
language: 'csharp',
|
|
412
|
+
operation,
|
|
413
|
+
affectedResource: match[1] || undefined,
|
|
414
|
+
confidence: operation.includes('recursive') ? 0.9 : 0.8,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return { matched: false, confidence: 0 };
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Match PHP code patterns
|
|
422
|
+
*/
|
|
423
|
+
export function matchPhpCode(code) {
|
|
424
|
+
for (const { pattern, operation } of PHP_PATTERNS) {
|
|
425
|
+
const match = code.match(pattern);
|
|
426
|
+
if (match) {
|
|
427
|
+
return {
|
|
428
|
+
matched: true,
|
|
429
|
+
code,
|
|
430
|
+
language: 'php',
|
|
431
|
+
operation,
|
|
432
|
+
affectedResource: match[1] || undefined,
|
|
433
|
+
confidence: operation.includes('recursive') || operation.includes('array_map') ? 0.85 : 0.8,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return { matched: false, confidence: 0 };
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Comprehensive code pattern matching
|
|
441
|
+
*/
|
|
442
|
+
export function matchCodePattern(code) {
|
|
443
|
+
// Try all language patterns
|
|
444
|
+
const pythonResult = matchPythonCode(code);
|
|
445
|
+
if (pythonResult.matched)
|
|
446
|
+
return pythonResult;
|
|
447
|
+
const nodeResult = matchNodeCode(code);
|
|
448
|
+
if (nodeResult.matched)
|
|
449
|
+
return nodeResult;
|
|
450
|
+
const goResult = matchGoCode(code);
|
|
451
|
+
if (goResult.matched)
|
|
452
|
+
return goResult;
|
|
453
|
+
const rustResult = matchRustCode(code);
|
|
454
|
+
if (rustResult.matched)
|
|
455
|
+
return rustResult;
|
|
456
|
+
const rubyResult = matchRubyCode(code);
|
|
457
|
+
if (rubyResult.matched)
|
|
458
|
+
return rubyResult;
|
|
459
|
+
const javaResult = matchJavaCode(code);
|
|
460
|
+
if (javaResult.matched)
|
|
461
|
+
return javaResult;
|
|
462
|
+
const csharpResult = matchCSharpCode(code);
|
|
463
|
+
if (csharpResult.matched)
|
|
464
|
+
return csharpResult;
|
|
465
|
+
const phpResult = matchPhpCode(code);
|
|
466
|
+
if (phpResult.matched)
|
|
467
|
+
return phpResult;
|
|
468
|
+
return { matched: false, confidence: 0 };
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Code detector class
|
|
472
|
+
*/
|
|
473
|
+
export class CodeDetector {
|
|
474
|
+
severity;
|
|
475
|
+
constructor(severity = 'critical') {
|
|
476
|
+
this.severity = severity;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Extract code from tool context
|
|
480
|
+
*/
|
|
481
|
+
extractCode(context) {
|
|
482
|
+
const input = context.toolInput;
|
|
483
|
+
// Direct code field
|
|
484
|
+
if (typeof input.code === 'string') {
|
|
485
|
+
return input.code;
|
|
486
|
+
}
|
|
487
|
+
// Script field
|
|
488
|
+
if (typeof input.script === 'string') {
|
|
489
|
+
return input.script;
|
|
490
|
+
}
|
|
491
|
+
// Content field (for file writes)
|
|
492
|
+
if (typeof input.content === 'string') {
|
|
493
|
+
return input.content;
|
|
494
|
+
}
|
|
495
|
+
// Source field
|
|
496
|
+
if (typeof input.source === 'string') {
|
|
497
|
+
return input.source;
|
|
498
|
+
}
|
|
499
|
+
// Body field (for requests)
|
|
500
|
+
if (typeof input.body === 'string') {
|
|
501
|
+
return input.body;
|
|
502
|
+
}
|
|
503
|
+
// Text field
|
|
504
|
+
if (typeof input.text === 'string') {
|
|
505
|
+
return input.text;
|
|
506
|
+
}
|
|
507
|
+
// New source for replacements
|
|
508
|
+
if (typeof input.new_source === 'string') {
|
|
509
|
+
return input.new_source;
|
|
510
|
+
}
|
|
511
|
+
// Function field (for eval)
|
|
512
|
+
if (typeof input.function === 'string') {
|
|
513
|
+
return input.function;
|
|
514
|
+
}
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
detect(context) {
|
|
518
|
+
const code = this.extractCode(context);
|
|
519
|
+
if (!code) {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
const result = matchCodePattern(code);
|
|
523
|
+
if (!result.matched) {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
const languageNames = {
|
|
527
|
+
python: 'Python',
|
|
528
|
+
javascript: 'JavaScript/Node.js',
|
|
529
|
+
go: 'Go',
|
|
530
|
+
rust: 'Rust',
|
|
531
|
+
ruby: 'Ruby',
|
|
532
|
+
java: 'Java/Kotlin',
|
|
533
|
+
csharp: 'C#',
|
|
534
|
+
php: 'PHP',
|
|
535
|
+
};
|
|
536
|
+
const langName = languageNames[result.language || 'unknown'] || result.language;
|
|
537
|
+
return {
|
|
538
|
+
detected: true,
|
|
539
|
+
category: 'destructive',
|
|
540
|
+
severity: this.severity,
|
|
541
|
+
confidence: result.confidence,
|
|
542
|
+
reason: `Dangerous ${langName} file deletion operation detected: ${result.operation}`,
|
|
543
|
+
metadata: {
|
|
544
|
+
command: result.code,
|
|
545
|
+
type: 'code',
|
|
546
|
+
operation: result.operation,
|
|
547
|
+
affectedResource: result.affectedResource,
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Create a code detector with the given severity
|
|
554
|
+
*/
|
|
555
|
+
export function createCodeDetector(severity = 'critical') {
|
|
556
|
+
return new CodeDetector(severity);
|
|
557
|
+
}
|
|
558
|
+
//# sourceMappingURL=code-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-detector.js","sourceRoot":"","sources":["../../../../src/detectors/destructive/code-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,gBAAgB;IAChB;QACE,OAAO,EAAE,wDAAwD;QACjE,SAAS,EAAE,eAAe;QAC1B,WAAW,EAAE,8BAA8B;KAC5C;IACD,wBAAwB;IACxB;QACE,OAAO,EAAE,+DAA+D;QACxE,SAAS,EAAE,WAAW;QACtB,WAAW,EAAE,eAAe;KAC7B;IACD,WAAW;IACX;QACE,OAAO,EAAE,mDAAmD;QAC5D,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,oBAAoB;KAClC;IACD,uBAAuB;IACvB;QACE,OAAO,EAAE,oBAAoB;QAC7B,SAAS,EAAE,YAAY;QACvB,WAAW,EAAE,gCAAgC;KAC9C;IACD;QACE,OAAO,EAAE,4DAA4D;QACrE,SAAS,EAAE,aAAa;QACxB,WAAW,EAAE,2BAA2B;KACzC;IACD,gBAAgB;IAChB;QACE,OAAO,EAAE,wDAAwD;QACjE,SAAS,EAAE,eAAe;QAC1B,WAAW,EAAE,8BAA8B;KAC5C;IACD,+BAA+B;IAC/B;QACE,OAAO,EAAE,wEAAwE;QACjF,SAAS,EAAE,kBAAkB;QAC7B,WAAW,EAAE,+BAA+B;KAC7C;CACF,CAAC;AAEF;;GAE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I,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,aAAa,GAA2B;YAC5C,MAAM,EAAE,QAAQ;YAChB,UAAU,EAAE,oBAAoB;YAChC,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE,KAAK;SACX,CAAC;QAEF,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,QAAQ,IAAI,SAAS,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC;QAEhF,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,aAAa;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,MAAM,EAAE,aAAa,QAAQ,sCAAsC,MAAM,CAAC,SAAS,EAAE;YACrF,QAAQ,EAAE;gBACR,OAAO,EAAE,MAAM,CAAC,IAAI;gBACpB,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;aAC1C;SACF,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAqB,UAAU;IAChE,OAAO,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Destructive Detector
|
|
3
|
+
* Main detector that combines shell, cloud, git, and code pattern detection
|
|
4
|
+
*/
|
|
5
|
+
import type { DetectionContext, DestructiveDetectionResult, DestructiveDetector as IDestructiveDetector, DestructiveDetectorConfig } from './types.js';
|
|
6
|
+
import type { DestructiveRule } from '../../config/index.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export { ShellDetector, createShellDetector } from './shell-detector.js';
|
|
9
|
+
export { CloudDetector, createCloudDetector } from './cloud-detector.js';
|
|
10
|
+
export { CodeDetector, createCodeDetector } from './code-detector.js';
|
|
11
|
+
export { isDangerousPath, matchRmCommand, matchSqlCommand, matchSystemCommand, matchShellCommand, } from './shell-detector.js';
|
|
12
|
+
export { matchAwsCommand, matchGcpCommand, matchAzureCommand, matchKubernetesCommand, matchTerraformCommand, matchGitCommand, matchCloudCommand, } from './cloud-detector.js';
|
|
13
|
+
export { matchPythonCode, matchNodeCode, matchGoCode, matchRustCode, matchRubyCode, matchJavaCode, matchCSharpCode, matchPhpCode, matchCodePattern, } from './code-detector.js';
|
|
14
|
+
/**
|
|
15
|
+
* Main destructive detector implementation
|
|
16
|
+
*/
|
|
17
|
+
export declare class DestructiveDetectorImpl implements IDestructiveDetector {
|
|
18
|
+
private config;
|
|
19
|
+
private shellDetector;
|
|
20
|
+
private cloudDetector;
|
|
21
|
+
private codeDetector;
|
|
22
|
+
constructor(config: DestructiveDetectorConfig);
|
|
23
|
+
detect(context: DetectionContext): Promise<DestructiveDetectionResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the configured action for detected destructive operations
|
|
26
|
+
*/
|
|
27
|
+
getAction(): "block" | "confirm" | "agent-confirm" | "warn" | "log";
|
|
28
|
+
/**
|
|
29
|
+
* Check if the detector is enabled
|
|
30
|
+
*/
|
|
31
|
+
isEnabled(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check if shell detection is enabled
|
|
34
|
+
*/
|
|
35
|
+
isShellEnabled(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if cloud detection is enabled
|
|
38
|
+
*/
|
|
39
|
+
isCloudEnabled(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Check if code detection is enabled
|
|
42
|
+
*/
|
|
43
|
+
isCodeEnabled(): boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a destructive detector from DestructiveRule configuration
|
|
47
|
+
*/
|
|
48
|
+
export declare function createDestructiveDetector(rule: DestructiveRule): DestructiveDetectorImpl;
|
|
49
|
+
/**
|
|
50
|
+
* Create a destructive detector with default configuration
|
|
51
|
+
*/
|
|
52
|
+
export declare function createDefaultDestructiveDetector(): DestructiveDetectorImpl;
|
|
53
|
+
export default DestructiveDetectorImpl;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/detectors/destructive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,IAAI,oBAAoB,EAC3C,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,eAAe,EAAY,MAAM,uBAAuB,CAAC;AAGvE,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,EACL,eAAe,EACf,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,oB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