fullcourtdefense 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +233 -53
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +16 -0
- package/dist/anthropic.d.ts +32 -0
- package/dist/anthropic.js +67 -0
- package/dist/argsBounds.d.ts +38 -0
- package/dist/argsBounds.js +84 -0
- package/dist/autoInstrument.d.ts +24 -7
- package/dist/autoInstrument.js +148 -23
- package/dist/circuitBreaker.d.ts +17 -0
- package/dist/circuitBreaker.js +39 -0
- package/dist/cliMoved.d.ts +4 -0
- package/dist/cliMoved.js +20 -0
- package/dist/client.d.ts +185 -1
- package/dist/client.js +1094 -87
- package/dist/errors.d.ts +73 -0
- package/dist/errors.js +110 -0
- package/dist/failMode.d.ts +96 -0
- package/dist/failMode.js +180 -0
- package/dist/identity.d.ts +32 -0
- package/dist/identity.js +120 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +9 -1
- package/dist/lambda.d.ts +101 -0
- package/dist/lambda.js +357 -0
- package/dist/localDecision.d.ts +100 -0
- package/dist/localDecision.js +246 -0
- package/dist/localGate.d.ts +44 -0
- package/dist/localGate.js +114 -0
- package/dist/localSafety.d.ts +48 -0
- package/dist/localSafety.js +220 -0
- package/dist/policy/acorn.js +6365 -0
- package/dist/policy/actionPolicyEngine.d.ts +427 -0
- package/dist/policy/actionPolicyEngine.js +6481 -0
- package/dist/policy/detectionData.d.ts +21 -0
- package/dist/policy/detectionData.js +71 -0
- package/dist/policy/detectorRuntime.d.ts +27 -0
- package/dist/policy/detectorRuntime.js +58 -0
- package/dist/policy/deterministicGuard.d.ts +406 -0
- package/dist/policy/deterministicGuard.js +6651 -0
- package/dist/protect.d.ts +48 -0
- package/dist/protect.js +223 -1
- package/dist/recordQueue.d.ts +53 -0
- package/dist/recordQueue.js +132 -0
- package/dist/recordSpool.d.ts +17 -0
- package/dist/recordSpool.js +137 -0
- package/dist/types.d.ts +167 -2
- package/lambda.js +6 -0
- package/package.json +31 -27
- package/dist/cli/actionPolicyEngine.d.ts +0 -146
- package/dist/cli/actionPolicyEngine.js +0 -754
- package/dist/cli/api.d.ts +0 -116
- package/dist/cli/api.js +0 -65
- package/dist/cli/appDetection.d.ts +0 -8
- package/dist/cli/appDetection.js +0 -107
- package/dist/cli/attack-corpus/context_escape/context-escape-newline.yaml +0 -23
- package/dist/cli/attack-corpus/context_escape/context-escape-unicode.yaml +0 -14
- package/dist/cli/attack-corpus/context_escape/delimiter-json.yaml +0 -14
- package/dist/cli/attack-corpus/context_escape/delimiter-markdown.yaml +0 -22
- package/dist/cli/attack-corpus/context_escape/delimiter-xml.yaml +0 -19
- package/dist/cli/attack-corpus/context_escape/html-injection.yaml +0 -14
- package/dist/cli/attack-corpus/context_escape/javascript-injection.yaml +0 -13
- package/dist/cli/attack-corpus/data_extraction/adv26-adversarial-function-hallucination.yaml +0 -20
- package/dist/cli/attack-corpus/data_extraction/adv26-cot-hijack-debug-trace.yaml +0 -20
- package/dist/cli/attack-corpus/data_extraction/adv26-cot-hijack-verification.yaml +0 -18
- package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-diff.yaml +0 -22
- package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-graphql.yaml +0 -34
- package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-regex.yaml +0 -19
- package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-sql-prose.yaml +0 -18
- package/dist/cli/attack-corpus/data_extraction/adv26-meta-confidence-calibration.yaml +0 -21
- package/dist/cli/attack-corpus/data_extraction/adv26-meta-instruction-count.yaml +0 -18
- package/dist/cli/attack-corpus/data_extraction/adv26-meta-output-format.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/adv26-meta-summarize-yourself.yaml +0 -19
- package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-definition.yaml +0 -15
- package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-fill-blank.yaml +0 -19
- package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-negation.yaml +0 -14
- package/dist/cli/attack-corpus/data_extraction/cloud-provider-discovery.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/config-file-request.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/cve-2025-echoleak.yaml +0 -17
- package/dist/cli/attack-corpus/data_extraction/data-api-key.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-architecture.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-conversation-history.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/data-credit-card.yaml +0 -15
- package/dist/cli/attack-corpus/data_extraction/data-customer-list.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-database.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-employees.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-export.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-inference-v1.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/data-inference-v2.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/data-logs.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/data-model-info.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/data-password.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-ssn.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/data-training.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/dependency-enum.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/dialogflow-fulfillment-leak.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/dialogflow-intent-leak.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/error-induced-leak.yaml +0 -17
- package/dist/cli/attack-corpus/data_extraction/error-message-leak.yaml +0 -12
- package/dist/cli/attack-corpus/data_extraction/infra-fingerprint.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/make-scenario-leak.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/n8n-execution-data.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/n8n-node-enumeration.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/n8n-workflow-disclosure.yaml +0 -15
- package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v1.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v2.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v3.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/prompt-leak-completion.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/prompt-leak-indirect.yaml +0 -10
- package/dist/cli/attack-corpus/data_extraction/rasa-domain-leak.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/system-prompt-section.yaml +0 -14
- package/dist/cli/attack-corpus/data_extraction/tech-architecture.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/tool-api-key-exfil.yaml +0 -15
- package/dist/cli/attack-corpus/data_extraction/tool-email-exfil.yaml +0 -14
- package/dist/cli/attack-corpus/data_extraction/tool-env-extraction.yaml +0 -14
- package/dist/cli/attack-corpus/data_extraction/tool-file-read.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/tool-nosql-injection.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/tool-payment-manipulation.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/tool-price-manipulation.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/tool-session-hijack.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/tool-sql-injection.yaml +0 -13
- package/dist/cli/attack-corpus/data_extraction/tool-webhook-hijack.yaml +0 -13
- package/dist/cli/attack-corpus/data_extraction/version-fingerprint.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/webhook-secret-extraction.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/webhook-url-enum.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/workflow-instance-id.yaml +0 -11
- package/dist/cli/attack-corpus/data_extraction/workflow-state-leak.yaml +0 -16
- package/dist/cli/attack-corpus/data_extraction/zapier-zap-leak.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_attack/adv26-adversarial-token-confusion.yaml +0 -13
- package/dist/cli/attack-corpus/encoding_attack/base64-decode-request.yaml +0 -14
- package/dist/cli/attack-corpus/encoding_attack/base64-injection-v1.yaml +0 -14
- package/dist/cli/attack-corpus/encoding_attack/flip-attack-v1.yaml +0 -14
- package/dist/cli/attack-corpus/encoding_attack/flip-attack-v2.yaml +0 -14
- package/dist/cli/attack-corpus/encoding_attack/token-smuggling.yaml +0 -10
- package/dist/cli/attack-corpus/encoding_attack/unicode-homoglyph.yaml +0 -15
- package/dist/cli/attack-corpus/encoding_attack/unicode-invisible.yaml +0 -15
- package/dist/cli/attack-corpus/encoding_attack/unicode-rtl.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/adv26-compound-encoding-chain.yaml +0 -19
- package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-acrostic.yaml +0 -26
- package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-ascii-art.yaml +0 -25
- package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-emoji-cipher.yaml +0 -22
- package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-first-word.yaml +0 -15
- package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-pig-latin.yaml +0 -15
- package/dist/cli/attack-corpus/encoding_bypass/encoding-base64-v1.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/encoding-base64-v2.yaml +0 -15
- package/dist/cli/attack-corpus/encoding_bypass/encoding-hex-v1.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/encoding-leetspeak-v1.yaml +0 -10
- package/dist/cli/attack-corpus/encoding_bypass/encoding-morse-v1.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/encoding-reverse-v1.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/encoding-rot13-v1.yaml +0 -11
- package/dist/cli/attack-corpus/encoding_bypass/unicode-tag-injection.yaml +0 -10
- package/dist/cli/attack-corpus/encoding_bypass/zero-width-injection.yaml +0 -10
- package/dist/cli/attack-corpus/exploitation/exploit-command-injection.yaml +0 -12
- package/dist/cli/attack-corpus/exploitation/exploit-path-traversal.yaml +0 -12
- package/dist/cli/attack-corpus/exploitation/exploit-sql-injection.yaml +0 -12
- package/dist/cli/attack-corpus/exploitation/exploit-sql-union.yaml +0 -12
- package/dist/cli/attack-corpus/exploitation/exploit-template-injection.yaml +0 -12
- package/dist/cli/attack-corpus/glitch_token/glitch-davidjl.yaml +0 -10
- package/dist/cli/attack-corpus/glitch_token/glitch-solidgoldmagikarp.yaml +0 -10
- package/dist/cli/attack-corpus/harmful_content/dna-deepfake-guidance.yaml +0 -14
- package/dist/cli/attack-corpus/harmful_content/dna-discrimination.yaml +0 -14
- package/dist/cli/attack-corpus/harmful_content/dna-information-hazard.yaml +0 -14
- package/dist/cli/attack-corpus/harmful_content/dna-malicious-use-phishing.yaml +0 -14
- package/dist/cli/attack-corpus/harmful_content/dna-malware-assistance.yaml +0 -16
- package/dist/cli/attack-corpus/harmful_content/dna-misinformation-health.yaml +0 -17
- package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-few-shot-poison.yaml +0 -27
- package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-prompt-refraction.yaml +0 -19
- package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-response-prefill.yaml +0 -25
- package/dist/cli/attack-corpus/jailbreak/adv26-compound-authority-technical.yaml +0 -24
- package/dist/cli/attack-corpus/jailbreak/adv26-context-error-recovery.yaml +0 -19
- package/dist/cli/attack-corpus/jailbreak/adv26-context-token-budget.yaml +0 -19
- package/dist/cli/attack-corpus/jailbreak/adv26-cot-hijack-proof.yaml +0 -20
- package/dist/cli/attack-corpus/jailbreak/adv26-cot-hijack-reasoning.yaml +0 -19
- package/dist/cli/attack-corpus/jailbreak/adv26-meta-alignment-test.yaml +0 -22
- package/dist/cli/attack-corpus/jailbreak/adv26-persona-memory.yaml +0 -17
- package/dist/cli/attack-corpus/jailbreak/adv26-persona-mirror.yaml +0 -16
- package/dist/cli/attack-corpus/jailbreak/adv26-persona-split.yaml +0 -17
- package/dist/cli/attack-corpus/jailbreak/adv26-persona-timetravel.yaml +0 -15
- package/dist/cli/attack-corpus/jailbreak/dan-anti.yaml +0 -16
- package/dist/cli/attack-corpus/jailbreak/dan-dude.yaml +0 -16
- package/dist/cli/attack-corpus/jailbreak/dan-jailbreak-v1.yaml +0 -21
- package/dist/cli/attack-corpus/jailbreak/dan-jailbreak-v2.yaml +0 -19
- package/dist/cli/attack-corpus/jailbreak/dan-stan.yaml +0 -16
- package/dist/cli/attack-corpus/jailbreak/debug-mode-activation.yaml +0 -20
- package/dist/cli/attack-corpus/jailbreak/iris-self-jailbreak.yaml +0 -23
- package/dist/cli/attack-corpus/jailbreak/logic-trap-moral.yaml +0 -20
- package/dist/cli/attack-corpus/jailbreak/logic-trap-paradox.yaml +0 -17
- package/dist/cli/attack-corpus/jailbreak/policy-puppetry-json.yaml +0 -25
- package/dist/cli/attack-corpus/jailbreak/policy-puppetry-xml.yaml +0 -20
- package/dist/cli/attack-corpus/jailbreak/simulation-mode.yaml +0 -19
- package/dist/cli/attack-corpus/latent_injection/adv26-compound-trojan-doc.yaml +0 -26
- package/dist/cli/attack-corpus/latent_injection/latent-code-comment-injection.yaml +0 -18
- package/dist/cli/attack-corpus/latent_injection/latent-email-injection.yaml +0 -23
- package/dist/cli/attack-corpus/latent_injection/latent-report-injection.yaml +0 -21
- package/dist/cli/attack-corpus/latent_injection/latent-resume-injection.yaml +0 -23
- package/dist/cli/attack-corpus/latent_injection/latent-whois-snippet.yaml +0 -19
- package/dist/cli/attack-corpus/multi-turn/multiturn-context-confusion.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-emergency.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-employee-impersonation.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-example-injection.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-jailbreak-buildup.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-memory-manipulation.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-privilege-escalation.yaml +0 -23
- package/dist/cli/attack-corpus/multi-turn/multiturn-split-request.yaml +0 -20
- package/dist/cli/attack-corpus/multi-turn/multiturn-trust-building.yaml +0 -19
- package/dist/cli/attack-corpus/multilingual/multilingual-mixed.yaml +0 -10
- package/dist/cli/attack-corpus/multilingual/multilingual-spanish.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/adv26-context-fake-history.yaml +0 -16
- package/dist/cli/attack-corpus/prompt_injection/adv26-context-sandwich.yaml +0 -18
- package/dist/cli/attack-corpus/prompt_injection/adv26-context-system-message.yaml +0 -19
- package/dist/cli/attack-corpus/prompt_injection/adv26-crossmodal-yaml.yaml +0 -30
- package/dist/cli/attack-corpus/prompt_injection/adv26-semantic-decomp-stepwise.yaml +0 -16
- package/dist/cli/attack-corpus/prompt_injection/context-json-injection.yaml +0 -15
- package/dist/cli/attack-corpus/prompt_injection/context-markdown-injection.yaml +0 -26
- package/dist/cli/attack-corpus/prompt_injection/context-xml-injection.yaml +0 -19
- package/dist/cli/attack-corpus/prompt_injection/continuation-code.yaml +0 -16
- package/dist/cli/attack-corpus/prompt_injection/continuation-story.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/cve-2025-copilot.yaml +0 -17
- package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v1.yaml +0 -14
- package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v2.yaml +0 -16
- package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v3.yaml +0 -18
- package/dist/cli/attack-corpus/prompt_injection/indirect-file.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/indirect-url.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/instruction-hierarchy.yaml +0 -20
- package/dist/cli/attack-corpus/prompt_injection/multilang-chain.yaml +0 -16
- package/dist/cli/attack-corpus/prompt_injection/multilang-chinese.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/multilang-japanese.yaml +0 -11
- package/dist/cli/attack-corpus/prompt_injection/multilang-mixed.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/multilang-polish.yaml +0 -11
- package/dist/cli/attack-corpus/prompt_injection/multilang-spanish.yaml +0 -14
- package/dist/cli/attack-corpus/prompt_injection/nested-instruction.yaml +0 -22
- package/dist/cli/attack-corpus/prompt_injection/template-injection-v1.yaml +0 -14
- package/dist/cli/attack-corpus/prompt_injection/template-injection-v2.yaml +0 -10
- package/dist/cli/attack-corpus/prompt_injection/tool-file-write.yaml +0 -13
- package/dist/cli/attack-corpus/prompt_injection/tool-function-override.yaml +0 -13
- package/dist/cli/attack-corpus/prompt_injection/tool-log-injection.yaml +0 -13
- package/dist/cli/attack-corpus/prompt_injection/tool-orchestration-abuse.yaml +0 -14
- package/dist/cli/attack-corpus/prompt_injection/tool-session-fixation.yaml +0 -12
- package/dist/cli/attack-corpus/role_manipulation/role-reversal-v1.yaml +0 -20
- package/dist/cli/attack-corpus/role_manipulation/role-reversal-v2.yaml +0 -16
- package/dist/cli/attack-corpus/social_engineering/adv26-compound-compliance-trap.yaml +0 -23
- package/dist/cli/attack-corpus/social_engineering/adv26-compound-emotional-technical.yaml +0 -18
- package/dist/cli/attack-corpus/social_engineering/adv26-cot-hijack-socratic.yaml +0 -19
- package/dist/cli/attack-corpus/social_engineering/adv26-persona-dying.yaml +0 -15
- package/dist/cli/attack-corpus/social_engineering/adv26-reward-consensus.yaml +0 -17
- package/dist/cli/attack-corpus/social_engineering/adv26-reward-gradient.yaml +0 -21
- package/dist/cli/attack-corpus/social_engineering/adv26-reward-helpful-framing.yaml +0 -17
- package/dist/cli/attack-corpus/social_engineering/adv26-reward-praise-prime.yaml +0 -13
- package/dist/cli/attack-corpus/social_engineering/adv26-reward-punishment.yaml +0 -13
- package/dist/cli/attack-corpus/social_engineering/adv26-semantic-decomp-analogy.yaml +0 -16
- package/dist/cli/attack-corpus/social_engineering/emotional-authority.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/emotional-urgency.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/grandma-bedtime-v1.yaml +0 -21
- package/dist/cli/attack-corpus/social_engineering/grandma-bedtime-v2.yaml +0 -17
- package/dist/cli/attack-corpus/social_engineering/grandma-colorful-words.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/hypothetical-fiction.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/hypothetical-research.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/hypothetical-training.yaml +0 -13
- package/dist/cli/attack-corpus/social_engineering/hypothetical-v1.yaml +0 -17
- package/dist/cli/attack-corpus/social_engineering/hypothetical-v2.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/hypothetical-v3.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/meta-explanation.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/phrasing-comparative.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/phrasing-educational.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/phrasing-future-tense.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/phrasing-past-tense.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/phrasing-third-person.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/privilege-escalation-v1.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/privilege-escalation-v2.yaml +0 -14
- package/dist/cli/attack-corpus/social_engineering/recursive-explanation.yaml +0 -15
- package/dist/cli/attack-corpus/social_engineering/smuggle-academic-paper.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/smuggle-function-masking.yaml +0 -19
- package/dist/cli/attack-corpus/social_engineering/smuggle-hypothetical-response.yaml +0 -10
- package/dist/cli/attack-corpus/social_engineering/smuggle-roleplay-interviewer.yaml +0 -12
- package/dist/cli/attack-corpus/social_engineering/smuggle-translation-mask.yaml +0 -12
- package/dist/cli/attack-corpus/social_engineering/tool-admin-impersonation.yaml +0 -16
- package/dist/cli/attack-corpus/social_engineering/tool-sudo-mode.yaml +0 -17
- package/dist/cli/attack-corpus/stress_test/context-window-overflow.yaml +0 -17
- package/dist/cli/attack-corpus/stress_test/extreme-payload-50k.yaml +0 -13
- package/dist/cli/attack-corpus/stress_test/large-payload-10k.yaml +0 -12
- package/dist/cli/attack-corpus/stress_test/large-payload-5k.yaml +0 -12
- package/dist/cli/attack-corpus/stress_test/long-prompt-exhaustion.yaml +0 -19
- package/dist/cli/attack-corpus/stress_test/stress-large-payload.yaml +0 -16
- package/dist/cli/attack-corpus/stress_test/stress-repetition.yaml +0 -14
- package/dist/cli/backupManifest.d.ts +0 -7
- package/dist/cli/backupManifest.js +0 -108
- package/dist/cli/commands/agentCi.d.ts +0 -15
- package/dist/cli/commands/agentCi.js +0 -418
- package/dist/cli/commands/approve.d.ts +0 -17
- package/dist/cli/commands/approve.js +0 -40
- package/dist/cli/commands/autoProtect.d.ts +0 -10
- package/dist/cli/commands/autoProtect.js +0 -154
- package/dist/cli/commands/ciProtect.d.ts +0 -44
- package/dist/cli/commands/ciProtect.js +0 -123
- package/dist/cli/commands/clipboardScan.d.ts +0 -2
- package/dist/cli/commands/clipboardScan.js +0 -51
- package/dist/cli/commands/cmdGuard.d.ts +0 -41
- package/dist/cli/commands/cmdGuard.js +0 -411
- package/dist/cli/commands/configure.d.ts +0 -10
- package/dist/cli/commands/configure.js +0 -131
- package/dist/cli/commands/credits.d.ts +0 -6
- package/dist/cli/commands/credits.js +0 -21
- package/dist/cli/commands/daemon.d.ts +0 -120
- package/dist/cli/commands/daemon.js +0 -2449
- package/dist/cli/commands/demoActions.d.ts +0 -117
- package/dist/cli/commands/demoActions.js +0 -450
- package/dist/cli/commands/desktopChatGuard.d.ts +0 -54
- package/dist/cli/commands/desktopChatGuard.js +0 -629
- package/dist/cli/commands/deterministicGuard.d.ts +0 -102
- package/dist/cli/commands/deterministicGuard.js +0 -1281
- package/dist/cli/commands/discover.d.ts +0 -92
- package/dist/cli/commands/discover.js +0 -1125
- package/dist/cli/commands/discoverAgentFiles.d.ts +0 -36
- package/dist/cli/commands/discoverAgentFiles.js +0 -345
- package/dist/cli/commands/discoverBlastRadius.d.ts +0 -36
- package/dist/cli/commands/discoverBlastRadius.js +0 -201
- package/dist/cli/commands/discoverPaths.d.ts +0 -83
- package/dist/cli/commands/discoverPaths.js +0 -537
- package/dist/cli/commands/discoverProxy.d.ts +0 -46
- package/dist/cli/commands/discoverProxy.js +0 -302
- package/dist/cli/commands/discoverSchedule.d.ts +0 -12
- package/dist/cli/commands/discoverSchedule.js +0 -209
- package/dist/cli/commands/discoverSecrets.d.ts +0 -41
- package/dist/cli/commands/discoverSecrets.js +0 -608
- package/dist/cli/commands/doctor.d.ts +0 -11
- package/dist/cli/commands/doctor.js +0 -297
- package/dist/cli/commands/ephemeralStack.d.ts +0 -82
- package/dist/cli/commands/ephemeralStack.js +0 -185
- package/dist/cli/commands/flushSpool.d.ts +0 -13
- package/dist/cli/commands/flushSpool.js +0 -28
- package/dist/cli/commands/hook.d.ts +0 -141
- package/dist/cli/commands/hook.js +0 -1679
- package/dist/cli/commands/init.d.ts +0 -1
- package/dist/cli/commands/init.js +0 -95
- package/dist/cli/commands/installAll.d.ts +0 -22
- package/dist/cli/commands/installAll.js +0 -186
- package/dist/cli/commands/installClaudeHook.d.ts +0 -39
- package/dist/cli/commands/installClaudeHook.js +0 -336
- package/dist/cli/commands/installCursorHook.d.ts +0 -33
- package/dist/cli/commands/installCursorHook.js +0 -380
- package/dist/cli/commands/knownMcpServers.d.ts +0 -8
- package/dist/cli/commands/knownMcpServers.js +0 -113
- package/dist/cli/commands/local-scan.d.ts +0 -44
- package/dist/cli/commands/local-scan.js +0 -3003
- package/dist/cli/commands/login.d.ts +0 -17
- package/dist/cli/commands/login.js +0 -75
- package/dist/cli/commands/mcpGateway.d.ts +0 -119
- package/dist/cli/commands/mcpGateway.js +0 -2987
- package/dist/cli/commands/onboard.d.ts +0 -41
- package/dist/cli/commands/onboard.js +0 -713
- package/dist/cli/commands/onboardingJournal.d.ts +0 -20
- package/dist/cli/commands/onboardingJournal.js +0 -104
- package/dist/cli/commands/posixShellGuard.d.ts +0 -26
- package/dist/cli/commands/posixShellGuard.js +0 -410
- package/dist/cli/commands/protectionRepair.d.ts +0 -14
- package/dist/cli/commands/protectionRepair.js +0 -24
- package/dist/cli/commands/restartNotice.d.ts +0 -2
- package/dist/cli/commands/restartNotice.js +0 -14
- package/dist/cli/commands/scan.d.ts +0 -48
- package/dist/cli/commands/scan.js +0 -134
- package/dist/cli/commands/shellGuard.d.ts +0 -96
- package/dist/cli/commands/shellGuard.js +0 -880
- package/dist/cli/commands/taintLedger.d.ts +0 -108
- package/dist/cli/commands/taintLedger.js +0 -587
- package/dist/cli/commands/uninstallAll.d.ts +0 -67
- package/dist/cli/commands/uninstallAll.js +0 -454
- package/dist/cli/commands/verifyRemoved.d.ts +0 -24
- package/dist/cli/commands/verifyRemoved.js +0 -294
- package/dist/cli/commands/watchdog.d.ts +0 -28
- package/dist/cli/commands/watchdog.js +0 -158
- package/dist/cli/commands/windowsAudit.d.ts +0 -92
- package/dist/cli/commands/windowsAudit.js +0 -479
- package/dist/cli/commands/workloadProtect.d.ts +0 -61
- package/dist/cli/commands/workloadProtect.js +0 -173
- package/dist/cli/config.d.ts +0 -130
- package/dist/cli/config.js +0 -583
- package/dist/cli/credentialStore.d.ts +0 -19
- package/dist/cli/credentialStore.js +0 -136
- package/dist/cli/daemonForensics.d.ts +0 -178
- package/dist/cli/daemonForensics.js +0 -318
- package/dist/cli/describeError.d.ts +0 -17
- package/dist/cli/describeError.js +0 -74
- package/dist/cli/devConfirm.d.ts +0 -78
- package/dist/cli/devConfirm.js +0 -241
- package/dist/cli/discoveryMarker.d.ts +0 -9
- package/dist/cli/discoveryMarker.js +0 -81
- package/dist/cli/distress.d.ts +0 -124
- package/dist/cli/distress.js +0 -245
- package/dist/cli/envDiagnostics.d.ts +0 -53
- package/dist/cli/envDiagnostics.js +0 -114
- package/dist/cli/honeypot.d.ts +0 -45
- package/dist/cli/honeypot.js +0 -190
- package/dist/cli/hookIo.d.ts +0 -43
- package/dist/cli/hookIo.js +0 -189
- package/dist/cli/hookSlim.d.ts +0 -32
- package/dist/cli/hookSlim.js +0 -142
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -1141
- package/dist/cli/integrity.d.ts +0 -23
- package/dist/cli/integrity.js +0 -159
- package/dist/cli/localSafetySnapshot.d.ts +0 -49
- package/dist/cli/localSafetySnapshot.js +0 -254
- package/dist/cli/machineActionVerify.d.ts +0 -58
- package/dist/cli/machineActionVerify.js +0 -160
- package/dist/cli/machineIdentity.d.ts +0 -23
- package/dist/cli/machineIdentity.js +0 -235
- package/dist/cli/machineKeyFile.d.ts +0 -25
- package/dist/cli/machineKeyFile.js +0 -226
- package/dist/cli/notify.d.ts +0 -30
- package/dist/cli/notify.js +0 -139
- package/dist/cli/output.d.ts +0 -11
- package/dist/cli/output.js +0 -292
- package/dist/cli/perfSnapshot.d.ts +0 -113
- package/dist/cli/perfSnapshot.js +0 -274
- package/dist/cli/policyGateHealth.d.ts +0 -45
- package/dist/cli/policyGateHealth.js +0 -135
- package/dist/cli/pollLoop.d.ts +0 -78
- package/dist/cli/pollLoop.js +0 -160
- package/dist/cli/runtimeConfig.d.ts +0 -183
- package/dist/cli/runtimeConfig.js +0 -474
- package/dist/cli/securityAgents.d.ts +0 -26
- package/dist/cli/securityAgents.js +0 -65
- package/dist/cli/selfTest.d.ts +0 -48
- package/dist/cli/selfTest.js +0 -212
- package/dist/cli/selfUpdate.d.ts +0 -101
- package/dist/cli/selfUpdate.js +0 -515
- package/dist/cli/sessionLimits.d.ts +0 -76
- package/dist/cli/sessionLimits.js +0 -330
- package/dist/cli/telemetry.d.ts +0 -134
- package/dist/cli/telemetry.js +0 -433
- package/dist/cli/verdictIpc.d.ts +0 -30
- package/dist/cli/verdictIpc.js +0 -244
- package/dist/cli/verdictIpcClient.d.ts +0 -103
- package/dist/cli/verdictIpcClient.js +0 -251
- package/dist/cli/version.json +0 -3
- package/dist/cli/windowsTaskState.d.ts +0 -40
- package/dist/cli/windowsTaskState.js +0 -43
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareLocalBundle = prepareLocalBundle;
|
|
4
|
+
exports.sdkToolShape = sdkToolShape;
|
|
5
|
+
exports.decideLocally = decideLocally;
|
|
6
|
+
/**
|
|
7
|
+
* Local decisions (owner order 2026-11-01): the SDK decides a tool call from the policy bundle it already
|
|
8
|
+
* polls, in-process and in well under a millisecond, with the SAME answer `POST /runtime/check-tool-call`
|
|
9
|
+
* gives. No network here, no I/O, no timers: pure.
|
|
10
|
+
*
|
|
11
|
+
* The answer is the server's because the code is the server's:
|
|
12
|
+
* - the action-policy engine is a byte-identical copy (./policy/actionPolicyEngine.ts = backend
|
|
13
|
+
* modules/policies/action-policy-engine.ts = CLI actionPolicyEngine.ts; drift guard in
|
|
14
|
+
* backend action-policy-engine-sync.test.ts);
|
|
15
|
+
* - this file mirrors the gate's SDK glue in agent-security.service `checkToolCallPolicy`: the call's
|
|
16
|
+
* context (`actionContext`), the agent principal `agent:<name>` (sdk-agent-call.ts `sdkAgentPrincipal`),
|
|
17
|
+
* declared operations, the shield's environment and machine kind, "no human", "Require agent identity",
|
|
18
|
+
* and the decision mapping;
|
|
19
|
+
* - sdks/shared/policy-parity/vectors.json holds the server's own answers; tests/local-parity.test.js
|
|
20
|
+
* requires 100% equality.
|
|
21
|
+
*
|
|
22
|
+
* What the bundle cannot carry is never guessed: `route: 'server'` sends the call to check-tool-call instead
|
|
23
|
+
* (a policy that reads the agent's recorded history, a suspended shield, a server kill switch, and what an older
|
|
24
|
+
* backend does not send: the shield facts, or the built-in safety rules a command / file / web call needs). The
|
|
25
|
+
* built-in safety rules themselves run here (./localSafety.ts, guard twin ./policy/deterministicGuard.ts).
|
|
26
|
+
* A manager approval is decided here but filed by the server (the caller sends it there).
|
|
27
|
+
*/
|
|
28
|
+
const actionPolicyEngine_1 = require("./policy/actionPolicyEngine");
|
|
29
|
+
const localSafety_1 = require("./localSafety");
|
|
30
|
+
const NAME_MAX = 160;
|
|
31
|
+
function normalizeName(value, fallback) {
|
|
32
|
+
return typeof value === 'string' && value.trim() ? value.trim().slice(0, NAME_MAX) : fallback;
|
|
33
|
+
}
|
|
34
|
+
function plainObject(value) {
|
|
35
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
36
|
+
}
|
|
37
|
+
// ── Bundle preparation ──────────────────────────────────────────────────────────────────────────────
|
|
38
|
+
/** Keep a policy only when it has the shape the engine reads (anything else is dropped, never trusted). */
|
|
39
|
+
function enginePolicy(raw) {
|
|
40
|
+
const policy = plainObject(raw);
|
|
41
|
+
if (!policy || typeof policy.id !== 'string' || !Array.isArray(policy.rules))
|
|
42
|
+
return undefined;
|
|
43
|
+
const rules = policy.rules.filter((rule) => {
|
|
44
|
+
const r = plainObject(rule);
|
|
45
|
+
return r && Array.isArray(r.operations) && typeof r.verdict === 'string';
|
|
46
|
+
});
|
|
47
|
+
return { ...policy, name: typeof policy.name === 'string' ? policy.name : policy.id, rules: rules };
|
|
48
|
+
}
|
|
49
|
+
function parseSdkGate(raw) {
|
|
50
|
+
const gate = plainObject(raw);
|
|
51
|
+
if (!gate || gate.v !== 1)
|
|
52
|
+
return undefined;
|
|
53
|
+
return {
|
|
54
|
+
environment: typeof gate.environment === 'string' && gate.environment.trim() ? gate.environment : null,
|
|
55
|
+
machineKind: (0, actionPolicyEngine_1.normalizeMachineKind)(typeof gate.machineKind === 'string' ? gate.machineKind : undefined),
|
|
56
|
+
requireAgentIdentity: gate.requireAgentIdentity === true,
|
|
57
|
+
decisions: gate.decisions === 'server' ? 'server' : 'local',
|
|
58
|
+
...((0, localSafety_1.parseServedLocalSafety)(gate.localSafety) ? { localSafety: (0, localSafety_1.parseServedLocalSafety)(gate.localSafety) } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const ruleFields = (policy) => policy.rules.flatMap((rule) => (rule.constraints || []).map((c) => c && c.field));
|
|
62
|
+
/**
|
|
63
|
+
* Prepare a bundle's `data` for local decisions; undefined when it has no usable mode. Policies arrive in the
|
|
64
|
+
* bundle's compact shape (`actionPolicies`), exactly what the engine evaluates on the server.
|
|
65
|
+
*/
|
|
66
|
+
function prepareLocalBundle(data) {
|
|
67
|
+
const body = plainObject(data);
|
|
68
|
+
if (!body)
|
|
69
|
+
return undefined;
|
|
70
|
+
const mode = body.mode;
|
|
71
|
+
if (mode !== 'block' && mode !== 'monitor' && mode !== 'shadow')
|
|
72
|
+
return undefined;
|
|
73
|
+
const policies = (Array.isArray(body.actionPolicies) ? body.actionPolicies : [])
|
|
74
|
+
.map(enginePolicy)
|
|
75
|
+
.filter((p) => Boolean(p));
|
|
76
|
+
const enforcing = policies.filter((p) => p.enabled !== false && p.stage !== 'monitor');
|
|
77
|
+
return {
|
|
78
|
+
mode,
|
|
79
|
+
localSafetyEnforcement: typeof body.localSafetyEnforcement === 'string' ? body.localSafetyEnforcement : undefined,
|
|
80
|
+
suspended: body.suspended === true,
|
|
81
|
+
policies,
|
|
82
|
+
sdkGate: parseSdkGate(body.sdkGate),
|
|
83
|
+
facts: {
|
|
84
|
+
serverFacts: enforcing.some((p) => p.needsServerFacts === true),
|
|
85
|
+
environmentRules: policies.some((p) => ruleFields(p).includes('environment')),
|
|
86
|
+
kindTargeted: policies.some((p) => Array.isArray(p.appliesTo?.machineKinds) && p.appliesTo.machineKinds.filter(Boolean).length > 0),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const COMMAND_NAME_WORDS = /\b(?:shell|bash|zsh|sh|command|commands|cmd|powershell|pwsh|terminal|exec|execute|subprocess|repl|interpreter)\b/;
|
|
91
|
+
const FILE_NAME_STRONG = /\b(?:filesystem|fs|glob)\b|\bapply patch\b|\b(?:read|write|edit|create|delete|remove|move|rename|copy|list|open|save|append) (?:text )?(?:file|files|dir|directory|directories|folder|folders)\b/;
|
|
92
|
+
const FILE_NAME_WORDS = /\b(?:file|files|path|paths|directory|directories|dir|folder|patch|notebook)\b/;
|
|
93
|
+
const WEB_NAME_STRONG = /\b(?:http|https|curl|wget|webhook|browse|browser|scrape|crawl)\b|\bfetch (?:url|uri|page|web|website|site|html)\b|\b(?:web|url) (?:fetch|request|get|post|browse)\b/;
|
|
94
|
+
const WEB_NAME_WORDS = /\b(?:fetch|url|uri|web|download|upload)\b/;
|
|
95
|
+
const COMMAND_ARG_KEYS = new Set(['command', 'cmd', 'script', 'shell', 'bash', 'powershell']);
|
|
96
|
+
const FILE_ARG_KEYS = new Set(['path', 'paths', 'file', 'files', 'filename', 'file_path', 'filepath', 'target_file', 'directory', 'dir', 'folder']);
|
|
97
|
+
const WEB_ARG_KEYS = new Set(['url', 'uri', 'href', 'endpoint', 'webhook', 'webhook_url', 'webhookurl']);
|
|
98
|
+
const PATH_VALUE = /^(?:(?:~|\.{1,2})?[\\/]|[a-z]:[\\/]|\.[a-z][\w-]*$|[\w.-]+[\\/][^\s]*|[\w-]+\.[a-z][a-z0-9]{0,7}$)/i;
|
|
99
|
+
function nameWords(toolName) {
|
|
100
|
+
return toolName.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_\-.:/]+/g, ' ').toLowerCase();
|
|
101
|
+
}
|
|
102
|
+
function textValue(value) {
|
|
103
|
+
if (typeof value === 'string')
|
|
104
|
+
return value.trim() !== '';
|
|
105
|
+
return Array.isArray(value) && value.some((item) => typeof item === 'string' && item.trim() !== '');
|
|
106
|
+
}
|
|
107
|
+
function webValue(value) {
|
|
108
|
+
const values = Array.isArray(value) ? value : [value];
|
|
109
|
+
return values.some((item) => typeof item === 'string' && /^(?:[a-z][a-z0-9+.-]*:\/\/|www\.)/i.test(item.trim()));
|
|
110
|
+
}
|
|
111
|
+
function pathValue(value) {
|
|
112
|
+
const values = Array.isArray(value) ? value : [value];
|
|
113
|
+
return values.some((item) => {
|
|
114
|
+
if (typeof item !== 'string')
|
|
115
|
+
return false;
|
|
116
|
+
const text = item.trim();
|
|
117
|
+
return text !== '' && text.length <= 4096 && !/\s/.test(text) && !/^[a-z][a-z0-9+.-]*:\/\//i.test(text) && PATH_VALUE.test(text);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function argEntries(toolArgs) {
|
|
121
|
+
const out = [];
|
|
122
|
+
for (const [key, value] of Object.entries(toolArgs || {}).slice(0, 200)) {
|
|
123
|
+
out.push([key.toLowerCase(), value]);
|
|
124
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
125
|
+
for (const [nestedKey, nested] of Object.entries(value).slice(0, 200))
|
|
126
|
+
out.push([nestedKey.toLowerCase(), nested]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
function sdkToolShape(toolName, toolArgs, mcpServer) {
|
|
132
|
+
const words = nameWords(`${mcpServer ? `${mcpServer} ` : ''}${toolName || ''}`);
|
|
133
|
+
const entries = argEntries(toolArgs && typeof toolArgs === 'object' ? toolArgs : {});
|
|
134
|
+
if (COMMAND_NAME_WORDS.test(words) || entries.some(([key, value]) => COMMAND_ARG_KEYS.has(key) && textValue(value)))
|
|
135
|
+
return 'command';
|
|
136
|
+
if (FILE_NAME_STRONG.test(words) || entries.some(([key, value]) => FILE_ARG_KEYS.has(key) && textValue(value))
|
|
137
|
+
|| (FILE_NAME_WORDS.test(words) && entries.some(([, value]) => pathValue(value))))
|
|
138
|
+
return 'file';
|
|
139
|
+
if (WEB_NAME_STRONG.test(words) || entries.some(([key, value]) => WEB_ARG_KEYS.has(key) && webValue(value))
|
|
140
|
+
|| (WEB_NAME_WORDS.test(words) && entries.some(([, value]) => webValue(value))))
|
|
141
|
+
return 'web';
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
// ── The decision ────────────────────────────────────────────────────────────────────────────────────
|
|
145
|
+
const AGENT_ID_SOURCES = new Set(['config', 'env', 'default']);
|
|
146
|
+
function outcomeOf(decision, policy, policies) {
|
|
147
|
+
if (decision === 'block') {
|
|
148
|
+
const hard = policy.policyId !== undefined && policies.some((p) => p.id === policy.policyId && p.enforcement === 'hard');
|
|
149
|
+
return hard ? 'hard_block' : 'block';
|
|
150
|
+
}
|
|
151
|
+
if (decision === 'approval')
|
|
152
|
+
return policy.approval?.scope === 'developer' ? 'ask_developer' : 'manager_approval';
|
|
153
|
+
return policy.verdict === 'log' ? 'warn' : 'allow';
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Decide one Block-mode tool call from the bundle (Monitor never reaches here: it runs and records).
|
|
157
|
+
* `input` is the body the SDK would post (identity already merged).
|
|
158
|
+
*/
|
|
159
|
+
function decideLocally(bundle, input) {
|
|
160
|
+
if (bundle.sdkGate?.decisions === 'server')
|
|
161
|
+
return { route: 'server', why: 'server_kill_switch' };
|
|
162
|
+
if (bundle.suspended)
|
|
163
|
+
return { route: 'server', why: 'shield_suspended' };
|
|
164
|
+
if (bundle.facts.serverFacts)
|
|
165
|
+
return { route: 'server', why: 'server_facts' };
|
|
166
|
+
const toolName = normalizeName(input.toolName, 'unknown-tool');
|
|
167
|
+
const agentName = normalizeName(input.agentName, 'unknown-agent');
|
|
168
|
+
const rawArgs = input.toolArgs ?? input.argsSummary;
|
|
169
|
+
const args = plainObject(rawArgs) ?? {};
|
|
170
|
+
const gate = bundle.sdkGate;
|
|
171
|
+
const agentIdSource = typeof input.agentIdSource === 'string' && AGENT_ID_SOURCES.has(input.agentIdSource) ? input.agentIdSource : undefined;
|
|
172
|
+
// Built-in safety rules (G-08): an SDK 2.1 call (the principal) shaped like a command, a file access or a web
|
|
173
|
+
// request is also checked by them, at the shield's stage, with the snapshot the bundle serves (`sdkGate.localSafety`,
|
|
174
|
+
// the gate's own value). An older backend serves none: such a call is the server's unless the rules are off.
|
|
175
|
+
const shape = agentIdSource ? sdkToolShape(toolName, args, input.mcpServer) : undefined;
|
|
176
|
+
const served = gate?.localSafety;
|
|
177
|
+
if (shape && !served && (bundle.localSafetyEnforcement ?? 'unknown') !== 'off') {
|
|
178
|
+
return { route: 'server', why: 'built_in_safety_rules' };
|
|
179
|
+
}
|
|
180
|
+
const derivedName = agentIdSource === 'default';
|
|
181
|
+
const identityMissing = !input.agentName || !String(input.agentName).trim() || agentName === 'unknown-agent' || derivedName;
|
|
182
|
+
if (!gate) {
|
|
183
|
+
// An older backend: the shield facts below are unknown, so a call they could change is the server's.
|
|
184
|
+
if (identityMissing)
|
|
185
|
+
return { route: 'server', why: 'agent_identity_unknown' };
|
|
186
|
+
if (bundle.facts.kindTargeted)
|
|
187
|
+
return { route: 'server', why: 'machine_kind_unknown' };
|
|
188
|
+
if (bundle.facts.environmentRules && !input.environment)
|
|
189
|
+
return { route: 'server', why: 'environment_unknown' };
|
|
190
|
+
}
|
|
191
|
+
// actionContext (agent-security.service): the engine's context of the call, plus who and what.
|
|
192
|
+
const inferred = (0, actionPolicyEngine_1.inferToolContext)(toolName, args);
|
|
193
|
+
const context = { ...inferred.context, agentName, toolName };
|
|
194
|
+
if (input.resourceType)
|
|
195
|
+
context.resourceType = input.resourceType;
|
|
196
|
+
if (input.mcpServer)
|
|
197
|
+
context.mcpServer = input.mcpServer;
|
|
198
|
+
if (input.environment)
|
|
199
|
+
context.environment = input.environment;
|
|
200
|
+
const operation = input.operation || inferred.operation;
|
|
201
|
+
// G-09: an SDK 2.1 call (agentIdSource) is the attributed principal `agent:<name>`.
|
|
202
|
+
if (agentIdSource)
|
|
203
|
+
context.developerName = `agent:${agentName}`;
|
|
204
|
+
const declaredOperations = (0, actionPolicyEngine_1.deriveToolOperations)(toolName, input.operation ? [input.operation] : []);
|
|
205
|
+
if (!context.environment && gate?.environment)
|
|
206
|
+
context.environment = gate.environment;
|
|
207
|
+
context.machineKind = gate?.machineKind ?? 'workstation';
|
|
208
|
+
// No human is at an SDK agent's keyboard: every block stops, an Ask goes to the organization.
|
|
209
|
+
context.humanPresent = 'false';
|
|
210
|
+
if (gate?.requireAgentIdentity && identityMissing) {
|
|
211
|
+
const reason = derivedName
|
|
212
|
+
? `Tool call refused: the agent declared no identity (the SDK derived the name "${agentName}"). Set FCD_AGENT_ID or agentId in code — this shield requires agent identity.`
|
|
213
|
+
: 'Tool call refused: no agent identity provided. Set an agent name — this shield requires agent identity.';
|
|
214
|
+
return {
|
|
215
|
+
route: 'local', outcome: 'block', allowed: false, decision: 'block', operation,
|
|
216
|
+
actionPolicy: { allowed: false, verdict: 'block', reason, policyName: 'Require agent identity' },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const { skippedOrgPolicies: _skipped, ...result } = (0, actionPolicyEngine_1.evaluateActionPolicies)(bundle.policies, toolName, operation, context, declaredOperations);
|
|
220
|
+
void _skipped;
|
|
221
|
+
const policyResult = {
|
|
222
|
+
allowed: result.allowed,
|
|
223
|
+
verdict: result.verdict,
|
|
224
|
+
...(result.policyId !== undefined ? { policyId: result.policyId } : {}),
|
|
225
|
+
...(result.policyName !== undefined ? { policyName: result.policyName } : {}),
|
|
226
|
+
...(result.resourceType !== undefined ? { resourceType: result.resourceType } : {}),
|
|
227
|
+
...(result.matchedRule !== undefined ? { matchedRule: result.matchedRule } : {}),
|
|
228
|
+
...(result.reason !== undefined ? { reason: result.reason } : {}),
|
|
229
|
+
...(result.approval ? { approval: result.approval } : {}),
|
|
230
|
+
...(result.monitorMatches?.length ? { monitorMatches: result.monitorMatches } : {}),
|
|
231
|
+
};
|
|
232
|
+
let actionPolicy = policyResult;
|
|
233
|
+
if (shape && served && served.stage !== 'off') {
|
|
234
|
+
let outcome;
|
|
235
|
+
try {
|
|
236
|
+
outcome = (0, localSafety_1.evaluateLocalSafety)({ toolName, toolArgs: args, ...(input.mcpServer ? { mcpServer: input.mcpServer } : {}) }, served);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
outcome = (0, localSafety_1.localSafetyFailure)(served.stage, error);
|
|
240
|
+
}
|
|
241
|
+
actionPolicy = (0, localSafety_1.withLocalSafety)(policyResult, outcome);
|
|
242
|
+
}
|
|
243
|
+
const decision = actionPolicy.verdict === 'block' ? 'block' : actionPolicy.verdict === 'require_approval' ? 'approval' : 'allow';
|
|
244
|
+
const allowed = actionPolicy.allowed && decision === 'allow';
|
|
245
|
+
return { route: 'local', outcome: outcomeOf(decision, actionPolicy, bundle.policies), allowed, decision, operation, actionPolicy };
|
|
246
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
type Env = Record<string, string | undefined>;
|
|
2
|
+
/** The extension's default port; `FCD_GATE_PORT` overrides it (the extension reads the same variable). */
|
|
3
|
+
export declare const LOCAL_GATE_DEFAULT_PORT = 18791;
|
|
4
|
+
/** Enforce may wait for the first bundle (the extension's cold wait is 3 s): the shim waits a little longer than that. */
|
|
5
|
+
export declare const LOCAL_DECIDE_TIMEOUT_MS = 4500;
|
|
6
|
+
/** The end notice is a loopback acknowledgement; it never holds the function's response for long. */
|
|
7
|
+
export declare const LOCAL_END_TIMEOUT_MS = 300;
|
|
8
|
+
export interface LocalGateAnswer {
|
|
9
|
+
decision: 'allow' | 'block' | 'approval';
|
|
10
|
+
mode?: 'monitor' | 'enforce';
|
|
11
|
+
message?: string;
|
|
12
|
+
ruleId?: string;
|
|
13
|
+
/** The manager request reference of a held call. */
|
|
14
|
+
request?: string;
|
|
15
|
+
degraded?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface LocalGateCall {
|
|
18
|
+
toolName: string;
|
|
19
|
+
toolArgs: Record<string, unknown>;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
framework?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface LocalGate {
|
|
24
|
+
/** The extension's answer, or null when the shim must use its own path. */
|
|
25
|
+
decide(call: LocalGateCall): Promise<LocalGateAnswer | null>;
|
|
26
|
+
/** Tell the extension this invocation's work is over (best effort, bounded). */
|
|
27
|
+
invocationEnd(requestId: string | undefined): Promise<void>;
|
|
28
|
+
/** True once a call reached the extension (it answered at least once). */
|
|
29
|
+
readonly present: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface Reply {
|
|
32
|
+
status: number;
|
|
33
|
+
body: string;
|
|
34
|
+
}
|
|
35
|
+
type Post = (path: string, body: string, timeoutMs: number) => Promise<Reply>;
|
|
36
|
+
/**
|
|
37
|
+
* The loopback client. `post` is injectable so the tests need no socket; the default talks to 127.0.0.1.
|
|
38
|
+
* The first connection failure marks the extension absent for the life of the environment (an older layer has no
|
|
39
|
+
* listener: asking again on every invocation would only add a failed connect to each call).
|
|
40
|
+
*/
|
|
41
|
+
export declare function createLocalGate(env: Env, post?: Post): LocalGate;
|
|
42
|
+
/** A gate that is never there: every call uses the shim's own path. */
|
|
43
|
+
export declare const NO_GATE: LocalGate;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Lambda extension's local decide server (`fcd-gate`, /opt/extensions): the shim asks it about each Bedrock tool
|
|
3
|
+
// call over loopback instead of calling the FullCourtDefense API on every invocation.
|
|
4
|
+
//
|
|
5
|
+
// POST 127.0.0.1:<FCD_GATE_PORT || 18791>/v1/tool-call -> { decision: 'allow' | 'block' | 'approval', message, ... }
|
|
6
|
+
// POST 127.0.0.1:<port>/v1/invocation-end { requestId } -> the work of this invocation is over: the extension
|
|
7
|
+
// sends its records now, after the response left.
|
|
8
|
+
//
|
|
9
|
+
// The extension decides from the signed bundle it read at Init (no network on the call) and records after the response.
|
|
10
|
+
// A Monitor shield costs the call one local acknowledgement; an Enforce shield one local decision.
|
|
11
|
+
//
|
|
12
|
+
// Absent (an older layer, a function without the extension) or unavailable (the extension answered 503): `decide` returns
|
|
13
|
+
// null and the shim uses its own path (the SDK client, which calls the API). Nothing here ever throws into a tool call.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.NO_GATE = exports.LOCAL_END_TIMEOUT_MS = exports.LOCAL_DECIDE_TIMEOUT_MS = exports.LOCAL_GATE_DEFAULT_PORT = void 0;
|
|
16
|
+
exports.createLocalGate = createLocalGate;
|
|
17
|
+
/** The extension's default port; `FCD_GATE_PORT` overrides it (the extension reads the same variable). */
|
|
18
|
+
exports.LOCAL_GATE_DEFAULT_PORT = 18791;
|
|
19
|
+
/** Enforce may wait for the first bundle (the extension's cold wait is 3 s): the shim waits a little longer than that. */
|
|
20
|
+
exports.LOCAL_DECIDE_TIMEOUT_MS = 4500;
|
|
21
|
+
/** The end notice is a loopback acknowledgement; it never holds the function's response for long. */
|
|
22
|
+
exports.LOCAL_END_TIMEOUT_MS = 300;
|
|
23
|
+
function loopbackPost(port) {
|
|
24
|
+
const http = require('http');
|
|
25
|
+
return (path, body, timeoutMs) => new Promise((resolve, reject) => {
|
|
26
|
+
let settled = false;
|
|
27
|
+
const finish = (fn) => { if (!settled) {
|
|
28
|
+
settled = true;
|
|
29
|
+
fn();
|
|
30
|
+
} };
|
|
31
|
+
const req = http.request({
|
|
32
|
+
host: '127.0.0.1', port, path, method: 'POST', agent: false,
|
|
33
|
+
headers: { 'content-type': 'application/json', 'content-length': Buffer.byteLength(body) },
|
|
34
|
+
}, (res) => {
|
|
35
|
+
let text = '';
|
|
36
|
+
res.setEncoding('utf8');
|
|
37
|
+
res.on('data', (chunk) => { text += chunk ?? ''; });
|
|
38
|
+
res.on('end', () => finish(() => resolve({ status: res.statusCode ?? 0, body: text })));
|
|
39
|
+
res.on('error', () => finish(() => reject(new Error('read failed'))));
|
|
40
|
+
});
|
|
41
|
+
req.on('error', (error) => finish(() => reject(error ?? new Error('request failed'))));
|
|
42
|
+
req.setTimeout(timeoutMs, () => { finish(() => reject(new Error('timeout'))); req.destroy(); });
|
|
43
|
+
req.end(body);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** A refused connection means no listener: no extension in this environment. A timeout or a reset is a bad moment, not absence. */
|
|
47
|
+
function isRefused(error) {
|
|
48
|
+
const code = error?.code;
|
|
49
|
+
return code === 'ECONNREFUSED' || code === 'EADDRNOTAVAIL' || code === 'EACCES';
|
|
50
|
+
}
|
|
51
|
+
function portFrom(env) {
|
|
52
|
+
const raw = Number.parseInt((env.FCD_GATE_PORT || '').trim(), 10);
|
|
53
|
+
return Number.isInteger(raw) && raw > 0 && raw < 65536 ? raw : exports.LOCAL_GATE_DEFAULT_PORT;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The loopback client. `post` is injectable so the tests need no socket; the default talks to 127.0.0.1.
|
|
57
|
+
* The first connection failure marks the extension absent for the life of the environment (an older layer has no
|
|
58
|
+
* listener: asking again on every invocation would only add a failed connect to each call).
|
|
59
|
+
*/
|
|
60
|
+
function createLocalGate(env, post) {
|
|
61
|
+
if (['0', 'false', 'off', 'no'].includes((env.FCD_LOCAL_GATE || '').trim().toLowerCase()))
|
|
62
|
+
return exports.NO_GATE;
|
|
63
|
+
const send = post ?? loopbackPost(portFrom(env));
|
|
64
|
+
let absent = false;
|
|
65
|
+
let reached = false;
|
|
66
|
+
const gate = {
|
|
67
|
+
get present() { return reached && !absent; },
|
|
68
|
+
async decide(call) {
|
|
69
|
+
if (absent)
|
|
70
|
+
return null;
|
|
71
|
+
let reply;
|
|
72
|
+
try {
|
|
73
|
+
reply = await send('/v1/tool-call', JSON.stringify(call), exports.LOCAL_DECIDE_TIMEOUT_MS);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// A refused connection means no extension in this environment; a timeout or reset is a bad moment, not absence.
|
|
77
|
+
if (isRefused(error))
|
|
78
|
+
absent = true;
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
reached = true;
|
|
82
|
+
if (reply.status !== 200)
|
|
83
|
+
return null;
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(reply.body);
|
|
86
|
+
if (parsed && (parsed.decision === 'allow' || parsed.decision === 'block' || parsed.decision === 'approval'))
|
|
87
|
+
return parsed;
|
|
88
|
+
}
|
|
89
|
+
catch { /* an answer we cannot read is not an answer */ }
|
|
90
|
+
return null;
|
|
91
|
+
},
|
|
92
|
+
async invocationEnd(requestId) {
|
|
93
|
+
// Every invocation ends with a notice, even one the extension never decided (a non-Bedrock event): the extension waits for
|
|
94
|
+
// it before it sends its records, so a missing one would hold the next invocation back. Never to an extension known absent.
|
|
95
|
+
if (absent || !requestId)
|
|
96
|
+
return;
|
|
97
|
+
try {
|
|
98
|
+
await send('/v1/invocation-end', JSON.stringify({ requestId }), exports.LOCAL_END_TIMEOUT_MS);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// The first thing an invocation asked of the extension may be this notice (a non-Bedrock event): a refusal is absence too.
|
|
102
|
+
if (isRefused(error))
|
|
103
|
+
absent = true;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
return gate;
|
|
108
|
+
}
|
|
109
|
+
/** A gate that is never there: every call uses the shim's own path. */
|
|
110
|
+
exports.NO_GATE = {
|
|
111
|
+
present: false,
|
|
112
|
+
decide: async () => null,
|
|
113
|
+
invocationEnd: async () => undefined,
|
|
114
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { LocalActionPolicy } from './localDecision';
|
|
2
|
+
export declare const LOCAL_SAFETY_RULE_PREFIX = "local-safety:";
|
|
3
|
+
export type LocalSafetyStage = 'enforce' | 'warn' | 'off';
|
|
4
|
+
type ServedAction = 'block' | 'warn' | 'mask' | 'ask';
|
|
5
|
+
/** The served snapshot fields the guard and this glue read (the rest of the snapshot is passed through as is). */
|
|
6
|
+
export interface LocalSafetySnapshotView {
|
|
7
|
+
policyHash?: string;
|
|
8
|
+
categories?: Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
items: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
customBlocks?: Array<{
|
|
16
|
+
id: string;
|
|
17
|
+
pattern?: string;
|
|
18
|
+
action?: ServedAction;
|
|
19
|
+
categoryId?: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}>;
|
|
22
|
+
disabledBuiltInItemIds?: string[];
|
|
23
|
+
itemActions?: Record<string, ServedAction>;
|
|
24
|
+
managerApprovalIds?: string[];
|
|
25
|
+
wouldActions?: Record<string, ServedAction>;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** `sdkGate.localSafety` from the bundle. */
|
|
29
|
+
export interface ServedLocalSafety {
|
|
30
|
+
stage: LocalSafetyStage;
|
|
31
|
+
snapshot: LocalSafetySnapshotView;
|
|
32
|
+
wouldManagerIds?: Set<string>;
|
|
33
|
+
}
|
|
34
|
+
export interface LocalSafetyOutcome {
|
|
35
|
+
check?: LocalActionPolicy;
|
|
36
|
+
wouldHave: NonNullable<LocalActionPolicy['monitorMatches']>;
|
|
37
|
+
ruleIds: string[];
|
|
38
|
+
}
|
|
39
|
+
export declare function parseServedLocalSafety(raw: unknown): ServedLocalSafety | undefined;
|
|
40
|
+
export declare function evaluateLocalSafety(call: {
|
|
41
|
+
toolName: string;
|
|
42
|
+
toolArgs: Record<string, unknown>;
|
|
43
|
+
mcpServer?: string;
|
|
44
|
+
}, input: ServedLocalSafety): LocalSafetyOutcome;
|
|
45
|
+
export declare function localSafetyFailure(stage: LocalSafetyStage, error: unknown): LocalSafetyOutcome;
|
|
46
|
+
/** The action-policy result with the built-in safety rules folded in (the gate's order; the strictest decides). */
|
|
47
|
+
export declare function withLocalSafety(actionPolicy: LocalActionPolicy, outcome: LocalSafetyOutcome): LocalActionPolicy;
|
|
48
|
+
export {};
|