@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 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/patterns.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA8JH,0CAUC;AA3JY,QAAA,mBAAmB,GAA+B;IAC7D,iBAAiB;IACjB;QACE,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,e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EAAE,0EAA0E;QACnF,QAAQ,EAAE,QAAQ;QAClB,WAAW,EAAE,kEAAkE;QAC/E,YAAY,EAAE,mEAAmE;KAClF;CACF,CAAA;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAgB,EAAE,SAAoB;IACpE,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAErD,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IAC1D,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC3B,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,GAAG,KAAK,IAAI,CAAA;QACtC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;QACnE,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;QACrD,OAAO,GAAG,KAAK,IAAI,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Body Validation Detection
|
|
3
|
+
*
|
|
4
|
+
* Detection logic for request.json() / req.json() usage without
|
|
5
|
+
* proper schema validation.
|
|
6
|
+
*/
|
|
7
|
+
import type { Vulnerability } from '../../types';
|
|
8
|
+
/**
|
|
9
|
+
* Detect request.json() / req.json() and suggest schema validation
|
|
10
|
+
* This is NOT a dangerous function - it's a prompt for best practices
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectRequestJsonValidation(content: string, filePath: string, isTestFile: boolean, vulnerabilities: Vulnerability[]): void;
|
|
13
|
+
//# sourceMappingURL=request-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-validation.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/request-validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKhD;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,EACnB,eAAe,EAAE,aAAa,EAAE,GAC/B,IAAI,CA2HN"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Request Body Validation Detection
|
|
4
|
+
*
|
|
5
|
+
* Detection logic for request.json() / req.json() usage without
|
|
6
|
+
* proper schema validation.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.detectRequestJsonValidation = detectRequestJsonValidation;
|
|
10
|
+
const context_helpers_1 = require("../../utils/context-helpers");
|
|
11
|
+
const schema_validation_1 = require("./utils/schema-validation");
|
|
12
|
+
const helpers_1 = require("./utils/helpers");
|
|
13
|
+
/**
|
|
14
|
+
* Detect request.json() / req.json() and suggest schema validation
|
|
15
|
+
* This is NOT a dangerous function - it's a prompt for best practices
|
|
16
|
+
*/
|
|
17
|
+
function detectRequestJsonValidation(content, filePath, isTestFile, vulnerabilities) {
|
|
18
|
+
// Only check API route files
|
|
19
|
+
if (!/\/(api|routes?|handlers?|controllers?)\//i.test(filePath) &&
|
|
20
|
+
!/route\.(ts|js)$/i.test(filePath)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Skip if route has throwing auth helper - these are already protected routes
|
|
24
|
+
// and the schema validation suggestion is lower priority
|
|
25
|
+
if ((0, helpers_1.hasThrowingAuthHelper)(content)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const lines = content.split('\n');
|
|
29
|
+
// Matches: request.json(), req.json(), await request.json(), etc.
|
|
30
|
+
const requestJsonPattern = /\b(request|req)\.json\s*\(\s*\)/gi;
|
|
31
|
+
// Check if file has schema validation (library-based)
|
|
32
|
+
const hasSchemaLibrary = /\b(zod|yup|joi|ajv|superstruct|valibot|typebox)\b/i.test(content) ||
|
|
33
|
+
/\.parse\s*\(|\.validate\s*\(|\.safeParse\s*\(/i.test(content);
|
|
34
|
+
// If file has schema library validation, don't report
|
|
35
|
+
if (hasSchemaLibrary)
|
|
36
|
+
return;
|
|
37
|
+
// Check for manual validation patterns (less robust but still indicates intent)
|
|
38
|
+
const hasManualCheck = (0, schema_validation_1.hasManualValidation)(content);
|
|
39
|
+
// Track instances for potential aggregation
|
|
40
|
+
const instances = [];
|
|
41
|
+
lines.forEach((line, index) => {
|
|
42
|
+
if ((0, context_helpers_1.isComment)(line))
|
|
43
|
+
return;
|
|
44
|
+
requestJsonPattern.lastIndex = 0;
|
|
45
|
+
if (!requestJsonPattern.test(line))
|
|
46
|
+
return;
|
|
47
|
+
// Check if there's validation nearby (within 10 lines after)
|
|
48
|
+
const startCheck = index;
|
|
49
|
+
const endCheck = Math.min(lines.length, index + 10);
|
|
50
|
+
const nearbyContent = lines.slice(startCheck, endCheck).join('\n');
|
|
51
|
+
// If there's validation in the nearby lines, skip
|
|
52
|
+
if (/\.parse\s*\(|\.validate\s*\(|\.safeParse\s*\(|schema\./i.test(nearbyContent)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// If manual validation is present, skip individual reporting but track for aggregate
|
|
56
|
+
if (hasManualCheck) {
|
|
57
|
+
instances.push({ lineNumber: index + 1, lineContent: line.trim() });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (isTestFile) {
|
|
61
|
+
return; // Don't report in test files
|
|
62
|
+
}
|
|
63
|
+
instances.push({ lineNumber: index + 1, lineContent: line.trim() });
|
|
64
|
+
});
|
|
65
|
+
// Don't report if no instances found
|
|
66
|
+
if (instances.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
// If manual validation exists, create a single info-level note
|
|
69
|
+
if (hasManualCheck && instances.length > 0) {
|
|
70
|
+
vulnerabilities.push({
|
|
71
|
+
id: `request-json-manual-${filePath}`,
|
|
72
|
+
filePath,
|
|
73
|
+
lineNumber: instances[0].lineNumber,
|
|
74
|
+
lineContent: instances[0].lineContent,
|
|
75
|
+
severity: 'info',
|
|
76
|
+
category: 'dangerous_function',
|
|
77
|
+
title: 'Request body with manual validation',
|
|
78
|
+
description: `API endpoint parses request body with manual validation patterns detected. Consider using a schema library (zod, yup) for more robust type-safe validation.`,
|
|
79
|
+
suggestedFix: 'While manual validation works, schema libraries provide better TypeScript integration and error messages.',
|
|
80
|
+
confidence: 'low',
|
|
81
|
+
layer: 2,
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Aggregate if multiple instances without validation
|
|
86
|
+
if (instances.length >= 2) {
|
|
87
|
+
const lineNumbers = instances.map(i => i.lineNumber).slice(0, 5);
|
|
88
|
+
vulnerabilities.push({
|
|
89
|
+
id: `request-json-aggregated-${filePath}`,
|
|
90
|
+
filePath,
|
|
91
|
+
lineNumber: instances[0].lineNumber,
|
|
92
|
+
lineContent: `${instances.length} instances`,
|
|
93
|
+
severity: 'info',
|
|
94
|
+
category: 'dangerous_function',
|
|
95
|
+
title: `Request body without schema validation (${instances.length} instances)`,
|
|
96
|
+
description: `API endpoint parses request body without visible schema validation at lines: ${lineNumbers.join(', ')}. Consider validating the shape of incoming data.`,
|
|
97
|
+
suggestedFix: 'Add schema validation (e.g., zod): const body = await request.json(); const data = schema.parse(body);',
|
|
98
|
+
confidence: 'low',
|
|
99
|
+
layer: 2,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Single instance
|
|
104
|
+
vulnerabilities.push({
|
|
105
|
+
id: `request-json-${filePath}-${instances[0].lineNumber}`,
|
|
106
|
+
filePath,
|
|
107
|
+
lineNumber: instances[0].lineNumber,
|
|
108
|
+
lineContent: instances[0].lineContent,
|
|
109
|
+
severity: 'info',
|
|
110
|
+
category: 'dangerous_function',
|
|
111
|
+
title: 'Request body without schema validation',
|
|
112
|
+
description: 'API endpoint parses request body without visible schema validation. Consider validating the shape of incoming data.',
|
|
113
|
+
suggestedFix: 'Add schema validation (e.g., zod): const body = await request.json(); const data = schema.parse(body);',
|
|
114
|
+
confidence: 'low',
|
|
115
|
+
layer: 2,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=request-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-validation.js","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/request-validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAWH,kEAgIC;AAxID,iEAAuD;AACvD,iEAA+D;AAC/D,6CAAuD;AAEvD;;;GAGG;AACH,SAAgB,2BAA2B,CACzC,OAAe,EACf,QAAgB,EAChB,UAAmB,EACnB,eAAgC;IAEhC,6BAA6B;IAC7B,IACE,CAAC,2CAA2C,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3D,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAClC,CAAC;QACD,OAAM;IACR,CAAC;IAED,8EAA8E;IAC9E,yDAAyD;IACzD,IAAI,IAAA,+BAAqB,EAAC,OAAO,CAAC,EAAE,CAAC;QACnC,OAAM;IACR,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,kEAAkE;IAClE,MAAM,kBAAkB,GAAG,mCAAmC,CAAA;IAE9D,sDAAsD;IACtD,MAAM,gBAAgB,GACpB,oDAAoD,CAAC,IAAI,CAAC,OAAO,CAAC;QAClE,gDAAgD,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEhE,sDAAsD;IACtD,IAAI,gBAAgB;QAAE,OAAM;IAE5B,gFAAgF;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AAS,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE;YACzD,QAAQ;YACR,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU;YACnC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW;YACrC,QAAQ,EAAE,MAAM;YAChB,QAAQ,EAAE,oBAAoB;YAC9B,KAAK,EAAE,wCAAwC;YAC/C,WAAW,EACT,qHAAqH;YACvH,YAAY,EACV,wGAAwG;YAC1G,UAAU,EAAE,KAAK;YACjB,KAAK,EAAE,CAAC;SACT,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control Flow Analysis Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for analyzing code control flow, including try-catch detection
|
|
5
|
+
* and function context extraction.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if a line is inside a try-catch block
|
|
9
|
+
* Looks for enclosing try { ... } catch pattern
|
|
10
|
+
*/
|
|
11
|
+
export declare function isInsideTryCatch(content: string, lineNumber: number): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Simpler heuristic: check if there's a try-catch in the same function scope
|
|
14
|
+
* Looks for try { before the line and } catch after, within reasonable bounds
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasTryCatchNearby(content: string, lineNumber: number, windowSize?: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Extract function context where a call is being made
|
|
19
|
+
* Looks backwards from the current line to find enclosing function name
|
|
20
|
+
* Returns lowercase function name or null if not found
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractFunctionContext(content: string, lineNumber: number): string | null;
|
|
23
|
+
//# sourceMappingURL=control-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-flow.d.ts","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/control-flow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAiD7E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAkCvG;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoDzF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Control Flow Analysis Utilities
|
|
4
|
+
*
|
|
5
|
+
* Functions for analyzing code control flow, including try-catch detection
|
|
6
|
+
* and function context extraction.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isInsideTryCatch = isInsideTryCatch;
|
|
10
|
+
exports.hasTryCatchNearby = hasTryCatchNearby;
|
|
11
|
+
exports.extractFunctionContext = extractFunctionContext;
|
|
12
|
+
const context_helpers_1 = require("../../../utils/context-helpers");
|
|
13
|
+
/**
|
|
14
|
+
* Check if a line is inside a try-catch block
|
|
15
|
+
* Looks for enclosing try { ... } catch pattern
|
|
16
|
+
*/
|
|
17
|
+
function isInsideTryCatch(content, lineNumber) {
|
|
18
|
+
const lines = content.split('\n');
|
|
19
|
+
// Track brace depth and whether we're in a try block
|
|
20
|
+
let tryDepth = 0;
|
|
21
|
+
let inTryBlock = false;
|
|
22
|
+
const braceStack = [];
|
|
23
|
+
// Scan from start to the target line
|
|
24
|
+
for (let i = 0; i < lineNumber && i < lines.length; i++) {
|
|
25
|
+
const line = lines[i];
|
|
26
|
+
// Check for try keyword (not in a comment)
|
|
27
|
+
if (/\btry\s*\{/.test(line) && !(0, context_helpers_1.isComment)(line)) {
|
|
28
|
+
inTryBlock = true;
|
|
29
|
+
tryDepth++;
|
|
30
|
+
// Count opening braces on this line
|
|
31
|
+
const openBraces = (line.match(/\{/g) || []).length;
|
|
32
|
+
const closeBraces = (line.match(/\}/g) || []).length;
|
|
33
|
+
for (let j = 0; j < openBraces - closeBraces; j++) {
|
|
34
|
+
braceStack.push('try');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (/\bcatch\s*\(/.test(line) && !(0, context_helpers_1.isComment)(line)) {
|
|
38
|
+
// Entering catch block - still protected
|
|
39
|
+
// Don't decrement tryDepth yet
|
|
40
|
+
}
|
|
41
|
+
else if (/\bfinally\s*\{/.test(line) && !(0, context_helpers_1.isComment)(line)) {
|
|
42
|
+
// Entering finally block - still protected
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Track regular braces
|
|
46
|
+
const openBraces = (line.match(/\{/g) || []).length;
|
|
47
|
+
const closeBraces = (line.match(/\}/g) || []).length;
|
|
48
|
+
for (let j = 0; j < openBraces; j++) {
|
|
49
|
+
braceStack.push(inTryBlock && tryDepth > 0 ? 'try' : 'other');
|
|
50
|
+
}
|
|
51
|
+
for (let j = 0; j < closeBraces; j++) {
|
|
52
|
+
const popped = braceStack.pop();
|
|
53
|
+
if (popped === 'try') {
|
|
54
|
+
tryDepth--;
|
|
55
|
+
if (tryDepth === 0) {
|
|
56
|
+
inTryBlock = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return tryDepth > 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Simpler heuristic: check if there's a try-catch in the same function scope
|
|
66
|
+
* Looks for try { before the line and } catch after, within reasonable bounds
|
|
67
|
+
*/
|
|
68
|
+
function hasTryCatchNearby(content, lineNumber, windowSize = 20) {
|
|
69
|
+
const lines = content.split('\n');
|
|
70
|
+
const startLine = Math.max(0, lineNumber - windowSize);
|
|
71
|
+
const endLine = Math.min(lines.length, lineNumber + windowSize);
|
|
72
|
+
// Look backward for 'try {'
|
|
73
|
+
let foundTry = false;
|
|
74
|
+
for (let i = lineNumber - 1; i >= startLine; i--) {
|
|
75
|
+
const line = lines[i];
|
|
76
|
+
if (/\btry\s*\{/.test(line) && !(0, context_helpers_1.isComment)(line)) {
|
|
77
|
+
foundTry = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
// Stop if we hit a function boundary
|
|
81
|
+
if (/\b(function|async function|=>|class)\b/.test(line) && /\{/.test(line)) {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!foundTry)
|
|
86
|
+
return false;
|
|
87
|
+
// Look forward for '} catch'
|
|
88
|
+
for (let i = lineNumber; i < endLine; i++) {
|
|
89
|
+
const line = lines[i];
|
|
90
|
+
if (/\}\s*catch\s*\(/.test(line) && !(0, context_helpers_1.isComment)(line)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// Stop if we hit another function boundary
|
|
94
|
+
if (i > lineNumber && /\b(function|async function|class)\b/.test(line) && /\{/.test(line)) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extract function context where a call is being made
|
|
102
|
+
* Looks backwards from the current line to find enclosing function name
|
|
103
|
+
* Returns lowercase function name or null if not found
|
|
104
|
+
*/
|
|
105
|
+
function extractFunctionContext(content, lineNumber) {
|
|
106
|
+
const lines = content.split('\n');
|
|
107
|
+
const start = Math.max(0, lineNumber - 20); // Increased from 10 to 20 for nested callbacks
|
|
108
|
+
// Look backwards for function declaration
|
|
109
|
+
for (let i = lineNumber; i >= start; i--) {
|
|
110
|
+
const line = lines[i];
|
|
111
|
+
// Skip anonymous arrow functions in callbacks (e.g., .map((x) => ...), .replace(/x/g, (c) => ...))
|
|
112
|
+
// These are not the function context we're looking for
|
|
113
|
+
// Look for pattern: .methodName(..., (param) => or .methodName(...(param) =>
|
|
114
|
+
const hasMethodCallWithArrowCallback = /\.\w+\(.*\([^)]*\)\s*=>/.test(line);
|
|
115
|
+
// Skip lines that only have arrow callbacks in method calls
|
|
116
|
+
if (hasMethodCallWithArrowCallback && !/^(const|let|var|function|async|export)/.test(line.trim())) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
// Named function declaration: function funcName(
|
|
120
|
+
const funcMatch = line.match(/function\s+(\w+)\s*\(/);
|
|
121
|
+
if (funcMatch) {
|
|
122
|
+
return funcMatch[1].toLowerCase();
|
|
123
|
+
}
|
|
124
|
+
// Arrow function with const/let/var: const funcName = () => | const funcName = async () =>
|
|
125
|
+
// Must have => after the parameters to distinguish from const x = (expression)
|
|
126
|
+
// Also handles TypeScript return type annotations: const funcName = (): string =>
|
|
127
|
+
const arrowMatch = line.match(/(const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)(?:\s*:\s*\w+)?\s*=>/);
|
|
128
|
+
if (arrowMatch) {
|
|
129
|
+
return arrowMatch[2].toLowerCase();
|
|
130
|
+
}
|
|
131
|
+
// Method declaration: methodName() { or async methodName() {
|
|
132
|
+
const methodMatch = line.match(/^\s*(?:async\s+)?(\w+)\s*\([^)]*\)\s*\{/);
|
|
133
|
+
if (methodMatch) {
|
|
134
|
+
return methodMatch[1].toLowerCase();
|
|
135
|
+
}
|
|
136
|
+
// Export function: export function funcName( or export const funcName = () =>
|
|
137
|
+
const exportFuncMatch = line.match(/export\s+(?:async\s+)?function\s+(\w+)\s*\(/);
|
|
138
|
+
if (exportFuncMatch) {
|
|
139
|
+
return exportFuncMatch[1].toLowerCase();
|
|
140
|
+
}
|
|
141
|
+
// Also handles TypeScript return type annotations: export const funcName = (): string =>
|
|
142
|
+
const exportConstMatch = line.match(/export\s+const\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)(?:\s*:\s*\w+)?\s*=>/);
|
|
143
|
+
if (exportConstMatch) {
|
|
144
|
+
return exportConstMatch[1].toLowerCase();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=control-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-flow.js","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/control-flow.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,4CAiDC;AAMD,8CAkCC;AAOD,wDAoDC;AA1JD,oEAA0D;AAE1D;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,OAAe,EAAE,UAAkB;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEjC,qDAAqD;IACrD,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,MAAM,UAAU,GAA2B,EAAE,CAAA;IAE7C,qCAAqC;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAErB,2CAA2C;QAC3C,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAA,2BAAS,EAAC,IAAI,CAAC,EAAE,CAAC;YAChD,UAAU,GAAG,IAAI,CAAA;YACjB,QAAQ,EAAE,CAAA;YACV,oCAAoC;YACpC,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAA;YACnD,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAA;YACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;gBACl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AW,GAAG,IAAI,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAA;QACzE,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACrC,CAAC;QAED,8EAA8E;QAC9E,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAA;QACjF,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACzC,CAAC;QAED,yFAAyF;QACzF,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,yEAAyE,CAAC,CAAA;QAC9G,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QAC1C,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Small utility functions used across the dangerous functions detection module.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get a specific line from content by line number (0-indexed)
|
|
8
|
+
*/
|
|
9
|
+
export declare function getLineContent(content: string, lineNumber: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Get a range of lines from content
|
|
12
|
+
*/
|
|
13
|
+
export declare function getLineRange(content: string, startLine: number, endLine: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Check if eval/exec/Function has only static literal inputs (no user data)
|
|
16
|
+
* Static inputs like eval('({ mode: "production" })') are low risk
|
|
17
|
+
*
|
|
18
|
+
* Returns true ONLY if the argument is a string literal (not a variable)
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasOnlyStaticInputs(lineContent: string, content: string, lineNumber: number): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if path traversal protection is in place
|
|
23
|
+
* Looks for common sanitization patterns that prevent directory traversal attacks
|
|
24
|
+
*/
|
|
25
|
+
export declare function hasPathTraversalProtection(context: string, lineContent: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if route has throwing auth helper (getCurrentUserId, requireAuth, etc.)
|
|
28
|
+
* Routes with throwing auth helpers are already protected
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasThrowingAuthHelper(content: string): boolean;
|
|
31
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAG1E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAgCT;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CA6BT;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAmB9D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* General Helper Utilities
|
|
4
|
+
*
|
|
5
|
+
* Small utility functions used across the dangerous functions detection module.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getLineContent = getLineContent;
|
|
9
|
+
exports.getLineRange = getLineRange;
|
|
10
|
+
exports.hasOnlyStaticInputs = hasOnlyStaticInputs;
|
|
11
|
+
exports.hasPathTraversalProtection = hasPathTraversalProtection;
|
|
12
|
+
exports.hasThrowingAuthHelper = hasThrowingAuthHelper;
|
|
13
|
+
/**
|
|
14
|
+
* Get a specific line from content by line number (0-indexed)
|
|
15
|
+
*/
|
|
16
|
+
function getLineContent(content, lineNumber) {
|
|
17
|
+
const lines = content.split('\n');
|
|
18
|
+
return lines[lineNumber] || '';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get a range of lines from content
|
|
22
|
+
*/
|
|
23
|
+
function getLineRange(content, startLine, endLine) {
|
|
24
|
+
const lines = content.split('\n');
|
|
25
|
+
const start = Math.max(0, startLine);
|
|
26
|
+
const end = Math.min(lines.length, endLine);
|
|
27
|
+
return lines.slice(start, end).join('\n');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if eval/exec/Function has only static literal inputs (no user data)
|
|
31
|
+
* Static inputs like eval('({ mode: "production" })') are low risk
|
|
32
|
+
*
|
|
33
|
+
* Returns true ONLY if the argument is a string literal (not a variable)
|
|
34
|
+
*/
|
|
35
|
+
function hasOnlyStaticInputs(lineContent, content, lineNumber) {
|
|
36
|
+
// Check if the argument to eval/exec/Function is a string literal ONLY
|
|
37
|
+
// If it's a variable, it's NOT static (could come from anywhere)
|
|
38
|
+
//
|
|
39
|
+
// String literal patterns:
|
|
40
|
+
// - Single quotes: 'content with "double quotes" inside' (no $ interpolation)
|
|
41
|
+
// - Double quotes: "content" (no $ interpolation)
|
|
42
|
+
// - Backticks without ${}: `content` (template literal but no interpolation)
|
|
43
|
+
//
|
|
44
|
+
// Note: We allow quotes INSIDE the string (e.g., 'text "with" quotes')
|
|
45
|
+
// but NOT $ (which would indicate interpolation)
|
|
46
|
+
const staticPatterns = [
|
|
47
|
+
// Single-quoted string: eval('...') - can contain anything except single quotes and $
|
|
48
|
+
/eval\s*\(\s*'[^'$]*'\s*\)/,
|
|
49
|
+
// Double-quoted string: eval("...") - can contain anything except double quotes and $
|
|
50
|
+
/eval\s*\(\s*"[^"$]*"\s*\)/,
|
|
51
|
+
// Backtick without interpolation: eval(`...`) - must not have ${ inside
|
|
52
|
+
/eval\s*\(\s*`[^`$]*`\s*\)/,
|
|
53
|
+
// Function constructor with string literal
|
|
54
|
+
/new\s+Function\s*\(\s*'[^'$]*'\s*\)/,
|
|
55
|
+
/new\s+Function\s*\(\s*"[^"$]*"\s*\)/,
|
|
56
|
+
// execSync with string literal
|
|
57
|
+
/execSync\s*\(\s*'[^'$]*'\s*\)/,
|
|
58
|
+
/execSync\s*\(\s*"[^"$]*"\s*\)/,
|
|
59
|
+
// exec with string literal
|
|
60
|
+
/exec\s*\(\s*'[^'$]*'/,
|
|
61
|
+
/exec\s*\(\s*"[^"$]*"/,
|
|
62
|
+
];
|
|
63
|
+
// Only return true if it matches a static pattern (string literal)
|
|
64
|
+
// If it's a variable like eval(code), we can't assume it's static
|
|
65
|
+
return staticPatterns.some(p => p.test(lineContent));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if path traversal protection is in place
|
|
69
|
+
* Looks for common sanitization patterns that prevent directory traversal attacks
|
|
70
|
+
*/
|
|
71
|
+
function hasPathTraversalProtection(context, lineContent) {
|
|
72
|
+
const protectionPatterns = [
|
|
73
|
+
// Path normalization with base directory check
|
|
74
|
+
/path\.resolve\s*\([^)]+\).*\.startsWith\s*\(/i,
|
|
75
|
+
/\.startsWith\s*\([^)]*(?:baseDir|basePath|rootDir|uploadDir|allowedDir)/i,
|
|
76
|
+
// Explicit ".." rejection
|
|
77
|
+
/\.includes\s*\(\s*['"`]\.\.['"`]\s*\)/i,
|
|
78
|
+
/\.indexOf\s*\(\s*['"`]\.\.['"`]\s*\)/i,
|
|
79
|
+
/['"`]\.\.['"`].*(?:throw|reject|return|error)/i,
|
|
80
|
+
// Path sanitization libraries
|
|
81
|
+
/sanitizePath|sanitizeFilename|sanitize-filename/i,
|
|
82
|
+
/path-sanitizer|secure-path/i,
|
|
83
|
+
// Explicit path validation
|
|
84
|
+
/validatePath|isValidPath|checkPath|verifyPath/i,
|
|
85
|
+
/isPathAllowed|isAllowedPath|pathIsAllowed/i,
|
|
86
|
+
// Normalize and check pattern
|
|
87
|
+
/path\.normalize\s*\([^)]+\).*(?:startsWith|includes|indexOf)/i,
|
|
88
|
+
// Regex validation for safe characters only
|
|
89
|
+
/\/\^?\[a-zA-Z0-9_\-\.\\\/\]\+\$?\//, // Only alphanumeric, dash, underscore, dot
|
|
90
|
+
// Allowlist/whitelist patterns
|
|
91
|
+
/allowedExtensions|allowedTypes|whitelist/i,
|
|
92
|
+
/\.endsWith\s*\(\s*['"`]\.\w+['"`]\s*\)/i, // Extension check
|
|
93
|
+
// Path.basename to strip directory
|
|
94
|
+
/path\.basename\s*\(/i,
|
|
95
|
+
// Zod/validation for filename patterns
|
|
96
|
+
/z\.string\s*\(\s*\)\.regex\s*\(/i,
|
|
97
|
+
];
|
|
98
|
+
return protectionPatterns.some(p => p.test(context) || p.test(lineContent));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if route has throwing auth helper (getCurrentUserId, requireAuth, etc.)
|
|
102
|
+
* Routes with throwing auth helpers are already protected
|
|
103
|
+
*/
|
|
104
|
+
function hasThrowingAuthHelper(content) {
|
|
105
|
+
const throwingAuthPatterns = [
|
|
106
|
+
/\bgetCurrentUserId\s*\(/i,
|
|
107
|
+
/\brequireAuth\s*\(/i,
|
|
108
|
+
/\bensureAuth\s*\(/i,
|
|
109
|
+
/\bauth\s*\(\s*\)\s*\.protect\s*\(/i, // Clerk: auth().protect()
|
|
110
|
+
/\bcurrentUser\s*\(\s*\)/i, // Clerk: currentUser()
|
|
111
|
+
/\bgetServerSession\s*\([^)]*\)/i, // NextAuth
|
|
112
|
+
/\bauth\s*\(\s*\)/i, // Generic auth() call
|
|
113
|
+
/\bcheckAuth\s*\(/i,
|
|
114
|
+
/\bverifyAuth\s*\(/i,
|
|
115
|
+
/\bvalidateAuth\s*\(/i,
|
|
116
|
+
/\bassertAuth\s*\(/i,
|
|
117
|
+
/\bgetAuth\s*\(/i,
|
|
118
|
+
/\brequireUser\s*\(/i,
|
|
119
|
+
/\bgetUser\s*\(\s*\)/i, // supabase.auth.getUser()
|
|
120
|
+
/const\s+\{\s*user\s*\}\s*=\s*await/i, // Destructuring pattern
|
|
121
|
+
];
|
|
122
|
+
return throwingAuthPatterns.some(p => p.test(content));
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/helpers.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAKH,wCAGC;AAKD,oCASC;AAQD,kDAoCC;AAMD,gEAgCC;AAMD,sDAmBC;AA/HD;;GAEG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,UAAkB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,SAAiB,EACjB,OAAe;IAEf,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,OAAe,EACf,UAAkB;IAElB,uEAAuE;IACvE,iEAAiE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AM,oBAAoB,GAAG;QAC3B,0BAA0B;QAC1B,qBAAqB;QACrB,oBAAoB;QACpB,oCAAoC,EAAE,0BAA0B;QAChE,0BAA0B,EAAE,uBAAuB;QACnD,iCAAiC,EAAE,WAAW;QAC9C,mBAAmB,EAAE,sBAAsB;QAC3C,mBAAmB;QACnB,oBAAoB;QACpB,sBAAsB;QACtB,oBAAoB;QACpB,iBAAiB;QACjB,qBAAqB;QACrB,sBAAsB,EAAE,0BAA0B;QAClD,qCAAqC,EAAE,wBAAwB;KAChE,CAAA;IACD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Functions Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all utility functions from the dangerous-functions module.
|
|
5
|
+
*/
|
|
6
|
+
export { isInsideTryCatch, hasTryCatchNearby, extractFunctionContext, } from './control-flow';
|
|
7
|
+
export { hasSchemaValidationNearby, hasManualValidation, hasSQLWhitelistValidation, } from './schema-validation';
|
|
8
|
+
export { getLineContent, getLineRange, hasOnlyStaticInputs, hasPathTraversalProtection, hasThrowingAuthHelper, } from './helpers';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility Functions Index
|
|
4
|
+
*
|
|
5
|
+
* Re-exports all utility functions from the dangerous-functions module.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.hasThrowingAuthHelper = exports.hasPathTraversalProtection = exports.hasOnlyStaticInputs = exports.getLineRange = exports.getLineContent = exports.hasSQLWhitelistValidation = exports.hasManualValidation = exports.hasSchemaValidationNearby = exports.extractFunctionContext = exports.hasTryCatchNearby = exports.isInsideTryCatch = void 0;
|
|
9
|
+
var control_flow_1 = require("./control-flow");
|
|
10
|
+
Object.defineProperty(exports, "isInsideTryCatch", { enumerable: true, get: function () { return control_flow_1.isInsideTryCatch; } });
|
|
11
|
+
Object.defineProperty(exports, "hasTryCatchNearby", { enumerable: true, get: function () { return control_flow_1.hasTryCatchNearby; } });
|
|
12
|
+
Object.defineProperty(exports, "extractFunctionContext", { enumerable: true, get: function () { return control_flow_1.extractFunctionContext; } });
|
|
13
|
+
var schema_validation_1 = require("./schema-validation");
|
|
14
|
+
Object.defineProperty(exports, "hasSchemaValidationNearby", { enumerable: true, get: function () { return schema_validation_1.hasSchemaValidationNearby; } });
|
|
15
|
+
Object.defineProperty(exports, "hasManualValidation", { enumerable: true, get: function () { return schema_validation_1.hasManualValidation; } });
|
|
16
|
+
Object.defineProperty(exports, "hasSQLWhitelistValidation", { enumerable: true, get: function () { return schema_validation_1.hasSQLWhitelistValidation; } });
|
|
17
|
+
var helpers_1 = require("./helpers");
|
|
18
|
+
Object.defineProperty(exports, "getLineContent", { enumerable: true, get: function () { return helpers_1.getLineContent; } });
|
|
19
|
+
Object.defineProperty(exports, "getLineRange", { enumerable: true, get: function () { return helpers_1.getLineRange; } });
|
|
20
|
+
Object.defineProperty(exports, "hasOnlyStaticInputs", { enumerable: true, get: function () { return helpers_1.hasOnlyStaticInputs; } });
|
|
21
|
+
Object.defineProperty(exports, "hasPathTraversalProtection", { enumerable: true, get: function () { return helpers_1.hasPathTraversalProtection; } });
|
|
22
|
+
Object.defineProperty(exports, "hasThrowingAuthHelper", { enumerable: true, get: function () { return helpers_1.hasThrowingAuthHelper; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,+CAIuB;AAHrB,gHAAA,gBAAgB,OAAA;AAChB,iHAAA,iBAAiB,OAAA;AACjB,sHAAA,sBAAsB,OAAA;AAGxB,yDAI4B;AAH1B,8HAAA,yBAAyB,OAAA;AACzB,wHAAA,mBAAmB,OAAA;AACnB,8HAAA,yBAAyB,OAAA;AAG3B,qCAMkB;AALhB,yGAAA,cAAc,OAAA;AACd,uGAAA,YAAY,OAAA;AACZ,8GAAA,mBAAmB,OAAA;AACnB,qHAAA,0BAA0B,OAAA;AAC1B,gHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Validation Detection Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for detecting schema validation patterns (zod, yup, joi, etc.)
|
|
5
|
+
* and manual validation patterns.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if schema validation is applied near a JSON.parse call
|
|
9
|
+
* Looks for zod, yup, joi, or similar validation patterns
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasSchemaValidationNearby(content: string, lineNumber: number): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if this file appears to have form/input validation elsewhere
|
|
14
|
+
* (manual checks on body fields, type guards, etc.)
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasManualValidation(content: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check if SQL query uses whitelist validation pattern
|
|
19
|
+
* e.g., columns validated against allowedColumns array before use
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasSQLWhitelistValidation(content: string, lineNumber: number): boolean;
|
|
22
|
+
//# sourceMappingURL=schema-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-validation.d.ts","sourceRoot":"","sources":["../../../../src/layer2/dangerous-functions/utils/schema-validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAkCtF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAe5D;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAkBtF"}
|