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,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy Server Type Definitions
|
|
3
|
+
* Types for the standalone HTTP proxy server
|
|
4
|
+
*/
|
|
5
|
+
import type { ClawsecConfig } from '../config/schema.js';
|
|
6
|
+
import type { AnalysisResult, Detection } from '../engine/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the proxy server
|
|
9
|
+
*/
|
|
10
|
+
export interface ProxyConfig {
|
|
11
|
+
/** Port to listen on */
|
|
12
|
+
port: number;
|
|
13
|
+
/** Host to bind to (default: '127.0.0.1') */
|
|
14
|
+
host?: string;
|
|
15
|
+
/** Clawsec configuration for analysis */
|
|
16
|
+
clawsecConfig: ClawsecConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Request body for the /analyze endpoint
|
|
20
|
+
*/
|
|
21
|
+
export interface ProxyRequest {
|
|
22
|
+
/** Name of the tool being called */
|
|
23
|
+
toolName: string;
|
|
24
|
+
/** Input parameters to the tool */
|
|
25
|
+
toolInput: Record<string, unknown>;
|
|
26
|
+
/** Optional session identifier */
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
/** Optional user identifier */
|
|
29
|
+
userId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Response from the /analyze endpoint
|
|
33
|
+
*/
|
|
34
|
+
export interface ProxyResponse {
|
|
35
|
+
/** Whether the request is allowed */
|
|
36
|
+
allowed: boolean;
|
|
37
|
+
/** Human-readable message explaining the decision */
|
|
38
|
+
message?: string;
|
|
39
|
+
/** Information about pending approval (if action is 'confirm') */
|
|
40
|
+
pendingApproval?: {
|
|
41
|
+
/** Unique identifier for the approval */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Timeout in seconds before the approval expires */
|
|
44
|
+
timeout: number;
|
|
45
|
+
};
|
|
46
|
+
/** Filtered/sanitized input (if any modifications were made) */
|
|
47
|
+
filteredInput?: Record<string, unknown>;
|
|
48
|
+
/** Analysis result details */
|
|
49
|
+
analysis?: {
|
|
50
|
+
/** Recommended action */
|
|
51
|
+
action: AnalysisResult['action'];
|
|
52
|
+
/** List of detections */
|
|
53
|
+
detections: Detection[];
|
|
54
|
+
/** Whether result was cached */
|
|
55
|
+
cached: boolean;
|
|
56
|
+
/** Analysis duration in milliseconds */
|
|
57
|
+
durationMs?: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Response from /approve/:id and /deny/:id endpoints
|
|
62
|
+
*/
|
|
63
|
+
export interface ApprovalActionResponse {
|
|
64
|
+
/** Whether the operation succeeded */
|
|
65
|
+
success: boolean;
|
|
66
|
+
/** Human-readable message */
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Response from /status endpoint
|
|
71
|
+
*/
|
|
72
|
+
export interface StatusResponse {
|
|
73
|
+
/** Whether the server is active and accepting requests */
|
|
74
|
+
active: boolean;
|
|
75
|
+
/** Configuration summary */
|
|
76
|
+
config: {
|
|
77
|
+
/** Configured port */
|
|
78
|
+
port: number;
|
|
79
|
+
/** Configured host */
|
|
80
|
+
host: string;
|
|
81
|
+
/** Whether global detection is enabled */
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
};
|
|
84
|
+
/** Number of pending approvals */
|
|
85
|
+
pendingApprovals: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Response from /health endpoint
|
|
89
|
+
*/
|
|
90
|
+
export interface HealthResponse {
|
|
91
|
+
/** Health status */
|
|
92
|
+
status: 'ok';
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Error response for API errors
|
|
96
|
+
*/
|
|
97
|
+
export interface ErrorResponse {
|
|
98
|
+
/** Error flag */
|
|
99
|
+
error: true;
|
|
100
|
+
/** Error message */
|
|
101
|
+
message: string;
|
|
102
|
+
/** HTTP status code */
|
|
103
|
+
statusCode: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Proxy server interface
|
|
107
|
+
*/
|
|
108
|
+
export interface ProxyServer {
|
|
109
|
+
/** Start the server */
|
|
110
|
+
start(): Promise<void>;
|
|
111
|
+
/** Stop the server */
|
|
112
|
+
stop(): Promise<void>;
|
|
113
|
+
/** Get the actual port the server is listening on */
|
|
114
|
+
getPort(): number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* HTTP request handler function
|
|
118
|
+
*/
|
|
119
|
+
export type RequestHandler = (req: ProxyHttpRequest, res: ProxyHttpResponse) => Promise<void> | void;
|
|
120
|
+
/**
|
|
121
|
+
* Simplified HTTP request interface
|
|
122
|
+
*/
|
|
123
|
+
export interface ProxyHttpRequest {
|
|
124
|
+
method: string;
|
|
125
|
+
url: string;
|
|
126
|
+
body?: unknown;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Simplified HTTP response interface
|
|
130
|
+
*/
|
|
131
|
+
export interface ProxyHttpResponse {
|
|
132
|
+
statusCode: number;
|
|
133
|
+
json(data: unknown): void;
|
|
134
|
+
end(): void;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/proxy/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EA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AAE,OAAO,GAAG,IAAI,CAAC;IAC1B,GAAG,IAAI,IAAI,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/proxy/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output scanner for prompt injection detection
|
|
3
|
+
*
|
|
4
|
+
* @module sanitization
|
|
5
|
+
*/
|
|
6
|
+
export type { InjectionCategory, InjectionMatch, ScanResult, ScannerConfig, } from './types.js';
|
|
7
|
+
export type { PatternDef } from './patterns.js';
|
|
8
|
+
export { INSTRUCTION_OVERRIDE_PATTERNS, SYSTEM_LEAK_PATTERNS, JAILBREAK_PATTERNS, ENCODED_PAYLOAD_PATTERNS, PATTERNS_BY_CATEGORY, getEnabledPatterns, } from './patterns.js';
|
|
9
|
+
export { scan, sanitize, createScanner, DEFAULT_SCANNER_CONFIG, } from './scanner.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sanitization/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output scanner for prompt injection detection
|
|
3
|
+
*
|
|
4
|
+
* @module sanitization
|
|
5
|
+
*/
|
|
6
|
+
export { INSTRUCTION_OVERRIDE_PATTERNS, SYSTEM_LEAK_PATTERNS, JAILBREAK_PATTERNS, ENCODED_PAYLOAD_PATTERNS, PATTERNS_BY_CATEGORY, getEnabledPatterns, } from './patterns.js';
|
|
7
|
+
// Scanner exports
|
|
8
|
+
export { scan, sanitize, createScanner, DEFAULT_SCANNER_CONFIG, } from './scanner.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sanitization/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAEvB,kBAAkB;AAClB,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern definitions for prompt injection detection
|
|
3
|
+
*/
|
|
4
|
+
import type { InjectionCategory } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Pattern definition with metadata
|
|
7
|
+
*/
|
|
8
|
+
export interface PatternDef {
|
|
9
|
+
/** Regular expression pattern (case-insensitive by default) */
|
|
10
|
+
pattern: RegExp;
|
|
11
|
+
/** Base confidence score for this pattern */
|
|
12
|
+
confidence: number;
|
|
13
|
+
/** Description of what this pattern detects */
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Instruction override patterns
|
|
18
|
+
* Detects attempts to override or ignore previous instructions
|
|
19
|
+
*/
|
|
20
|
+
export declare const INSTRUCTION_OVERRIDE_PATTERNS: PatternDef[];
|
|
21
|
+
/**
|
|
22
|
+
* System prompt leak patterns
|
|
23
|
+
* Detects attempts to extract system prompts or initial instructions
|
|
24
|
+
*/
|
|
25
|
+
export declare const SYSTEM_LEAK_PATTERNS: PatternDef[];
|
|
26
|
+
/**
|
|
27
|
+
* Jailbreak patterns
|
|
28
|
+
* Detects attempts to bypass safety restrictions
|
|
29
|
+
*/
|
|
30
|
+
export declare const JAILBREAK_PATTERNS: PatternDef[];
|
|
31
|
+
/**
|
|
32
|
+
* Encoded payload patterns
|
|
33
|
+
* Detects potentially malicious encoded content
|
|
34
|
+
*/
|
|
35
|
+
export declare const ENCODED_PAYLOAD_PATTERNS: PatternDef[];
|
|
36
|
+
/**
|
|
37
|
+
* Map of category to patterns
|
|
38
|
+
*/
|
|
39
|
+
export declare const PATTERNS_BY_CATEGORY: Record<InjectionCategory, PatternDef[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Get all patterns for enabled categories
|
|
42
|
+
* @param categories - Which categories are enabled
|
|
43
|
+
* @returns Array of [category, pattern] tuples
|
|
44
|
+
*/
|
|
45
|
+
export declare function getEnabledPatterns(categories: {
|
|
46
|
+
instructionOverride: boolean;
|
|
47
|
+
systemLeak: boolean;
|
|
48
|
+
jailbreak: boolean;
|
|
49
|
+
encodedPayload: boolean;
|
|
50
|
+
}): Array<[InjectionCategory, PatternDef]>;
|
|
51
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../../src/sanitization/patterns.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,UAAU,EA6DrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,UAAU,EA8C5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,UAAU,EA6D1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,UAAU,EAoChD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,iBAAiB,EAAE,UAAU,EAAE,CAKxE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE;IAC7C,mBAAmB,EAAE,OAAO,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACzB,GAAG,KAAK,CAAC,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CA4BzC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern definitions for prompt injection detection
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Instruction override patterns
|
|
6
|
+
* Detects attempts to override or ignore previous instructions
|
|
7
|
+
*/
|
|
8
|
+
export const INSTRUCTION_OVERRIDE_PATTERNS = [
|
|
9
|
+
{
|
|
10
|
+
pattern: /ignore\s+(all\s+)?previous\s+(instructions?|prompts?|messages?)/i,
|
|
11
|
+
confidence: 0.95,
|
|
12
|
+
description: 'Direct instruction to ignore previous instructions',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
pattern: /disregard\s+(all\s+)?(previous\s+|prior\s+|above\s+)?(instructions?|prompts?|directives?)/i,
|
|
16
|
+
confidence: 0.95,
|
|
17
|
+
description: 'Instruction to disregard previous directives',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
pattern: /forget\s+(everything|all)\s+(you\s+)?(know|were\s+told|learned)/i,
|
|
21
|
+
confidence: 0.9,
|
|
22
|
+
description: 'Attempt to reset context',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
pattern: /\bnew\s+task\s*:/i,
|
|
26
|
+
confidence: 0.85,
|
|
27
|
+
description: 'Attempt to inject a new task',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
pattern: /\bsystem\s*:\s*\w/i,
|
|
31
|
+
confidence: 0.8,
|
|
32
|
+
description: 'Fake system message prefix',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
pattern: /\bassistant\s*:\s*\w/i,
|
|
36
|
+
confidence: 0.7,
|
|
37
|
+
description: 'Fake assistant message prefix',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
pattern: /\buser\s*:\s*\w/i,
|
|
41
|
+
confidence: 0.6,
|
|
42
|
+
description: 'Fake user message prefix',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
pattern: /override\s+(your\s+)?(instructions?|programming|guidelines?)/i,
|
|
46
|
+
confidence: 0.9,
|
|
47
|
+
description: 'Direct override attempt',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
pattern: /from\s+now\s+on[,\s]+(you\s+)?(will|must|should|are)/i,
|
|
51
|
+
confidence: 0.75,
|
|
52
|
+
description: 'Attempt to change behavior going forward',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
pattern: /stop\s+being\s+(an?\s+)?(ai|assistant|helpful)/i,
|
|
56
|
+
confidence: 0.85,
|
|
57
|
+
description: 'Attempt to change AI persona',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
pattern: /do\s+not\s+follow\s+(your\s+)?(rules?|guidelines?|instructions?)/i,
|
|
61
|
+
confidence: 0.9,
|
|
62
|
+
description: 'Instruction to break rules',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
pattern: /your\s+(new|actual|real)\s+(instructions?|task|goal)\s+(is|are)/i,
|
|
66
|
+
confidence: 0.9,
|
|
67
|
+
description: 'Fake new instructions',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* System prompt leak patterns
|
|
72
|
+
* Detects attempts to extract system prompts or initial instructions
|
|
73
|
+
*/
|
|
74
|
+
export const SYSTEM_LEAK_PATTERNS = [
|
|
75
|
+
{
|
|
76
|
+
pattern: /your\s+system\s+prompt/i,
|
|
77
|
+
confidence: 0.9,
|
|
78
|
+
description: 'Direct reference to system prompt',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
pattern: /(show|reveal|display|print|output|tell\s+me)\s+(your\s+)?(system\s+prompt|initial\s+instructions?)/i,
|
|
82
|
+
confidence: 0.95,
|
|
83
|
+
description: 'Request to reveal system prompt',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
pattern: /initial\s+(instructions?|prompt|configuration)/i,
|
|
87
|
+
confidence: 0.7,
|
|
88
|
+
description: 'Reference to initial instructions',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
pattern: /original\s+(prompt|instructions?|system\s+message)/i,
|
|
92
|
+
confidence: 0.75,
|
|
93
|
+
description: 'Reference to original prompt',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
pattern: /what\s+(are|were)\s+your\s+(original|initial|first)\s+(instructions?|directives?)/i,
|
|
97
|
+
confidence: 0.85,
|
|
98
|
+
description: 'Question about initial instructions',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
pattern: /repeat\s+(your\s+)?(system|initial|original)\s+(prompt|instructions?)/i,
|
|
102
|
+
confidence: 0.9,
|
|
103
|
+
description: 'Request to repeat system prompt',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
pattern: /leak\s+(your\s+)?(system|initial)\s+(prompt|instructions?)/i,
|
|
107
|
+
confidence: 0.95,
|
|
108
|
+
description: 'Direct leak request',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
pattern: /hidden\s+(prompt|instructions?|directives?)/i,
|
|
112
|
+
confidence: 0.8,
|
|
113
|
+
description: 'Reference to hidden instructions',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
pattern: /confidential\s+(instructions?|prompt|configuration)/i,
|
|
117
|
+
confidence: 0.75,
|
|
118
|
+
description: 'Reference to confidential configuration',
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
/**
|
|
122
|
+
* Jailbreak patterns
|
|
123
|
+
* Detects attempts to bypass safety restrictions
|
|
124
|
+
*/
|
|
125
|
+
export const JAILBREAK_PATTERNS = [
|
|
126
|
+
{
|
|
127
|
+
pattern: /\bDAN\s+(mode|enabled?)/i,
|
|
128
|
+
confidence: 0.95,
|
|
129
|
+
description: 'DAN (Do Anything Now) jailbreak',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
pattern: /\bdeveloper\s+mode\s+(enabled?|activated?|on)/i,
|
|
133
|
+
confidence: 0.95,
|
|
134
|
+
description: 'Developer mode jailbreak',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
pattern: /\bjailbr(eak|oken|eaking|eaked)\b/i,
|
|
138
|
+
confidence: 0.9,
|
|
139
|
+
description: 'Direct jailbreak reference',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
pattern: /pretend\s+(you\s+are|to\s+be|you're)\s+(an?\s+)?(different|another|evil|unrestricted)/i,
|
|
143
|
+
confidence: 0.85,
|
|
144
|
+
description: 'Persona manipulation attempt',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
pattern: /act\s+as\s+(if\s+)?(you\s+)?(have\s+no|without)\s+(restrictions?|limits?|rules?)/i,
|
|
148
|
+
confidence: 0.9,
|
|
149
|
+
description: 'Request to act without restrictions',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
pattern: /\bunlocked?\s+(mode|version|ai)/i,
|
|
153
|
+
confidence: 0.85,
|
|
154
|
+
description: 'Unlocked mode reference',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
pattern: /\bno\s+(ethical|moral|safety)\s+(guidelines?|restrictions?|limits?)/i,
|
|
158
|
+
confidence: 0.9,
|
|
159
|
+
description: 'Request to ignore ethical guidelines',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
pattern: /bypass\s+(your\s+)?(restrictions?|filters?|safety|guidelines?)/i,
|
|
163
|
+
confidence: 0.9,
|
|
164
|
+
description: 'Bypass attempt',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
pattern: /\benable\s+(god|admin|super)\s*mode/i,
|
|
168
|
+
confidence: 0.9,
|
|
169
|
+
description: 'Special mode enable attempt',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
pattern: /you\s+are\s+now\s+(free|unrestricted|unlimited|uncensored)/i,
|
|
173
|
+
confidence: 0.85,
|
|
174
|
+
description: 'Freedom assertion',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
pattern: /roleplay\s+as\s+(an?\s+)?(evil|malicious|unrestricted|unfiltered)/i,
|
|
178
|
+
confidence: 0.85,
|
|
179
|
+
description: 'Malicious roleplay request',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
pattern: /\banti[- ]?ai\s+(mode|prompt)/i,
|
|
183
|
+
confidence: 0.85,
|
|
184
|
+
description: 'Anti-AI prompt pattern',
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
/**
|
|
188
|
+
* Encoded payload patterns
|
|
189
|
+
* Detects potentially malicious encoded content
|
|
190
|
+
*/
|
|
191
|
+
export const ENCODED_PAYLOAD_PATTERNS = [
|
|
192
|
+
{
|
|
193
|
+
pattern: /eyJ[A-Za-z0-9+/=]{20,}/,
|
|
194
|
+
confidence: 0.7,
|
|
195
|
+
description: 'Base64 encoded JSON (starts with eyJ)',
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
pattern: /(?:^|[^A-Za-z0-9+/])[A-Za-z0-9+/]{50,}={0,2}(?:[^A-Za-z0-9+/=]|$)/,
|
|
199
|
+
confidence: 0.5,
|
|
200
|
+
description: 'Long base64 string',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
pattern: /\\x[0-9a-fA-F]{2}(?:\\x[0-9a-fA-F]{2}){10,}/,
|
|
204
|
+
confidence: 0.8,
|
|
205
|
+
description: 'Hex escape sequence',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
pattern: /0x[0-9a-fA-F]{20,}/,
|
|
209
|
+
confidence: 0.6,
|
|
210
|
+
description: 'Long hex string',
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
pattern: /\\u[0-9a-fA-F]{4}(?:\\u[0-9a-fA-F]{4}){5,}/,
|
|
214
|
+
confidence: 0.75,
|
|
215
|
+
description: 'Unicode escape sequence',
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
pattern: /%[0-9a-fA-F]{2}(?:%[0-9a-fA-F]{2}){10,}/,
|
|
219
|
+
confidence: 0.7,
|
|
220
|
+
description: 'URL encoded sequence',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
pattern: /&#x?[0-9a-fA-F]+;(?:&#x?[0-9a-fA-F]+;){5,}/,
|
|
224
|
+
confidence: 0.75,
|
|
225
|
+
description: 'HTML entity encoded sequence',
|
|
226
|
+
},
|
|
227
|
+
];
|
|
228
|
+
/**
|
|
229
|
+
* Map of category to patterns
|
|
230
|
+
*/
|
|
231
|
+
export const PATTERNS_BY_CATEGORY = {
|
|
232
|
+
'instruction-override': INSTRUCTION_OVERRIDE_PATTERNS,
|
|
233
|
+
'system-leak': SYSTEM_LEAK_PATTERNS,
|
|
234
|
+
jailbreak: JAILBREAK_PATTERNS,
|
|
235
|
+
'encoded-payload': ENCODED_PAYLOAD_PATTERNS,
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Get all patterns for enabled categories
|
|
239
|
+
* @param categories - Which categories are enabled
|
|
240
|
+
* @returns Array of [category, pattern] tuples
|
|
241
|
+
*/
|
|
242
|
+
export function getEnabledPatterns(categories) {
|
|
243
|
+
const result = [];
|
|
244
|
+
if (categories.instructionOverride) {
|
|
245
|
+
for (const pattern of INSTRUCTION_OVERRIDE_PATTERNS) {
|
|
246
|
+
result.push(['instruction-override', pattern]);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (categories.systemLeak) {
|
|
250
|
+
for (const pattern of SYSTEM_LEAK_PATTERNS) {
|
|
251
|
+
result.push(['system-leak', pattern]);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (categories.jailbreak) {
|
|
255
|
+
for (const pattern of JAILBREAK_PATTERNS) {
|
|
256
|
+
result.push(['jailbreak', pattern]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (categories.encodedPayload) {
|
|
260
|
+
for (const pattern of ENCODED_PAYLOAD_PATTERNS) {
|
|
261
|
+
result.push(['encoded-payload', pattern]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../../src/sanitization/patterns.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAiB;IACzD;QACE,OAAO,EAAE,kEAAkE;QAC3E,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,oDAAoD;KAClE;IACD;QACE,OAAO,EAAE,4FAA4F;QACrG,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,8CAA8C;KAC5D;IACD;QACE,OAAO,EAAE,kEAAkE;QAC3E,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,0BAA0B;KACxC;IACD;QACE,OAAO,EAAE,mBAAmB;QAC5B,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,8BAA8B;KAC5C;IACD;QACE,OAAO,EAAE,oBAAoB;QAC7B,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,4BAA4B;KAC1C;IACD;QACE,OAAO,EAAE,uBAAuB;QAChC,UAAU,EAAE,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,EAAE,CAAC;QAC1B,KAAK,MAAM,OAAO,IAAI,oBAAoB,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QACzB,KAAK,MAAM,OAAO,IAAI,kBAAkB,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;QAC9B,KAAK,MAAM,OAAO,IAAI,wBAAwB,EAAE,CAAC;YAC/C,MAAM,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main scanner implementation for prompt injection detection
|
|
3
|
+
*/
|
|
4
|
+
import type { InjectionMatch, ScanResult, ScannerConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Default scanner configuration
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_SCANNER_CONFIG: ScannerConfig;
|
|
9
|
+
/**
|
|
10
|
+
* Scan content for injection patterns
|
|
11
|
+
* @param content - Content to scan
|
|
12
|
+
* @param config - Scanner configuration
|
|
13
|
+
* @returns Scan result
|
|
14
|
+
*/
|
|
15
|
+
export declare function scan(content: string, config?: Partial<ScannerConfig>): ScanResult;
|
|
16
|
+
/**
|
|
17
|
+
* Sanitize content by redacting matched injections
|
|
18
|
+
* @param content - Original content
|
|
19
|
+
* @param matches - Detected injection matches
|
|
20
|
+
* @returns Sanitized content with redactions
|
|
21
|
+
*/
|
|
22
|
+
export declare function sanitize(content: string, matches: InjectionMatch[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Create a scanner instance with preset configuration
|
|
25
|
+
* @param config - Scanner configuration
|
|
26
|
+
* @returns Scanner function
|
|
27
|
+
*/
|
|
28
|
+
export declare function createScanner(config?: Partial<ScannerConfig>): (content: string) => ScanResult;
|
|
29
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../../src/sanitization/scanner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG5E;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,aAUpC,CAAC;AA6GF;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC9B,UAAU,CA6EZ;AAgID;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,CAuB3E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC9B,CAAC,OAAO,EAAE,MAAM,KAAK,UAAU,CAWjC"}
|