@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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON.parse Detection
|
|
3
|
+
*
|
|
4
|
+
* Source-aware detection of JSON.parse usage with severity classification
|
|
5
|
+
* based on the data source and error handling context.
|
|
6
|
+
*/
|
|
7
|
+
import type { Vulnerability } from '../../types';
|
|
8
|
+
/**
|
|
9
|
+
* JSON.parse source classification
|
|
10
|
+
* Determines if the input is user-controlled or internal data
|
|
11
|
+
*/
|
|
12
|
+
export type JSONParseSource = 'user_input' | 'local_storage' | 'database' | 'config' | 'migration' | 'internal' | 'test_fixture' | 'ui_state' | 'unknown';
|
|
13
|
+
/**
|
|
14
|
+
* Check if file path indicates a low-risk context for JSON.parse
|
|
15
|
+
*/
|
|
16
|
+
export declare function isLowRiskJSONParseFile(filePath: string): JSONParseSource | null;
|
|
17
|
+
/**
|
|
18
|
+
* Check if JSON.parse is parsing a trusted SDK response
|
|
19
|
+
* These are well-defined responses from known APIs and are safe to parse
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTrustedSDKResponse(lineContent: string, content: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Classify the source of data being passed to JSON.parse
|
|
24
|
+
*/
|
|
25
|
+
export declare function classifyJSONParseSource(lineContent: string, filePath: string): JSONParseSource;
|
|
26
|
+
/**
|
|
27
|
+
* Detect JSON.parse usage with source-aware severity
|
|
28
|
+
* Much smarter than simple pattern matching - considers try/catch and data source
|
|
29
|
+
*/
|
|
30
|
+
export declare function detectJSONParseSafe(content: string, filePath: string, isTestFile: boolean, vulnerabilities: Vulnerability[]): void;
|
|
31
|
+
//# sourceMappingURL=json-parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parse.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/json-parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAKvE;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,eAAe,GACf,UAAU,GACV,QAAQ,GACR,WAAW,GACX,UAAU,GACV,cAAc,GACd,UAAU,GACV,SAAS,CAAA;AAEb;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA+C/E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CA0BlF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,eAAe,CAoEjB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,EACnB,eAAe,EAAE,aAAa,EAAE,GAC/B,IAAI,CA4LN"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON.parse Detection
|
|
4
|
+
*
|
|
5
|
+
* Source-aware detection of JSON.parse usage with severity classification
|
|
6
|
+
* based on the data source and error handling context.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isLowRiskJSONParseFile = isLowRiskJSONParseFile;
|
|
10
|
+
exports.isTrustedSDKResponse = isTrustedSDKResponse;
|
|
11
|
+
exports.classifyJSONParseSource = classifyJSONParseSource;
|
|
12
|
+
exports.detectJSONParseSafe = detectJSONParseSafe;
|
|
13
|
+
const context_helpers_1 = require("../../utils/context-helpers");
|
|
14
|
+
const control_flow_1 = require("./utils/control-flow");
|
|
15
|
+
const schema_validation_1 = require("./utils/schema-validation");
|
|
16
|
+
/**
|
|
17
|
+
* Check if file path indicates a low-risk context for JSON.parse
|
|
18
|
+
*/
|
|
19
|
+
function isLowRiskJSONParseFile(filePath) {
|
|
20
|
+
// Test/mock files - skip or info only
|
|
21
|
+
if ((0, context_helpers_1.isTestOrMockFile)(filePath)) {
|
|
22
|
+
return 'test_fixture';
|
|
23
|
+
}
|
|
24
|
+
// Settings/preferences components - internal UI state
|
|
25
|
+
if (/\/(components|pages)\/(settings|preferences|config)/i.test(filePath)) {
|
|
26
|
+
return 'ui_state';
|
|
27
|
+
}
|
|
28
|
+
// Provider/context files - typically storing state in localStorage
|
|
29
|
+
if (/Provider\.(ts|tsx|js|jsx)$/i.test(filePath)) {
|
|
30
|
+
return 'ui_state';
|
|
31
|
+
}
|
|
32
|
+
// Modal/Dialog components - typically internal state
|
|
33
|
+
if (/(Modal|Dialog|Settings|Preferences)\.(ts|tsx|js|jsx)$/i.test(filePath)) {
|
|
34
|
+
return 'ui_state';
|
|
35
|
+
}
|
|
36
|
+
// __mocks__ directory
|
|
37
|
+
if (/__mocks__/i.test(filePath)) {
|
|
38
|
+
return 'test_fixture';
|
|
39
|
+
}
|
|
40
|
+
// fixtures directory
|
|
41
|
+
if (/\/(fixtures?|stubs?|mocks?)\//i.test(filePath)) {
|
|
42
|
+
return 'test_fixture';
|
|
43
|
+
}
|
|
44
|
+
// scripts/tools directories (internal tooling)
|
|
45
|
+
if (/\/(scripts?|tools?|cli)\//i.test(filePath)) {
|
|
46
|
+
return 'internal';
|
|
47
|
+
}
|
|
48
|
+
// Migration files
|
|
49
|
+
if (/migration/i.test(filePath)) {
|
|
50
|
+
return 'migration';
|
|
51
|
+
}
|
|
52
|
+
// Config files
|
|
53
|
+
if (/\/(config|settings|constants)\.(ts|js)/i.test(filePath)) {
|
|
54
|
+
return 'config';
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if JSON.parse is parsing a trusted SDK response
|
|
60
|
+
* These are well-defined responses from known APIs and are safe to parse
|
|
61
|
+
*/
|
|
62
|
+
function isTrustedSDKResponse(lineContent, content) {
|
|
63
|
+
const trustedPatterns = [
|
|
64
|
+
// OpenAI SDK responses
|
|
65
|
+
/JSON\.parse\s*\(\s*(?:response|completion|result|message)\.(?:content|text|data)/i,
|
|
66
|
+
/JSON\.parse\s*\(\s*(?:openai|anthropic|client)\./i,
|
|
67
|
+
// Fetch response.json() result (already parsed by fetch)
|
|
68
|
+
/JSON\.parse\s*\(\s*await\s+.*\.json\s*\(\s*\)\s*\)/i,
|
|
69
|
+
// SDK method results
|
|
70
|
+
/JSON\.parse\s*\(\s*(?:result|response)\.(?:choices|content|data|body)\[/i,
|
|
71
|
+
// AI SDK streaming results
|
|
72
|
+
/JSON\.parse\s*\(\s*(?:chunk|delta|part)\.(?:content|text)/i,
|
|
73
|
+
];
|
|
74
|
+
if (trustedPatterns.some(p => p.test(lineContent))) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
// Check surrounding context for SDK usage
|
|
78
|
+
const sdkContextPatterns = [
|
|
79
|
+
/openai\..*\.create/i,
|
|
80
|
+
/anthropic\..*\.create/i,
|
|
81
|
+
/\.chat\.completions/i,
|
|
82
|
+
/\.messages\.create/i,
|
|
83
|
+
];
|
|
84
|
+
return sdkContextPatterns.some(p => p.test(content));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Classify the source of data being passed to JSON.parse
|
|
88
|
+
*/
|
|
89
|
+
function classifyJSONParseSource(lineContent, filePath) {
|
|
90
|
+
// First check file path for low-risk contexts
|
|
91
|
+
const fileBasedSource = isLowRiskJSONParseFile(filePath);
|
|
92
|
+
if (fileBasedSource) {
|
|
93
|
+
return fileBasedSource;
|
|
94
|
+
}
|
|
95
|
+
// User input - potentially dangerous
|
|
96
|
+
const userInputPatterns = [
|
|
97
|
+
/JSON\.parse\s*\(\s*(req|request)\.(body|query|params)/i,
|
|
98
|
+
/JSON\.parse\s*\(\s*event\.(body|queryStringParameters)/i, // AWS Lambda
|
|
99
|
+
/JSON\.parse\s*\(\s*ctx\.(request|body|query)/i, // Koa
|
|
100
|
+
/JSON\.parse\s*\(\s*(input|userInput|rawInput|payload)/i,
|
|
101
|
+
/JSON\.parse\s*\(\s*body\b/i, // Generic 'body' often means request body
|
|
102
|
+
];
|
|
103
|
+
if (userInputPatterns.some(p => p.test(lineContent))) {
|
|
104
|
+
return 'user_input';
|
|
105
|
+
}
|
|
106
|
+
// localStorage/sessionStorage - client-side storage
|
|
107
|
+
const storagePatterns = [
|
|
108
|
+
/JSON\.parse\s*\(\s*localStorage\.getItem/i,
|
|
109
|
+
/JSON\.parse\s*\(\s*sessionStorage\.getItem/i,
|
|
110
|
+
/JSON\.parse\s*\(\s*window\.localStorage/i,
|
|
111
|
+
/JSON\.parse\s*\(\s*storage\.get/i,
|
|
112
|
+
/JSON\.parse\s*\(\s*saved\b/i, // Common pattern: const saved = localStorage.getItem(...); JSON.parse(saved)
|
|
113
|
+
/JSON\.parse\s*\(\s*stored\b/i,
|
|
114
|
+
];
|
|
115
|
+
if (storagePatterns.some(p => p.test(lineContent))) {
|
|
116
|
+
return 'local_storage';
|
|
117
|
+
}
|
|
118
|
+
// Database results - internal data
|
|
119
|
+
const databasePatterns = [
|
|
120
|
+
/JSON\.parse\s*\(\s*(row|result|record|doc|document)\./i,
|
|
121
|
+
/JSON\.parse\s*\(\s*\w+\.(data|json|metadata|embedding)\)/i,
|
|
122
|
+
/JSON\.parse\s*\(\s*\w+\[['"]?\w+['"]?\]\.(data|json|embedding)/i,
|
|
123
|
+
/JSON\.parse\s*\(\s*item\.\w+\)/i, // ORM iteration: items.map(item => JSON.parse(item.field))
|
|
124
|
+
/JSON\.parse\s*\(\s*\w+\.content\)/i, // Parsing content field from DB
|
|
125
|
+
];
|
|
126
|
+
if (databasePatterns.some(p => p.test(lineContent))) {
|
|
127
|
+
return 'database';
|
|
128
|
+
}
|
|
129
|
+
// Editor state, internal caches, UI state
|
|
130
|
+
const internalPatterns = [
|
|
131
|
+
/JSON\.parse\s*\(\s*(state|cache|stored|saved|cached)/i,
|
|
132
|
+
/JSON\.parse\s*\(\s*this\.(state|cache|data)/i,
|
|
133
|
+
/JSON\.parse\s*\(\s*\w+State\)/i,
|
|
134
|
+
/JSON\.parse\s*\(\s*editorState/i,
|
|
135
|
+
/JSON\.parse\s*\(\s*parsed\b/i, // JSON.parse(parsed) - likely already validated
|
|
136
|
+
/JSON\.parse\s*\(\s*settings\b/i, // Settings data
|
|
137
|
+
/JSON\.parse\s*\(\s*preferences\b/i,
|
|
138
|
+
];
|
|
139
|
+
if (internalPatterns.some(p => p.test(lineContent))) {
|
|
140
|
+
return 'internal';
|
|
141
|
+
}
|
|
142
|
+
// Node content in editor apps (e.g., noda-os nodes have JSON content)
|
|
143
|
+
if (/JSON\.parse\s*\(\s*(node|note|document|entry)\.(content|body|data)\)/i.test(lineContent)) {
|
|
144
|
+
return 'database';
|
|
145
|
+
}
|
|
146
|
+
return 'unknown';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Detect JSON.parse usage with source-aware severity
|
|
150
|
+
* Much smarter than simple pattern matching - considers try/catch and data source
|
|
151
|
+
*/
|
|
152
|
+
function detectJSONParseSafe(content, filePath, isTestFile, vulnerabilities) {
|
|
153
|
+
const lines = content.split('\n');
|
|
154
|
+
const jsonParsePattern = /JSON\.parse\s*\(/gi;
|
|
155
|
+
// Track instances per file to aggregate noisy patterns
|
|
156
|
+
const instances = [];
|
|
157
|
+
lines.forEach((line, index) => {
|
|
158
|
+
if ((0, context_helpers_1.isComment)(line))
|
|
159
|
+
return;
|
|
160
|
+
jsonParsePattern.lastIndex = 0;
|
|
161
|
+
if (!jsonParsePattern.test(line))
|
|
162
|
+
return;
|
|
163
|
+
const jsonSource = classifyJSONParseSource(line, filePath);
|
|
164
|
+
// Skip migration files entirely - they're internal tooling
|
|
165
|
+
if (jsonSource === 'migration')
|
|
166
|
+
return;
|
|
167
|
+
// Skip test fixtures entirely - they're intentionally parsing test data
|
|
168
|
+
if (jsonSource === 'test_fixture')
|
|
169
|
+
return;
|
|
170
|
+
// Skip trusted SDK responses - these are well-defined and safe to parse
|
|
171
|
+
if (isTrustedSDKResponse(line, content))
|
|
172
|
+
return;
|
|
173
|
+
// Check if JSON.parse is inside a try-catch block
|
|
174
|
+
const insideTryCatch = (0, control_flow_1.isInsideTryCatch)(content, index) || (0, control_flow_1.hasTryCatchNearby)(content, index);
|
|
175
|
+
// Check if schema validation is applied after JSON.parse
|
|
176
|
+
const hasSchemaValidation = (0, schema_validation_1.hasSchemaValidationNearby)(content, index);
|
|
177
|
+
// If inside try-catch with safe source, suppress entirely - this is perfectly fine
|
|
178
|
+
if (insideTryCatch &&
|
|
179
|
+
['local_storage', 'database', 'config', 'internal', 'ui_state'].includes(jsonSource)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// If schema validation is present, this is properly handled
|
|
183
|
+
if (hasSchemaValidation) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// UI state (settings, providers, modals) - very low risk, aggregate or skip
|
|
187
|
+
if (jsonSource === 'ui_state') {
|
|
188
|
+
// Only track for aggregation, don't report individually
|
|
189
|
+
instances.push({
|
|
190
|
+
lineNumber: index + 1,
|
|
191
|
+
lineContent: line.trim(),
|
|
192
|
+
source: jsonSource,
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// Determine severity based on source and error handling
|
|
197
|
+
let severity;
|
|
198
|
+
let description;
|
|
199
|
+
let suggestedFix;
|
|
200
|
+
let confidence = 'medium';
|
|
201
|
+
if (insideTryCatch) {
|
|
202
|
+
// Already has error handling
|
|
203
|
+
switch (jsonSource) {
|
|
204
|
+
case 'user_input':
|
|
205
|
+
severity = 'low';
|
|
206
|
+
description =
|
|
207
|
+
'JSON.parse on user input is wrapped in try-catch. Consider adding schema validation (zod/yup) to validate the parsed structure.';
|
|
208
|
+
suggestedFix =
|
|
209
|
+
'Add schema validation after parsing: const validated = schema.parse(JSON.parse(input))';
|
|
210
|
+
confidence = 'low';
|
|
211
|
+
break;
|
|
212
|
+
default:
|
|
213
|
+
// With try-catch and non-user source, this is fine - don't report
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// No try-catch
|
|
219
|
+
switch (jsonSource) {
|
|
220
|
+
case 'user_input':
|
|
221
|
+
severity = 'medium';
|
|
222
|
+
description =
|
|
223
|
+
'JSON.parse on user input without schema validation. Malformed input will crash; malicious input may have unexpected shape.';
|
|
224
|
+
suggestedFix =
|
|
225
|
+
'Use a schema validation library (zod, yup, joi): try { const data = schema.parse(JSON.parse(body)) } catch (e) { return 400 }';
|
|
226
|
+
confidence = 'high';
|
|
227
|
+
break;
|
|
228
|
+
case 'local_storage':
|
|
229
|
+
severity = 'info';
|
|
230
|
+
description =
|
|
231
|
+
'JSON.parse on localStorage data. Consider adding try-catch for robustness against corrupted data.';
|
|
232
|
+
suggestedFix =
|
|
233
|
+
'Wrap in try-catch to handle corrupted localStorage gracefully.';
|
|
234
|
+
confidence = 'low';
|
|
235
|
+
break;
|
|
236
|
+
case 'database':
|
|
237
|
+
// Database content parsing is very common and low-risk
|
|
238
|
+
instances.push({
|
|
239
|
+
lineNumber: index + 1,
|
|
240
|
+
lineContent: line.trim(),
|
|
241
|
+
source: jsonSource,
|
|
242
|
+
});
|
|
243
|
+
return; // Will be aggregated below
|
|
244
|
+
case 'config':
|
|
245
|
+
case 'internal':
|
|
246
|
+
severity = 'info';
|
|
247
|
+
description = `JSON.parse on ${jsonSource.replace('_', ' ')} data without error handling. Low risk but consider defensive coding.`;
|
|
248
|
+
suggestedFix = 'Consider adding try-catch for robustness.';
|
|
249
|
+
confidence = 'low';
|
|
250
|
+
break;
|
|
251
|
+
default:
|
|
252
|
+
// Unknown source - track for potential aggregation
|
|
253
|
+
instances.push({
|
|
254
|
+
lineNumber: index + 1,
|
|
255
|
+
lineContent: line.trim(),
|
|
256
|
+
source: jsonSource,
|
|
257
|
+
});
|
|
258
|
+
return; // Will be evaluated below based on aggregation
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// Downgrade test files
|
|
262
|
+
if (isTestFile) {
|
|
263
|
+
severity = 'info';
|
|
264
|
+
confidence = 'low';
|
|
265
|
+
description += ' (in test file)';
|
|
266
|
+
}
|
|
267
|
+
vulnerabilities.push({
|
|
268
|
+
id: `json-parse-${filePath}-${index + 1}`,
|
|
269
|
+
filePath,
|
|
270
|
+
lineNumber: index + 1,
|
|
271
|
+
lineContent: line.trim(),
|
|
272
|
+
severity,
|
|
273
|
+
category: 'dangerous_function',
|
|
274
|
+
title: 'JSON.parse usage',
|
|
275
|
+
description,
|
|
276
|
+
suggestedFix,
|
|
277
|
+
confidence,
|
|
278
|
+
layer: 2,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
// Aggregate low-risk JSON.parse instances if there are many
|
|
282
|
+
if (instances.length >= 3) {
|
|
283
|
+
// Create single aggregated finding instead of N individual findings
|
|
284
|
+
const lineNumbers = instances.map(i => i.lineNumber).slice(0, 5);
|
|
285
|
+
const moreText = instances.length > 5 ? `... (${instances.length} total)` : '';
|
|
286
|
+
vulnerabilities.push({
|
|
287
|
+
id: `json-parse-aggregated-${filePath}`,
|
|
288
|
+
filePath,
|
|
289
|
+
lineNumber: instances[0].lineNumber,
|
|
290
|
+
lineContent: `${instances.length} instances across this file`,
|
|
291
|
+
severity: 'info',
|
|
292
|
+
category: 'dangerous_function',
|
|
293
|
+
title: `JSON.parse usage (${instances.length} instances)`,
|
|
294
|
+
description: `JSON.parse detected. Consider adding error handling and schema validation if parsing user input.${isTestFile ? ' (in test file)' : ''}\n\nFound ${instances.length} occurrences at lines: ${lineNumbers.join(', ')}${moreText}`,
|
|
295
|
+
suggestedFix: 'Add try-catch for error handling. If parsing user input, add schema validation.',
|
|
296
|
+
confidence: 'low',
|
|
297
|
+
layer: 2,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
else if (instances.length > 0 && instances.length < 3) {
|
|
301
|
+
// Report individually for small counts
|
|
302
|
+
for (const instance of instances) {
|
|
303
|
+
vulnerabilities.push({
|
|
304
|
+
id: `json-parse-${filePath}-${instance.lineNumber}`,
|
|
305
|
+
filePath,
|
|
306
|
+
lineNumber: instance.lineNumber,
|
|
307
|
+
lineContent: instance.lineContent,
|
|
308
|
+
severity: 'info',
|
|
309
|
+
category: 'dangerous_function',
|
|
310
|
+
title: 'JSON.parse usage',
|
|
311
|
+
description: `JSON.parse on ${instance.source.replace('_', ' ')} data without error handling. Low risk but consider defensive coding.${isTestFile ? ' (in test file)' : ''}`,
|
|
312
|
+
suggestedFix: 'Consider adding try-catch for robustness.',
|
|
313
|
+
confidence: 'low',
|
|
314
|
+
layer: 2,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=json-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/json-parse.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAyBH,wDA+CC;AAMD,oDA0BC;AAKD,0DAuEC;AAMD,kDAiMC;AAxXD,iEAAyE;AACzE,uDAA0E;AAC1E,iEAAqE;AAiBrE;;GAEG;AACH,SAAgB,sBAAsB,CAAC,QAAgB;IACrD,sCAAsC;IACtC,IAAI,IAAA,kCAAgB,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,sDAAsD;IACtD,IAAI,sDAAsD,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1E,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,mEAAmE;IACnE,IAAI,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjD,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,qDAAqD;IACrD,IAAI,wDAAwD,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,sBAAsB;IACtB,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,qBAAqB;IACrB,IAAI,gCAAgC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,+CAA+C;IAC/C,IA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,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,wEAAwE,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC5K,YAAY,EAAE,2CAA2C;gBACzD,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,CAAC;aACT,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Math.random() Detection
|
|
3
|
+
*
|
|
4
|
+
* Context-aware detection of Math.random() usage with intelligent severity
|
|
5
|
+
* classification based on usage context, variable names, and function intent.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Check if Math.random() is used for cosmetic/UI purposes (not security)
|
|
9
|
+
* Cosmetic uses: CSS values, animations, UI variations, demo data
|
|
10
|
+
* Security uses: tokens, IDs, cryptographic operations, session management
|
|
11
|
+
*/
|
|
12
|
+
export declare function isCosmeticMathRandom(lineContent: string, content: string, lineNumber: number): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Classify function intent based on function name
|
|
15
|
+
* Used to determine if Math.random() usage is legitimate
|
|
16
|
+
*/
|
|
17
|
+
export declare function classifyFunctionIntent(functionName: string | null): 'uuid' | 'captcha' | 'demo' | 'security' | 'unknown';
|
|
18
|
+
/**
|
|
19
|
+
* Analyze toString() pattern in Math.random() usage
|
|
20
|
+
* Determines intent based on base and truncation length
|
|
21
|
+
*/
|
|
22
|
+
export declare function analyzeToStringPattern(lineContent: string): {
|
|
23
|
+
hasToString: boolean;
|
|
24
|
+
base: number | null;
|
|
25
|
+
isTruncated: boolean;
|
|
26
|
+
truncationLength: number | null;
|
|
27
|
+
intent: 'short-ui-id' | 'business-id' | 'full-token' | 'unknown';
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Extract variable name from Math.random() assignment
|
|
31
|
+
* Examples:
|
|
32
|
+
* const token = Math.random() -> "token"
|
|
33
|
+
* const businessId = Math.random().toString(36) -> "businessId"
|
|
34
|
+
* return Math.random() -> null (no variable)
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractMathRandomVariableName(lineContent: string): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Classify variable name security risk based on naming patterns
|
|
39
|
+
*
|
|
40
|
+
* High risk: Security-sensitive names (token, secret, key, etc.)
|
|
41
|
+
* Medium risk: Unclear context
|
|
42
|
+
* Low risk: Non-security names (id, businessId, orderId, etc.)
|
|
43
|
+
*/
|
|
44
|
+
export declare function classifyVariableNameRisk(varName: string | null): 'high' | 'medium' | 'low';
|
|
45
|
+
/**
|
|
46
|
+
* Analyze surrounding code context for security signals
|
|
47
|
+
* Returns context type and description for severity classification
|
|
48
|
+
*/
|
|
49
|
+
export declare function analyzeMathRandomContext(content: string, filePath: string, lineNumber: number): {
|
|
50
|
+
inSecurityContext: boolean;
|
|
51
|
+
inTestContext: boolean;
|
|
52
|
+
inUIContext: boolean;
|
|
53
|
+
inBusinessLogicContext: boolean;
|
|
54
|
+
contextDescription: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Check if Math.random() should be skipped entirely
|
|
58
|
+
* Returns true for seed files, test fixtures, captcha/puzzle, uuid, and pure cosmetic uses
|
|
59
|
+
*/
|
|
60
|
+
export declare function shouldSkipMathRandom(content: string, filePath: string, lineNumber: number): boolean;
|
|
61
|
+
//# sourceMappingURL=math-random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-random.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/math-random.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CA8FT;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,GAAG,IA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