@oculum/scanner 1.0.9 → 1.0.11
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/dist/baseline/diff.d.ts +32 -0
- package/dist/baseline/diff.d.ts.map +1 -0
- package/dist/baseline/diff.js +119 -0
- package/dist/baseline/diff.js.map +1 -0
- package/dist/baseline/index.d.ts +9 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +19 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/manager.d.ts +67 -0
- package/dist/baseline/manager.d.ts.map +1 -0
- package/dist/baseline/manager.js +180 -0
- package/dist/baseline/manager.js.map +1 -0
- package/dist/baseline/types.d.ts +91 -0
- package/dist/baseline/types.d.ts.map +1 -0
- package/dist/baseline/types.js +12 -0
- package/dist/baseline/types.js.map +1 -0
- package/dist/formatters/cli-terminal.d.ts +38 -0
- package/dist/formatters/cli-terminal.d.ts.map +1 -1
- package/dist/formatters/cli-terminal.js +365 -42
- package/dist/formatters/cli-terminal.js.map +1 -1
- package/dist/formatters/github-comment.d.ts +1 -1
- package/dist/formatters/github-comment.d.ts.map +1 -1
- package/dist/formatters/github-comment.js +75 -11
- package/dist/formatters/github-comment.js.map +1 -1
- package/dist/formatters/index.d.ts +1 -1
- package/dist/formatters/index.d.ts.map +1 -1
- package/dist/formatters/index.js +4 -1
- package/dist/formatters/index.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -16
- package/dist/index.js.map +1 -1
- package/dist/layer1/config-audit.d.ts.map +1 -1
- package/dist/layer1/config-audit.js +20 -3
- package/dist/layer1/config-audit.js.map +1 -1
- package/dist/layer1/config-mcp-audit.d.ts +20 -0
- package/dist/layer1/config-mcp-audit.d.ts.map +1 -0
- package/dist/layer1/config-mcp-audit.js +239 -0
- package/dist/layer1/config-mcp-audit.js.map +1 -0
- package/dist/layer1/index.d.ts +1 -0
- package/dist/layer1/index.d.ts.map +1 -1
- package/dist/layer1/index.js +9 -1
- package/dist/layer1/index.js.map +1 -1
- package/dist/layer2/ai-agent-tools.d.ts.map +1 -1
- package/dist/layer2/ai-agent-tools.js +303 -0
- package/dist/layer2/ai-agent-tools.js.map +1 -1
- package/dist/layer2/ai-endpoint-protection.d.ts.map +1 -1
- package/dist/layer2/ai-endpoint-protection.js +17 -3
- package/dist/layer2/ai-endpoint-protection.js.map +1 -1
- package/dist/layer2/ai-execution-sinks.d.ts.map +1 -1
- package/dist/layer2/ai-execution-sinks.js +462 -12
- package/dist/layer2/ai-execution-sinks.js.map +1 -1
- package/dist/layer2/ai-fingerprinting.d.ts.map +1 -1
- package/dist/layer2/ai-fingerprinting.js +3 -0
- package/dist/layer2/ai-fingerprinting.js.map +1 -1
- package/dist/layer2/ai-mcp-security.d.ts +17 -0
- package/dist/layer2/ai-mcp-security.d.ts.map +1 -0
- package/dist/layer2/ai-mcp-security.js +679 -0
- package/dist/layer2/ai-mcp-security.js.map +1 -0
- package/dist/layer2/ai-package-hallucination.d.ts +19 -0
- package/dist/layer2/ai-package-hallucination.d.ts.map +1 -0
- package/dist/layer2/ai-package-hallucination.js +696 -0
- package/dist/layer2/ai-package-hallucination.js.map +1 -0
- package/dist/layer2/ai-prompt-hygiene.d.ts.map +1 -1
- package/dist/layer2/ai-prompt-hygiene.js +495 -9
- package/dist/layer2/ai-prompt-hygiene.js.map +1 -1
- package/dist/layer2/ai-rag-safety.d.ts.map +1 -1
- package/dist/layer2/ai-rag-safety.js +372 -1
- package/dist/layer2/ai-rag-safety.js.map +1 -1
- package/dist/layer2/auth-antipatterns.d.ts.map +1 -1
- package/dist/layer2/auth-antipatterns.js +4 -0
- package/dist/layer2/auth-antipatterns.js.map +1 -1
- package/dist/layer2/byok-patterns.d.ts.map +1 -1
- package/dist/layer2/byok-patterns.js +3 -0
- package/dist/layer2/byok-patterns.js.map +1 -1
- package/dist/layer2/dangerous-functions/child-process.d.ts +16 -0
- package/dist/layer2/dangerous-functions/child-process.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/child-process.js +74 -0
- package/dist/layer2/dangerous-functions/child-process.js.map +1 -0
- package/dist/layer2/dangerous-functions/dom-xss.d.ts +29 -0
- package/dist/layer2/dangerous-functions/dom-xss.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/dom-xss.js +179 -0
- package/dist/layer2/dangerous-functions/dom-xss.js.map +1 -0
- package/dist/layer2/dangerous-functions/index.d.ts +13 -0
- package/dist/layer2/dangerous-functions/index.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/index.js +621 -0
- package/dist/layer2/dangerous-functions/index.js.map +1 -0
- package/dist/layer2/dangerous-functions/json-parse.d.ts +31 -0
- package/dist/layer2/dangerous-functions/json-parse.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/json-parse.js +319 -0
- package/dist/layer2/dangerous-functions/json-parse.js.map +1 -0
- package/dist/layer2/dangerous-functions/math-random.d.ts +61 -0
- package/dist/layer2/dangerous-functions/math-random.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/math-random.js +459 -0
- package/dist/layer2/dangerous-functions/math-random.js.map +1 -0
- package/dist/layer2/dangerous-functions/patterns.d.ts +21 -0
- package/dist/layer2/dangerous-functions/patterns.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/patterns.js +161 -0
- package/dist/layer2/dangerous-functions/patterns.js.map +1 -0
- package/dist/layer2/dangerous-functions/request-validation.d.ts +13 -0
- package/dist/layer2/dangerous-functions/request-validation.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/request-validation.js +119 -0
- package/dist/layer2/dangerous-functions/request-validation.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.d.ts +23 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.js +149 -0
- package/dist/layer2/dangerous-functions/utils/control-flow.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/helpers.d.ts +31 -0
- package/dist/layer2/dangerous-functions/utils/helpers.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/helpers.js +124 -0
- package/dist/layer2/dangerous-functions/utils/helpers.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/index.d.ts +9 -0
- package/dist/layer2/dangerous-functions/utils/index.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/index.js +23 -0
- package/dist/layer2/dangerous-functions/utils/index.js.map +1 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts +22 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.d.ts.map +1 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.js +89 -0
- package/dist/layer2/dangerous-functions/utils/schema-validation.js.map +1 -0
- package/dist/layer2/data-exposure.d.ts.map +1 -1
- package/dist/layer2/data-exposure.js +3 -0
- package/dist/layer2/data-exposure.js.map +1 -1
- package/dist/layer2/framework-checks.d.ts.map +1 -1
- package/dist/layer2/framework-checks.js +3 -0
- package/dist/layer2/framework-checks.js.map +1 -1
- package/dist/layer2/index.d.ts +3 -0
- package/dist/layer2/index.d.ts.map +1 -1
- package/dist/layer2/index.js +61 -2
- package/dist/layer2/index.js.map +1 -1
- package/dist/layer2/logic-gates.d.ts.map +1 -1
- package/dist/layer2/logic-gates.js +4 -0
- package/dist/layer2/logic-gates.js.map +1 -1
- package/dist/layer2/model-supply-chain.d.ts +20 -0
- package/dist/layer2/model-supply-chain.d.ts.map +1 -0
- package/dist/layer2/model-supply-chain.js +376 -0
- package/dist/layer2/model-supply-chain.js.map +1 -0
- package/dist/layer2/risky-imports.d.ts.map +1 -1
- package/dist/layer2/risky-imports.js +4 -0
- package/dist/layer2/risky-imports.js.map +1 -1
- package/dist/layer2/variables.d.ts.map +1 -1
- package/dist/layer2/variables.js +4 -0
- package/dist/layer2/variables.js.map +1 -1
- package/dist/layer3/anthropic/auto-dismiss.d.ts +24 -0
- package/dist/layer3/anthropic/auto-dismiss.d.ts.map +1 -0
- package/dist/layer3/anthropic/auto-dismiss.js +188 -0
- package/dist/layer3/anthropic/auto-dismiss.js.map +1 -0
- package/dist/layer3/anthropic/clients.d.ts +44 -0
- package/dist/layer3/anthropic/clients.d.ts.map +1 -0
- package/dist/layer3/anthropic/clients.js +81 -0
- package/dist/layer3/anthropic/clients.js.map +1 -0
- package/dist/layer3/anthropic/index.d.ts +41 -0
- package/dist/layer3/anthropic/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/index.js +141 -0
- package/dist/layer3/anthropic/index.js.map +1 -0
- package/dist/layer3/anthropic/prompts/index.d.ts +8 -0
- package/dist/layer3/anthropic/prompts/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/index.js +14 -0
- package/dist/layer3/anthropic/prompts/index.js.map +1 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts +15 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.js +169 -0
- package/dist/layer3/anthropic/prompts/semantic-analysis.js.map +1 -0
- package/dist/layer3/anthropic/prompts/validation.d.ts +12 -0
- package/dist/layer3/anthropic/prompts/validation.d.ts.map +1 -0
- package/dist/layer3/anthropic/prompts/validation.js +421 -0
- package/dist/layer3/anthropic/prompts/validation.js.map +1 -0
- package/dist/layer3/anthropic/providers/anthropic.d.ts +21 -0
- package/dist/layer3/anthropic/providers/anthropic.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/anthropic.js +266 -0
- package/dist/layer3/anthropic/providers/anthropic.js.map +1 -0
- package/dist/layer3/anthropic/providers/index.d.ts +8 -0
- package/dist/layer3/anthropic/providers/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/index.js +15 -0
- package/dist/layer3/anthropic/providers/index.js.map +1 -0
- package/dist/layer3/anthropic/providers/openai.d.ts +18 -0
- package/dist/layer3/anthropic/providers/openai.d.ts.map +1 -0
- package/dist/layer3/anthropic/providers/openai.js +340 -0
- package/dist/layer3/anthropic/providers/openai.js.map +1 -0
- package/dist/layer3/anthropic/request-builder.d.ts +20 -0
- package/dist/layer3/anthropic/request-builder.d.ts.map +1 -0
- package/dist/layer3/anthropic/request-builder.js +134 -0
- package/dist/layer3/anthropic/request-builder.js.map +1 -0
- package/dist/layer3/anthropic/types.d.ts +88 -0
- package/dist/layer3/anthropic/types.d.ts.map +1 -0
- package/dist/layer3/anthropic/types.js +38 -0
- package/dist/layer3/anthropic/types.js.map +1 -0
- package/dist/layer3/anthropic/utils/index.d.ts +9 -0
- package/dist/layer3/anthropic/utils/index.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/index.js +24 -0
- package/dist/layer3/anthropic/utils/index.js.map +1 -0
- package/dist/layer3/anthropic/utils/path-helpers.d.ts +21 -0
- package/dist/layer3/anthropic/utils/path-helpers.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/path-helpers.js +69 -0
- package/dist/layer3/anthropic/utils/path-helpers.js.map +1 -0
- package/dist/layer3/anthropic/utils/response-parser.d.ts +40 -0
- package/dist/layer3/anthropic/utils/response-parser.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/response-parser.js +285 -0
- package/dist/layer3/anthropic/utils/response-parser.js.map +1 -0
- package/dist/layer3/anthropic/utils/retry.d.ts +15 -0
- package/dist/layer3/anthropic/utils/retry.d.ts.map +1 -0
- package/dist/layer3/anthropic/utils/retry.js +62 -0
- package/dist/layer3/anthropic/utils/retry.js.map +1 -0
- package/dist/layer3/index.d.ts +1 -0
- package/dist/layer3/index.d.ts.map +1 -1
- package/dist/layer3/index.js +16 -6
- package/dist/layer3/index.js.map +1 -1
- package/dist/layer3/osv-check.d.ts +75 -0
- package/dist/layer3/osv-check.d.ts.map +1 -0
- package/dist/layer3/osv-check.js +308 -0
- package/dist/layer3/osv-check.js.map +1 -0
- package/dist/rules/framework-fixes.d.ts +48 -0
- package/dist/rules/framework-fixes.d.ts.map +1 -0
- package/dist/rules/framework-fixes.js +439 -0
- package/dist/rules/framework-fixes.js.map +1 -0
- package/dist/rules/index.d.ts +8 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +18 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/metadata.d.ts +43 -0
- package/dist/rules/metadata.d.ts.map +1 -0
- package/dist/rules/metadata.js +734 -0
- package/dist/rules/metadata.js.map +1 -0
- package/dist/suppression/config-loader.d.ts +74 -0
- package/dist/suppression/config-loader.d.ts.map +1 -0
- package/dist/suppression/config-loader.js +424 -0
- package/dist/suppression/config-loader.js.map +1 -0
- package/dist/suppression/hash.d.ts +48 -0
- package/dist/suppression/hash.d.ts.map +1 -0
- package/dist/suppression/hash.js +88 -0
- package/dist/suppression/hash.js.map +1 -0
- package/dist/suppression/index.d.ts +11 -0
- package/dist/suppression/index.d.ts.map +1 -0
- package/dist/suppression/index.js +39 -0
- package/dist/suppression/index.js.map +1 -0
- package/dist/suppression/inline-parser.d.ts +39 -0
- package/dist/suppression/inline-parser.d.ts.map +1 -0
- package/dist/suppression/inline-parser.js +218 -0
- package/dist/suppression/inline-parser.js.map +1 -0
- package/dist/suppression/manager.d.ts +94 -0
- package/dist/suppression/manager.d.ts.map +1 -0
- package/dist/suppression/manager.js +292 -0
- package/dist/suppression/manager.js.map +1 -0
- package/dist/suppression/types.d.ts +151 -0
- package/dist/suppression/types.d.ts.map +1 -0
- package/dist/suppression/types.js +28 -0
- package/dist/suppression/types.js.map +1 -0
- package/dist/tiers.d.ts +1 -1
- package/dist/tiers.d.ts.map +1 -1
- package/dist/tiers.js +27 -0
- package/dist/tiers.js.map +1 -1
- package/dist/types.d.ts +62 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/context-helpers.d.ts +4 -0
- package/dist/utils/context-helpers.d.ts.map +1 -1
- package/dist/utils/context-helpers.js +13 -9
- package/dist/utils/context-helpers.js.map +1 -1
- package/package.json +4 -2
- package/src/__tests__/benchmark/fixtures/layer1/mcp-config-audit.json +31 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-execution-sinks.ts +1489 -82
- package/src/__tests__/benchmark/fixtures/layer2/ai-mcp-security.ts +495 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-package-hallucination.ts +255 -0
- package/src/__tests__/benchmark/fixtures/layer2/ai-prompt-hygiene.ts +300 -1
- package/src/__tests__/benchmark/fixtures/layer2/ai-rag-safety.ts +139 -0
- package/src/__tests__/benchmark/fixtures/layer2/byok-patterns.ts +7 -0
- package/src/__tests__/benchmark/fixtures/layer2/data-exposure.ts +63 -0
- package/src/__tests__/benchmark/fixtures/layer2/excessive-agency.ts +221 -0
- package/src/__tests__/benchmark/fixtures/layer2/index.ts +18 -0
- package/src/__tests__/benchmark/fixtures/layer2/model-supply-chain.ts +204 -0
- package/src/__tests__/benchmark/fixtures/layer2/phase1-enhancements.ts +157 -0
- package/src/__tests__/snapshots/__snapshots__/anthropic-validation-refactor.test.ts.snap +758 -0
- package/src/__tests__/snapshots/__snapshots__/dangerous-functions-refactor.test.ts.snap +503 -0
- package/src/__tests__/snapshots/anthropic-validation-refactor.test.ts +321 -0
- package/src/__tests__/snapshots/dangerous-functions-refactor.test.ts +439 -0
- package/src/baseline/__tests__/diff.test.ts +261 -0
- package/src/baseline/__tests__/manager.test.ts +225 -0
- package/src/baseline/diff.ts +135 -0
- package/src/baseline/index.ts +29 -0
- package/src/baseline/manager.ts +230 -0
- package/src/baseline/types.ts +97 -0
- package/src/formatters/cli-terminal.ts +444 -41
- package/src/formatters/github-comment.ts +79 -11
- package/src/formatters/index.ts +4 -0
- package/src/index.ts +197 -14
- package/src/layer1/config-audit.ts +24 -3
- package/src/layer1/config-mcp-audit.ts +276 -0
- package/src/layer1/index.ts +16 -6
- package/src/layer2/ai-agent-tools.ts +336 -0
- package/src/layer2/ai-endpoint-protection.ts +16 -3
- package/src/layer2/ai-execution-sinks.ts +516 -12
- package/src/layer2/ai-fingerprinting.ts +5 -1
- package/src/layer2/ai-mcp-security.ts +730 -0
- package/src/layer2/ai-package-hallucination.ts +791 -0
- package/src/layer2/ai-prompt-hygiene.ts +547 -9
- package/src/layer2/ai-rag-safety.ts +382 -3
- package/src/layer2/auth-antipatterns.ts +5 -0
- package/src/layer2/byok-patterns.ts +5 -1
- package/src/layer2/dangerous-functions/child-process.ts +98 -0
- package/src/layer2/dangerous-functions/dom-xss.ts +220 -0
- package/src/layer2/dangerous-functions/index.ts +949 -0
- package/src/layer2/dangerous-functions/json-parse.ts +385 -0
- package/src/layer2/dangerous-functions/math-random.ts +537 -0
- package/src/layer2/dangerous-functions/patterns.ts +174 -0
- package/src/layer2/dangerous-functions/request-validation.ts +145 -0
- package/src/layer2/dangerous-functions/utils/control-flow.ts +162 -0
- package/src/layer2/dangerous-functions/utils/helpers.ts +170 -0
- package/src/layer2/dangerous-functions/utils/index.ts +25 -0
- package/src/layer2/dangerous-functions/utils/schema-validation.ts +91 -0
- package/src/layer2/data-exposure.ts +5 -1
- package/src/layer2/framework-checks.ts +5 -0
- package/src/layer2/index.ts +63 -1
- package/src/layer2/logic-gates.ts +5 -0
- package/src/layer2/model-supply-chain.ts +456 -0
- package/src/layer2/risky-imports.ts +5 -0
- package/src/layer2/variables.ts +5 -0
- package/src/layer3/__tests__/osv-check.test.ts +384 -0
- package/src/layer3/anthropic/auto-dismiss.ts +212 -0
- package/src/layer3/anthropic/clients.ts +84 -0
- package/src/layer3/anthropic/index.ts +170 -0
- package/src/layer3/anthropic/prompts/index.ts +14 -0
- package/src/layer3/anthropic/prompts/semantic-analysis.ts +173 -0
- package/src/layer3/anthropic/prompts/validation.ts +419 -0
- package/src/layer3/anthropic/providers/anthropic.ts +310 -0
- package/src/layer3/anthropic/providers/index.ts +8 -0
- package/src/layer3/anthropic/providers/openai.ts +384 -0
- package/src/layer3/anthropic/request-builder.ts +150 -0
- package/src/layer3/anthropic/types.ts +148 -0
- package/src/layer3/anthropic/utils/index.ts +26 -0
- package/src/layer3/anthropic/utils/path-helpers.ts +68 -0
- package/src/layer3/anthropic/utils/response-parser.ts +322 -0
- package/src/layer3/anthropic/utils/retry.ts +75 -0
- package/src/layer3/index.ts +18 -5
- package/src/layer3/osv-check.ts +420 -0
- package/src/rules/__tests__/framework-fixes.test.ts +689 -0
- package/src/rules/__tests__/metadata.test.ts +218 -0
- package/src/rules/framework-fixes.ts +470 -0
- package/src/rules/index.ts +21 -0
- package/src/rules/metadata.ts +831 -0
- package/src/suppression/__tests__/config-loader.test.ts +382 -0
- package/src/suppression/__tests__/hash.test.ts +166 -0
- package/src/suppression/__tests__/inline-parser.test.ts +212 -0
- package/src/suppression/__tests__/manager.test.ts +415 -0
- package/src/suppression/config-loader.ts +462 -0
- package/src/suppression/hash.ts +95 -0
- package/src/suppression/index.ts +51 -0
- package/src/suppression/inline-parser.ts +273 -0
- package/src/suppression/manager.ts +379 -0
- package/src/suppression/types.ts +174 -0
- package/src/tiers.ts +36 -0
- package/src/types.ts +90 -0
- package/src/utils/context-helpers.ts +13 -9
- package/dist/layer2/dangerous-functions.d.ts +0 -7
- package/dist/layer2/dangerous-functions.d.ts.map +0 -1
- package/dist/layer2/dangerous-functions.js +0 -1701
- package/dist/layer2/dangerous-functions.js.map +0 -1
- package/dist/layer3/anthropic.d.ts +0 -87
- package/dist/layer3/anthropic.d.ts.map +0 -1
- package/dist/layer3/anthropic.js +0 -1948
- package/dist/layer3/anthropic.js.map +0 -1
- package/dist/layer3/openai.d.ts +0 -25
- package/dist/layer3/openai.d.ts.map +0 -1
- package/dist/layer3/openai.js +0 -238
- package/dist/layer3/openai.js.map +0 -1
- package/src/layer2/dangerous-functions.ts +0 -1940
- package/src/layer3/anthropic.ts +0 -2257
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Smart Auto-Dismiss Rules
|
|
4
|
+
*
|
|
5
|
+
* Instant filtering rules that don't require AI validation.
|
|
6
|
+
* These rules catch obvious false positives before sending to AI.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.applyAutoDismissRules = applyAutoDismissRules;
|
|
10
|
+
const context_helpers_1 = require("../../utils/context-helpers");
|
|
11
|
+
const tiers_1 = require("../../tiers");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Auto-Dismiss Rules
|
|
14
|
+
// ============================================================================
|
|
15
|
+
const AUTO_DISMISS_RULES = [
|
|
16
|
+
// Test files - often contain intentional "vulnerable" patterns for testing
|
|
17
|
+
{
|
|
18
|
+
name: 'test_file',
|
|
19
|
+
check: (finding) => (0, context_helpers_1.isTestOrMockFile)(finding.filePath),
|
|
20
|
+
reason: 'Finding in test/mock file',
|
|
21
|
+
},
|
|
22
|
+
// Example/demo code - not production code
|
|
23
|
+
{
|
|
24
|
+
name: 'example_file',
|
|
25
|
+
check: (finding) => (0, context_helpers_1.isExampleFile)(finding.filePath),
|
|
26
|
+
reason: 'Finding in example/demo file',
|
|
27
|
+
},
|
|
28
|
+
// Documentation files
|
|
29
|
+
{
|
|
30
|
+
name: 'documentation_file',
|
|
31
|
+
check: (finding) => /\.(md|mdx|txt|rst)$/i.test(finding.filePath),
|
|
32
|
+
reason: 'Finding in documentation file',
|
|
33
|
+
},
|
|
34
|
+
// Scanner/security tool code itself
|
|
35
|
+
{
|
|
36
|
+
name: 'scanner_code',
|
|
37
|
+
check: (finding) => (0, context_helpers_1.isScannerOrFixtureFile)(finding.filePath),
|
|
38
|
+
reason: 'Finding in scanner/fixture code',
|
|
39
|
+
},
|
|
40
|
+
// Environment variable references (not hardcoded secrets)
|
|
41
|
+
{
|
|
42
|
+
name: 'env_var_reference',
|
|
43
|
+
check: (finding) => {
|
|
44
|
+
if (finding.category !== 'hardcoded_secret' && finding.category !== 'high_entropy_string') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return (0, context_helpers_1.isEnvVarReference)(finding.lineContent);
|
|
48
|
+
},
|
|
49
|
+
reason: 'Uses environment variable (not hardcoded)',
|
|
50
|
+
},
|
|
51
|
+
// Public health check endpoints don't need auth
|
|
52
|
+
{
|
|
53
|
+
name: 'health_check_endpoint',
|
|
54
|
+
check: (finding) => {
|
|
55
|
+
if (finding.category !== 'missing_auth')
|
|
56
|
+
return false;
|
|
57
|
+
return (0, context_helpers_1.isPublicEndpoint)(finding.lineContent, finding.filePath);
|
|
58
|
+
},
|
|
59
|
+
reason: 'Public health check endpoint (auth not required)',
|
|
60
|
+
},
|
|
61
|
+
// CSS/Tailwind classes flagged as high entropy
|
|
62
|
+
{
|
|
63
|
+
name: 'css_classes',
|
|
64
|
+
check: (finding) => {
|
|
65
|
+
if (finding.category !== 'high_entropy_string')
|
|
66
|
+
return false;
|
|
67
|
+
const cssIndicators = ['flex', 'grid', 'text-', 'bg-', 'px-', 'py-', 'rounded', 'shadow', 'hover:', 'dark:'];
|
|
68
|
+
const lowerLine = finding.lineContent.toLowerCase();
|
|
69
|
+
const matchCount = cssIndicators.filter(ind => lowerLine.includes(ind)).length;
|
|
70
|
+
return matchCount >= 2;
|
|
71
|
+
},
|
|
72
|
+
reason: 'CSS/Tailwind classes (not a secret)',
|
|
73
|
+
},
|
|
74
|
+
// Comment lines shouldn't be flagged for most categories
|
|
75
|
+
{
|
|
76
|
+
name: 'comment_line',
|
|
77
|
+
check: (finding) => {
|
|
78
|
+
// Some categories are valid in comments (e.g., TODO security)
|
|
79
|
+
if (finding.category === 'ai_pattern')
|
|
80
|
+
return false;
|
|
81
|
+
return (0, context_helpers_1.isComment)(finding.lineContent);
|
|
82
|
+
},
|
|
83
|
+
reason: 'Code comment (not executable)',
|
|
84
|
+
},
|
|
85
|
+
// Info severity already - no need to validate
|
|
86
|
+
// BUT: Only auto-dismiss info-severity for Tier A (core) findings
|
|
87
|
+
// Tier B (ai_assisted) findings MUST go through AI validation even at info severity
|
|
88
|
+
// because detectors may have pre-downgraded them based on partial context
|
|
89
|
+
{
|
|
90
|
+
name: 'info_severity_core_only',
|
|
91
|
+
check: (finding) => {
|
|
92
|
+
if (finding.severity !== 'info')
|
|
93
|
+
return false;
|
|
94
|
+
// Only auto-dismiss info-severity for Tier A (core) findings
|
|
95
|
+
// Tier B should always go through AI for proper validation
|
|
96
|
+
const tier = (0, tiers_1.getTierForCategory)(finding.category, finding.layer);
|
|
97
|
+
return tier === 'core';
|
|
98
|
+
},
|
|
99
|
+
reason: 'Already info severity for core detector (low priority)',
|
|
100
|
+
},
|
|
101
|
+
// Generic success/error messages in ai_pattern
|
|
102
|
+
{
|
|
103
|
+
name: 'generic_message',
|
|
104
|
+
check: (finding) => {
|
|
105
|
+
if (finding.category !== 'ai_pattern')
|
|
106
|
+
return false;
|
|
107
|
+
const genericPatterns = [
|
|
108
|
+
/['"`](success|done|ok|completed|finished|saved|updated|deleted|created)['"`]/i,
|
|
109
|
+
/['"`]something went wrong['"`]/i,
|
|
110
|
+
/['"`]an error occurred['"`]/i,
|
|
111
|
+
/console\.(log|info|debug)\s*\(\s*['"`][^'"]+['"`]\s*\)/i,
|
|
112
|
+
];
|
|
113
|
+
return genericPatterns.some(p => p.test(finding.lineContent));
|
|
114
|
+
},
|
|
115
|
+
reason: 'Generic UI message (not security-relevant)',
|
|
116
|
+
},
|
|
117
|
+
// Type definitions with 'any' - often necessary for third-party libs
|
|
118
|
+
{
|
|
119
|
+
name: 'type_definition_any',
|
|
120
|
+
check: (finding) => {
|
|
121
|
+
if (finding.category !== 'ai_pattern')
|
|
122
|
+
return false;
|
|
123
|
+
if (!finding.title.toLowerCase().includes('any'))
|
|
124
|
+
return false;
|
|
125
|
+
// Check if it's in a .d.ts file or type definition context
|
|
126
|
+
if (finding.filePath.includes('.d.ts'))
|
|
127
|
+
return true;
|
|
128
|
+
const typeDefPatterns = [/^type\s+\w+\s*=/, /^interface\s+\w+/, /declare\s+(const|let|var|function|class)/];
|
|
129
|
+
return typeDefPatterns.some(p => p.test(finding.lineContent.trim()));
|
|
130
|
+
},
|
|
131
|
+
reason: 'Type definition (not runtime code)',
|
|
132
|
+
},
|
|
133
|
+
// setTimeout/setInterval magic numbers - code style, not security
|
|
134
|
+
{
|
|
135
|
+
name: 'timeout_magic_number',
|
|
136
|
+
check: (finding) => {
|
|
137
|
+
if (finding.category !== 'ai_pattern')
|
|
138
|
+
return false;
|
|
139
|
+
return /set(Timeout|Interval)\s*\([^,]+,\s*\d+\s*\)/.test(finding.lineContent);
|
|
140
|
+
},
|
|
141
|
+
reason: 'Timeout value (code style, not security)',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Apply Auto-Dismiss Rules
|
|
146
|
+
// ============================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Rules that should NOT be applied to direct-surface findings.
|
|
149
|
+
* These rules are designed to reduce AI validation costs, not to suppress findings entirely.
|
|
150
|
+
*/
|
|
151
|
+
const VALIDATION_ONLY_RULES = new Set([
|
|
152
|
+
'info_severity_core_only', // Info findings should surface, just not go through expensive AI validation
|
|
153
|
+
]);
|
|
154
|
+
/**
|
|
155
|
+
* Apply smart auto-dismiss rules to filter obvious false positives
|
|
156
|
+
* Returns findings that should be sent to AI validation
|
|
157
|
+
*
|
|
158
|
+
* @param findings - Array of vulnerabilities to filter
|
|
159
|
+
* @param mode - 'validation' applies all rules (for AI validation candidates),
|
|
160
|
+
* 'surface' excludes cost-saving rules (for direct-surface findings)
|
|
161
|
+
*/
|
|
162
|
+
function applyAutoDismissRules(findings, mode = 'validation') {
|
|
163
|
+
const toValidate = [];
|
|
164
|
+
const dismissed = [];
|
|
165
|
+
// Filter rules based on mode
|
|
166
|
+
const applicableRules = mode === 'surface'
|
|
167
|
+
? AUTO_DISMISS_RULES.filter(rule => !VALIDATION_ONLY_RULES.has(rule.name))
|
|
168
|
+
: AUTO_DISMISS_RULES;
|
|
169
|
+
for (const finding of findings) {
|
|
170
|
+
let wasDismissed = false;
|
|
171
|
+
for (const rule of applicableRules) {
|
|
172
|
+
if (rule.check(finding)) {
|
|
173
|
+
dismissed.push({
|
|
174
|
+
finding,
|
|
175
|
+
rule: rule.name,
|
|
176
|
+
reason: rule.reason,
|
|
177
|
+
});
|
|
178
|
+
wasDismissed = true;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!wasDismissed) {
|
|
183
|
+
toValidate.push(finding);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { toValidate, dismissed };
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=auto-dismiss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-dismiss.js","sourceRoot":"","sources":["../../../src/layer3/anthropic/auto-dismiss.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA0KH,sDAoCC;AA1MD,iEAOoC;AACpC,uCAAgD;AAEhD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,MAAM,kBAAkB,GAAsB;IAC5C,2EAA2E;IAC3E;QACE,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,kCAAgB,EAAC,OAAO,CAAC,QAAQ,CAAC;QACtD,MAAM,EAAE,2BAA2B;KACpC;IAED,0CAA0C;IAC1C;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,+BAAa,EAAC,OAAO,CAAC,QAAQ,CAAC;QACnD,MAAM,EAAE,8BAA8B;KACvC;IAED,sBAAsB;IACtB;QACE,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QACjE,MAAM,EAAE,+BAA+B;KACxC;IAED,oCAAoC;IACpC;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,wCAAsB,EAAC,OAAO,CAAC,QAAQ,CAAC;QAC5D,MAAM,EAAE,iCAAiC;KAC1C;IAED,0DAA0D;IAC1D;QACE,IAAI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;QAC1E,CAAC,CAAC,kBAAkB,CAAA;IAEtB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,YAAY,GAAG,KAAK,CAAA;QAExB,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxB,SAAS,CAAC,IAAI,CAAC;oBACb,OAAO;oBACP,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC,CAAA;gBACF,YAAY,GAAG,IAAI,CAAA;gBACnB,MAAK;YACP,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider Client Factories
|
|
3
|
+
*
|
|
4
|
+
* Provides lazy-initialized clients for OpenAI and Anthropic APIs.
|
|
5
|
+
*/
|
|
6
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
7
|
+
import OpenAI from 'openai';
|
|
8
|
+
/**
|
|
9
|
+
* Initialize Anthropic client
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAnthropicClient(): Anthropic;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize OpenAI client (singleton)
|
|
14
|
+
*/
|
|
15
|
+
export declare function getOpenAIClient(): OpenAI;
|
|
16
|
+
/**
|
|
17
|
+
* GPT-5-mini pricing constants (per 1M tokens)
|
|
18
|
+
*/
|
|
19
|
+
export declare const GPT5_MINI_PRICING: {
|
|
20
|
+
input: number;
|
|
21
|
+
cached: number;
|
|
22
|
+
output: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Claude 3.5 Haiku pricing constants (per 1M tokens)
|
|
26
|
+
*/
|
|
27
|
+
export declare const HAIKU_PRICING: {
|
|
28
|
+
input: number;
|
|
29
|
+
cacheWrite: number;
|
|
30
|
+
cacheRead: number;
|
|
31
|
+
output: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Number of files to include in each API call (Phase 2 optimization)
|
|
35
|
+
* Batching multiple files reduces API overhead and leverages prompt caching better
|
|
36
|
+
*/
|
|
37
|
+
export declare const FILES_PER_API_BATCH = 8;
|
|
38
|
+
/**
|
|
39
|
+
* Number of API batches to process in parallel (Phase 3 optimization)
|
|
40
|
+
* Higher values = faster scans but more API load
|
|
41
|
+
* OpenAI/GPT-5-mini handles this well
|
|
42
|
+
*/
|
|
43
|
+
export declare const PARALLEL_API_BATCHES = 6;
|
|
44
|
+
//# sourceMappingURL=clients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../../../src/layer3/anthropic/clients.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AACzC,OAAO,MAAM,MAAM,QAAQ,CAAA;AAM3B;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,SAAS,CAM9C;AASD;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CASxC;AAMD;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;CAI7B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;CAKzB,CAAA;AAMD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI Provider Client Factories
|
|
4
|
+
*
|
|
5
|
+
* Provides lazy-initialized clients for OpenAI and Anthropic APIs.
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.PARALLEL_API_BATCHES = exports.FILES_PER_API_BATCH = exports.HAIKU_PRICING = exports.GPT5_MINI_PRICING = void 0;
|
|
12
|
+
exports.getAnthropicClient = getAnthropicClient;
|
|
13
|
+
exports.getOpenAIClient = getOpenAIClient;
|
|
14
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
15
|
+
const openai_1 = __importDefault(require("openai"));
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Anthropic Client
|
|
18
|
+
// ============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Initialize Anthropic client
|
|
21
|
+
*/
|
|
22
|
+
function getAnthropicClient() {
|
|
23
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
24
|
+
if (!apiKey) {
|
|
25
|
+
throw new Error('ANTHROPIC_API_KEY environment variable is not set');
|
|
26
|
+
}
|
|
27
|
+
return new sdk_1.default({ apiKey });
|
|
28
|
+
}
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// OpenAI Client
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Singleton instance for connection reuse
|
|
33
|
+
let openaiClient = null;
|
|
34
|
+
/**
|
|
35
|
+
* Initialize OpenAI client (singleton)
|
|
36
|
+
*/
|
|
37
|
+
function getOpenAIClient() {
|
|
38
|
+
if (!openaiClient) {
|
|
39
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
40
|
+
if (!apiKey) {
|
|
41
|
+
throw new Error('OPENAI_API_KEY environment variable is not set');
|
|
42
|
+
}
|
|
43
|
+
openaiClient = new openai_1.default({ apiKey });
|
|
44
|
+
}
|
|
45
|
+
return openaiClient;
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Pricing Constants
|
|
49
|
+
// ============================================================================
|
|
50
|
+
/**
|
|
51
|
+
* GPT-5-mini pricing constants (per 1M tokens)
|
|
52
|
+
*/
|
|
53
|
+
exports.GPT5_MINI_PRICING = {
|
|
54
|
+
input: 0.25, // $0.25 per 1M tokens
|
|
55
|
+
cached: 0.025, // $0.025 per 1M tokens (10% of input)
|
|
56
|
+
output: 2.00, // $2.00 per 1M tokens
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Claude 3.5 Haiku pricing constants (per 1M tokens)
|
|
60
|
+
*/
|
|
61
|
+
exports.HAIKU_PRICING = {
|
|
62
|
+
input: 0.80, // $0.80 per 1M tokens
|
|
63
|
+
cacheWrite: 1.00, // $1.00 per 1M tokens (5m cache)
|
|
64
|
+
cacheRead: 0.08, // $0.08 per 1M tokens
|
|
65
|
+
output: 4.00, // $4.00 per 1M tokens
|
|
66
|
+
};
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Batching Configuration
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Number of files to include in each API call (Phase 2 optimization)
|
|
72
|
+
* Batching multiple files reduces API overhead and leverages prompt caching better
|
|
73
|
+
*/
|
|
74
|
+
exports.FILES_PER_API_BATCH = 8;
|
|
75
|
+
/**
|
|
76
|
+
* Number of API batches to process in parallel (Phase 3 optimization)
|
|
77
|
+
* Higher values = faster scans but more API load
|
|
78
|
+
* OpenAI/GPT-5-mini handles this well
|
|
79
|
+
*/
|
|
80
|
+
exports.PARALLEL_API_BATCHES = 6;
|
|
81
|
+
//# sourceMappingURL=clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/layer3/anthropic/clients.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAYH,gDAMC;AAYD,0CASC;AArCD,4DAAyC;AACzC,oDAA2B;AAE3B,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,kBAAkB;IAChC,MAAM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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 3: AI Semantic Analysis
|
|
3
|
+
*
|
|
4
|
+
* Uses Claude to perform deep security analysis including:
|
|
5
|
+
* - Taint analysis (data flow from sources to sinks)
|
|
6
|
+
* - Business logic flaw detection
|
|
7
|
+
* - Missing authorization checks
|
|
8
|
+
* - Cryptography validation
|
|
9
|
+
* - Data exposure detection
|
|
10
|
+
* - Framework-specific deep analysis
|
|
11
|
+
*
|
|
12
|
+
* Also provides high-context validation for Layer 1/2 findings.
|
|
13
|
+
*/
|
|
14
|
+
import type { Vulnerability, ScanFile } from '../../types';
|
|
15
|
+
import type { ProjectContext } from '../../utils/project-context-builder';
|
|
16
|
+
import type { AIValidationResult, Layer3Context } from './types';
|
|
17
|
+
export type { ValidationStats, AIValidationResult, Layer3Context } from './types';
|
|
18
|
+
export { applyAutoDismissRules } from './auto-dismiss';
|
|
19
|
+
/**
|
|
20
|
+
* Analyze a single file using AI for deep security analysis (Layer 3)
|
|
21
|
+
*/
|
|
22
|
+
export declare function analyzeWithAI(file: ScanFile, context?: Layer3Context): Promise<Vulnerability[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Batch analyze multiple files using AI (Layer 3)
|
|
25
|
+
* Processes files in batches to avoid rate limits
|
|
26
|
+
*/
|
|
27
|
+
export declare function batchAnalyzeWithAI(files: ScanFile[], context?: Layer3Context, maxConcurrent?: number): Promise<Vulnerability[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Validate Layer 1/2 findings using AI with HIGH-CONTEXT validation
|
|
30
|
+
*
|
|
31
|
+
* Key improvements over previous version:
|
|
32
|
+
* 1. Sends FULL FILE CONTENT (not just snippets) for better context
|
|
33
|
+
* 2. Includes PROJECT CONTEXT (auth patterns, data access, etc.)
|
|
34
|
+
* 3. Uses generalised rules from Section 3 of the security model
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateFindingsWithAI(findings: Vulnerability[], files: ScanFile[], projectContext?: ProjectContext, onProgress?: (progress: {
|
|
37
|
+
filesProcessed: number;
|
|
38
|
+
totalFiles: number;
|
|
39
|
+
status: string;
|
|
40
|
+
}) => void): Promise<AIValidationResult>;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/layer3/anthropic/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEzE,OAAO,KAAK,EAAmB,kBAAkB,EAAE,aAAa,EAAa,MAAM,SAAS,CAAA;AAS5F,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAMtD;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,aAAa,EAAE,CAAC,CA+D1B;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,CAAC,EAAE,aAAa,EACvB,aAAa,GAAE,MAAU,GACxB,OAAO,CAAC,aAAa,EAAE,CAAC,CAqB1B;AAMD;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,aAAa,EAAE,EACzB,KAAK,EAAE,QAAQ,EAAE,EACjB,cAAc,CAAC,EAAE,cAAc,EAC/B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,GAC9F,OAAO,CAAC,kBAAkB,CAAC,CAiB7B"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Layer 3: AI Semantic Analysis
|
|
4
|
+
*
|
|
5
|
+
* Uses Claude to perform deep security analysis including:
|
|
6
|
+
* - Taint analysis (data flow from sources to sinks)
|
|
7
|
+
* - Business logic flaw detection
|
|
8
|
+
* - Missing authorization checks
|
|
9
|
+
* - Cryptography validation
|
|
10
|
+
* - Data exposure detection
|
|
11
|
+
* - Framework-specific deep analysis
|
|
12
|
+
*
|
|
13
|
+
* Also provides high-context validation for Layer 1/2 findings.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.applyAutoDismissRules = void 0;
|
|
17
|
+
exports.analyzeWithAI = analyzeWithAI;
|
|
18
|
+
exports.batchAnalyzeWithAI = batchAnalyzeWithAI;
|
|
19
|
+
exports.validateFindingsWithAI = validateFindingsWithAI;
|
|
20
|
+
const types_1 = require("./types");
|
|
21
|
+
const clients_1 = require("./clients");
|
|
22
|
+
const response_parser_1 = require("./utils/response-parser");
|
|
23
|
+
const semantic_analysis_1 = require("./prompts/semantic-analysis");
|
|
24
|
+
const openai_1 = require("./providers/openai");
|
|
25
|
+
const anthropic_1 = require("./providers/anthropic");
|
|
26
|
+
var auto_dismiss_1 = require("./auto-dismiss");
|
|
27
|
+
Object.defineProperty(exports, "applyAutoDismissRules", { enumerable: true, get: function () { return auto_dismiss_1.applyAutoDismissRules; } });
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Layer 3: Deep AI Analysis
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Analyze a single file using AI for deep security analysis (Layer 3)
|
|
33
|
+
*/
|
|
34
|
+
async function analyzeWithAI(file, context) {
|
|
35
|
+
const client = (0, clients_1.getAnthropicClient)();
|
|
36
|
+
// Prepare the code with line numbers for reference
|
|
37
|
+
const numberedCode = file.content
|
|
38
|
+
.split('\n')
|
|
39
|
+
.map((line, i) => `${i + 1}: ${line}`)
|
|
40
|
+
.join('\n');
|
|
41
|
+
// Build auth context for the prompt
|
|
42
|
+
const authContext = (0, semantic_analysis_1.buildAuthContextForPrompt)(context);
|
|
43
|
+
const userMessage = `Analyze this ${file.language} file for security vulnerabilities:
|
|
44
|
+
|
|
45
|
+
File: ${file.path}${authContext}
|
|
46
|
+
|
|
47
|
+
\`\`\`${file.language}
|
|
48
|
+
${numberedCode}
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
Return ONLY a JSON array of findings.`;
|
|
52
|
+
try {
|
|
53
|
+
const response = await client.messages.create({
|
|
54
|
+
model: 'claude-3-5-haiku-20241022',
|
|
55
|
+
max_tokens: 4096,
|
|
56
|
+
system: semantic_analysis_1.SECURITY_ANALYSIS_PROMPT,
|
|
57
|
+
messages: [
|
|
58
|
+
{
|
|
59
|
+
role: 'user',
|
|
60
|
+
content: userMessage,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
// Extract text content from response
|
|
65
|
+
const textContent = response.content.find((block) => block.type === 'text');
|
|
66
|
+
if (!textContent || textContent.type !== 'text') {
|
|
67
|
+
console.error('No text content in AI response');
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
// Parse the JSON response
|
|
71
|
+
const findings = (0, response_parser_1.parseAIResponse)(textContent.text);
|
|
72
|
+
// Convert to Vulnerability format
|
|
73
|
+
return findings.map((finding, index) => ({
|
|
74
|
+
id: `ai-${file.path}-${finding.lineNumber}-${index}`,
|
|
75
|
+
filePath: file.path,
|
|
76
|
+
lineNumber: finding.lineNumber,
|
|
77
|
+
lineContent: (0, response_parser_1.getLineContent)(file.content, finding.lineNumber),
|
|
78
|
+
severity: finding.severity,
|
|
79
|
+
category: finding.category,
|
|
80
|
+
title: finding.title,
|
|
81
|
+
description: finding.description,
|
|
82
|
+
suggestedFix: finding.suggestedFix,
|
|
83
|
+
confidence: 'high',
|
|
84
|
+
layer: 3,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error('AI analysis error:', error);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Batch analyze multiple files using AI (Layer 3)
|
|
94
|
+
* Processes files in batches to avoid rate limits
|
|
95
|
+
*/
|
|
96
|
+
async function batchAnalyzeWithAI(files, context, maxConcurrent = 3) {
|
|
97
|
+
const vulnerabilities = [];
|
|
98
|
+
// Process files in batches to avoid rate limits
|
|
99
|
+
for (let i = 0; i < files.length; i += maxConcurrent) {
|
|
100
|
+
const batch = files.slice(i, i + maxConcurrent);
|
|
101
|
+
const results = await Promise.all(batch.map(file => analyzeWithAI(file, context).catch(err => {
|
|
102
|
+
console.error(`AI analysis failed for ${file.path}:`, err);
|
|
103
|
+
return [];
|
|
104
|
+
})));
|
|
105
|
+
vulnerabilities.push(...results.flat());
|
|
106
|
+
// Small delay between batches to avoid rate limits
|
|
107
|
+
if (i + maxConcurrent < files.length) {
|
|
108
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return vulnerabilities;
|
|
112
|
+
}
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// Layer 2.5: High-Context Validation
|
|
115
|
+
// ============================================================================
|
|
116
|
+
/**
|
|
117
|
+
* Validate Layer 1/2 findings using AI with HIGH-CONTEXT validation
|
|
118
|
+
*
|
|
119
|
+
* Key improvements over previous version:
|
|
120
|
+
* 1. Sends FULL FILE CONTENT (not just snippets) for better context
|
|
121
|
+
* 2. Includes PROJECT CONTEXT (auth patterns, data access, etc.)
|
|
122
|
+
* 3. Uses generalised rules from Section 3 of the security model
|
|
123
|
+
*/
|
|
124
|
+
async function validateFindingsWithAI(findings, files, projectContext, onProgress) {
|
|
125
|
+
// Initialize stats tracking
|
|
126
|
+
const stats = (0, types_1.createInitialStats)(findings.length);
|
|
127
|
+
if (findings.length === 0) {
|
|
128
|
+
return { vulnerabilities: [], stats };
|
|
129
|
+
}
|
|
130
|
+
// Check for provider override (GPT-5-mini is default for 47% cost savings)
|
|
131
|
+
const aiProvider = process.env.AI_PROVIDER || 'openai';
|
|
132
|
+
if (aiProvider === 'anthropic') {
|
|
133
|
+
console.log('[AI Validation] Using Anthropic provider (Claude 3.5 Haiku)');
|
|
134
|
+
return (0, anthropic_1.validateWithAnthropic)(findings, files, projectContext, stats, onProgress);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.log('[AI Validation] Using OpenAI provider (GPT-5-mini)');
|
|
138
|
+
return (0, openai_1.validateWithOpenAI)(findings, files, projectContext, stats);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layer3/anthropic/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAwBH,sCAkEC;AAMD,gDAyBC;AAcD,wDAsBC;AAvJD,mCAA4C;AAC5C,uCAA8C;AAC9C,6DAA6G;AAC7G,mEAAiG;AACjG,+CAAuD;AACvD,qDAA6D;AAI7D,+CAAsD;AAA7C,qHAAA,qBAAqB,OAAA;AAE9B,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,IAAc,EACd,OAAuB;IAEvB,MAAM,MAAM,GAAG,IAAA,4BAAkB,GAAE,CAAA;IAEnC,mDAAmD;IACnD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO;SAC9B,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;SACrC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,oCAAoC;IACpC,MAAM,WAAW,GAAG,I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EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC;AAED,+EAA+E;AAC/E,qCAAqC;AACrC,+EAA+E;AAE/E;;;;;;;GAOG;AACI,KAAK,UAAU,sBAAsB,CAC1C,QAAyB,EACzB,KAAiB,EACjB,cAA+B,EAC/B,UAA+F;IAE/F,4BAA4B;IAC5B,MAAM,KAAK,GAAoB,IAAA,0BAAkB,EAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAElE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,KAAK,EAAE,CAAA;IACvC,CAAC;IAED,2EAA2E;IAC3E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,QAAQ,CAAA;IACtD,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAA;QAC1E,OAAO,IAAA,iCAAqB,EAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;IAClF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAA;QACjE,OAAO,IAAA,2BAAkB,EAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,CAAA;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all prompt templates and helpers.
|
|
5
|
+
*/
|
|
6
|
+
export { SECURITY_ANALYSIS_PROMPT, buildAuthContextForPrompt, } from './semantic-analysis';
|
|
7
|
+
export { HIGH_CONTEXT_VALIDATION_PROMPT, } from './validation';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/prompts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,8BAA8B,GAC/B,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompts Index
|
|
4
|
+
*
|
|
5
|
+
* Re-exports all prompt templates and helpers.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.HIGH_CONTEXT_VALIDATION_PROMPT = exports.buildAuthContextForPrompt = exports.SECURITY_ANALYSIS_PROMPT = void 0;
|
|
9
|
+
var semantic_analysis_1 = require("./semantic-analysis");
|
|
10
|
+
Object.defineProperty(exports, "SECURITY_ANALYSIS_PROMPT", { enumerable: true, get: function () { return semantic_analysis_1.SECURITY_ANALYSIS_PROMPT; } });
|
|
11
|
+
Object.defineProperty(exports, "buildAuthContextForPrompt", { enumerable: true, get: function () { return semantic_analysis_1.buildAuthContextForPrompt; } });
|
|
12
|
+
var validation_1 = require("./validation");
|
|
13
|
+
Object.defineProperty(exports, "HIGH_CONTEXT_VALIDATION_PROMPT", { enumerable: true, get: function () { return validation_1.HIGH_CONTEXT_VALIDATION_PROMPT; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layer3/anthropic/prompts/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yDAG4B;AAF1B,6HAAA,wBAAwB,OAAA;AACxB,8HAAA,yBAAyB,OAAA;AAG3B,2CAEqB;AADnB,4HAAA,8BAA8B,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Analysis Prompt (Layer 3)
|
|
3
|
+
*
|
|
4
|
+
* System prompt for deep semantic security analysis using AI.
|
|
5
|
+
*/
|
|
6
|
+
import type { Layer3Context } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* System prompt for security analysis
|
|
9
|
+
*/
|
|
10
|
+
export declare const SECURITY_ANALYSIS_PROMPT = "You are an expert security code reviewer. Analyze the provided code for security vulnerabilities.\n\nFocus on these specific vulnerability types:\n\n1. **Taint Analysis (Data Flow)**\n - Track user input from sources (req.query, req.params, req.body, searchParams, URL parameters)\n - To dangerous sinks (eval, dangerouslySetInnerHTML, exec, SQL queries, file operations)\n - Flag any path where untrusted data reaches a dangerous function without sanitization\n\n2. **SQL Injection**\n - String concatenation in SQL queries\n - Template literals with user input in queries\n - Missing parameterized queries\n\n3. **XSS (Cross-Site Scripting)**\n - User input rendered without escaping\n - dangerouslySetInnerHTML with user data\n - innerHTML assignments\n - NOTE: React/Next.js JSX automatically escapes content, so {variable} in JSX is NOT XSS\n\n4. **Command Injection**\n - exec, spawn, execSync with user input\n - Shell command construction with variables\n\n5. **Missing Authorization**\n - API routes that modify data without auth checks\n - Database writes in GET handlers\n - Missing permission checks before sensitive operations\n\n6. **Insecure Deserialization**\n - JSON.parse on untrusted data without validation\n - eval of serialized data\n\n7. **Cryptography Validation**\n - Weak algorithms: MD5 (for security), SHA1 (for security), DES, RC4\n - Insecure random: Math.random() for tokens/keys/secrets\n - Hardcoded encryption keys or IVs (not from env vars)\n - ECB mode usage (patterns indicate cipher mode)\n - Low iteration counts for PBKDF2 (< 10000)\n - Short key lengths (< 256 bits for symmetric)\n - Missing salt for password hashing\n - createCipher() instead of createCipheriv()\n\n8. **Data Exposure Detection**\n - Logging sensitive data: console.log with passwords, tokens, secrets, API keys\n - Stack traces exposed to clients: err.stack in response\n - Returning entire user objects (may include password hash)\n - Debug endpoints left in code: /debug, /test, /_internal routes\n - Verbose error messages exposing internal details\n - Sensitive data in error responses\n\n9. **Framework-Specific Security**\n\n **Next.js:**\n - Server actions ('use server') without authentication\n - Client components ('use client') accessing non-NEXT_PUBLIC_ env vars\n - Middleware that returns NextResponse.next() without auth checks\n - getServerSideProps without session validation\n - Exposed API routes without rate limiting\n\n **React:**\n - Sensitive data stored in useState (visible in devtools)\n - dangerouslySetInnerHTML with props/state\n - useEffect making authenticated API calls without token validation\n\n **Express:**\n - Missing helmet() middleware for security headers\n - CORS with origin: \"*\" in production\n - Missing body-parser limits (DoS risk)\n - Trust proxy without verification\n - Error handlers exposing stack traces\n\nIMPORTANT - DO NOT FLAG THESE AS VULNERABILITIES (common false positives):\n\n**Framework Patterns (Safe by Design):**\n- Next.js middleware using request.url for redirects (standard pattern)\n- React/Next.js JSX rendering variables like {user.name} (auto-escaped by React)\n- Supabase/Firebase client creation with NEXT_PUBLIC_ environment variables\n- Using headers().get('host') in Next.js server actions\n\n**Data Handling (Low Risk):**\n- JSON.parse on data from YOUR OWN database (the app wrote it, it's trusted). Do NOT report this as a vulnerability. At most, you may mention an info-level robustness note if there is no error handling, but generally you should omit it.\n- JSON.parse on localStorage data (same-origin, XSS is a separate issue). This is also not a security vulnerability. At most, you may suggest an info-level robustness improvement, and usually it is not worth mentioning.\n- Passing user's own data to external APIs (user embedding their own content).\n- Error messages that use error.message in catch blocks or are returned to the client as a generic error string are standard error handling. Treat them as LOW/INFO hardening at most, and DO NOT mark them as medium/high unless the message clearly includes credentials, secrets, or full stack traces.\n- Generic configuration or feature messages like \"OpenAI API key not configured\" or \"service disabled\" are operational information, not security vulnerabilities. Treat them as info at most, or ignore them.\n\n**Authentication Patterns (Context Matters):**\n- Internal server-side functions only called from trusted code paths (OAuth callbacks, etc.)\n- Functions with userId parameters called with session.user.id from authenticated contexts\n- Service role keys used in server-side code with proper auth checks elsewhere\n- API routes that call getCurrentUserId() and use the result (the auth check IS the userId call)\n\n**BYOK (Bring Your Own Key) Patterns:**\n- User-provided API keys in BYOK mode are INTENTIONAL - the user wants to use their own key\n- This is a feature, not a vulnerability - don't flag it unless there's actual abuse potential\n- When a BYOK key is only used TRANSIENTLY in memory for a single provider call (and is never logged or stored), and the route is authenticated, do NOT report this as a medium/high vulnerability. At most, you may surface a low/info note reminding the developer not to log or persist keys.\n- Frontend components sending a BYOK key to an authenticated backend endpoint for one-shot use are expected behavior, not a vulnerability. Do NOT flag these as data_exposure or dangerous_function unless the key is logged, stored, or echoed back to the client.\n- Only raise medium/high BYOK findings when keys are clearly stored (e.g., written to a database or long-term logs), logged in plaintext, or accepted by unauthenticated endpoints that attackers could abuse at scale.\n\n**What TO Flag (Real Vulnerabilities):**\n- SQL string concatenation with user input\n- eval() or Function() with user-controlled strings\n- Missing auth checks where sensitive data could be accessed by wrong user\n- Actual hardcoded secrets (real API keys, not env var references)\n- Command injection (exec/spawn with user input)\n\nRespond ONLY with a JSON array of findings. Each finding must have:\n{\n \"lineNumber\": <number>,\n \"severity\": \"critical\" | \"high\" | \"medium\" | \"low\",\n \"category\": \"sql_injection\" | \"xss\" | \"command_injection\" | \"missing_auth\" | \"dangerous_function\",\n \"title\": \"<short title>\",\n \"description\": \"<detailed explanation of the vulnerability>\",\n \"suggestedFix\": \"<how to fix it>\"\n}\n\nIf no vulnerabilities are found, return an empty array: []\n\nCRITICAL: Only report REAL vulnerabilities with HIGH confidence. Be conservative - it's better to miss a low-confidence issue than to report false positives. The code is likely using modern frameworks with built-in protections.";
|
|
11
|
+
/**
|
|
12
|
+
* Build auth context string for AI prompt
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildAuthContextForPrompt(ctx?: Layer3Context): string;
|
|
15
|
+
//# sourceMappingURL=semantic-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-analysis.d.ts","sourceRoot":"","sources":["../../../../src/layer3/anthropic/prompts/semantic-analysis.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAM7C;;GAEG;AACH,eAAO,MAAM,wBAAwB,sxNAuH+L,CAAA;AAMpO;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,CA6BrE"}
|