@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,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Math.random() Detection
|
|
4
|
+
*
|
|
5
|
+
* Context-aware detection of Math.random() usage with intelligent severity
|
|
6
|
+
* classification based on usage context, variable names, and function intent.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isCosmeticMathRandom = isCosmeticMathRandom;
|
|
10
|
+
exports.classifyFunctionIntent = classifyFunctionIntent;
|
|
11
|
+
exports.analyzeToStringPattern = analyzeToStringPattern;
|
|
12
|
+
exports.extractMathRandomVariableName = extractMathRandomVariableName;
|
|
13
|
+
exports.classifyVariableNameRisk = classifyVariableNameRisk;
|
|
14
|
+
exports.analyzeMathRandomContext = analyzeMathRandomContext;
|
|
15
|
+
exports.shouldSkipMathRandom = shouldSkipMathRandom;
|
|
16
|
+
const context_helpers_1 = require("../../utils/context-helpers");
|
|
17
|
+
const control_flow_1 = require("./utils/control-flow");
|
|
18
|
+
/**
|
|
19
|
+
* Check if Math.random() is used for cosmetic/UI purposes (not security)
|
|
20
|
+
* Cosmetic uses: CSS values, animations, UI variations, demo data
|
|
21
|
+
* Security uses: tokens, IDs, cryptographic operations, session management
|
|
22
|
+
*/
|
|
23
|
+
function isCosmeticMathRandom(lineContent, content, lineNumber) {
|
|
24
|
+
const lines = content.split('\n');
|
|
25
|
+
// Check the line itself for cosmetic indicators
|
|
26
|
+
const cosmeticLinePatterns = [
|
|
27
|
+
// CSS/style values
|
|
28
|
+
/['"`]\s*\$\{.*Math\.random.*\}\s*%['"`]/, // `${Math.random() * 40 + 50}%`
|
|
29
|
+
/Math\.random.*\s*\+\s*['"`]%['"`]/, // Math.random() * 40 + '%'
|
|
30
|
+
/Math\.random.*\)\s*\*\s*\d+\s*\+\s*\d+\s*\}\s*%/, // }) * 40 + 50}%
|
|
31
|
+
/return\s+`.*Math\.random.*%`/, // return `${...}%`
|
|
32
|
+
/width:\s*['"`].*Math\.random/i, // width: `${Math.random()...}%`
|
|
33
|
+
/height:\s*['"`].*Math\.random/i, // height: `${Math.random()...}%`
|
|
34
|
+
/opacity:\s*['"`]?.*Math\.random/i, // opacity: Math.random()
|
|
35
|
+
/transform:\s*['"`]?.*Math\.random/i, // transform: translate(...)
|
|
36
|
+
/rotate\(.*Math\.random/i, // rotate(Math.random() * 360)
|
|
37
|
+
/translate\(.*Math\.random/i, // translate(Math.random() * 100)
|
|
38
|
+
/scale\(.*Math\.random/i, // scale(Math.random() * 2)
|
|
39
|
+
// Color/animation values
|
|
40
|
+
/rgba?\(.*Math\.random/i, // rgb(Math.random() * 255, ...)
|
|
41
|
+
/hsl\(.*Math\.random/i, // hsl(Math.random() * 360, ...)
|
|
42
|
+
/Math\.random.*\*\s*360/, // Math.random() * 360 (degrees/hue)
|
|
43
|
+
/Math\.random.*\*\s*255/, // Math.random() * 255 (RGB values)
|
|
44
|
+
// Array/list randomization for UI
|
|
45
|
+
/Math\.floor\(Math\.random.*\.length\)/, // Math.floor(Math.random() * array.length)
|
|
46
|
+
/\[Math\.floor\(Math\.random/, // array[Math.floor(Math.random()...)]
|
|
47
|
+
// Demo/placeholder data
|
|
48
|
+
/Math\.random.*\*\s*\d+\s*\+\s*\d+.*\bpx\b/i, // Math.random() * 100 + 50 + 'px'
|
|
49
|
+
/Math\.random.*\*\s*\d+\s*\+\s*\d+.*\bms\b/i, // Math.random() * 1000 + 500 + 'ms'
|
|
50
|
+
/Math\.random.*\*\s*\d+\s*\+\s*\d+.*\bs\b/i, // Math.random() * 5 + 2 + 's'
|
|
51
|
+
// NOTE: toString patterns removed - now handled by analyzeToStringPattern()
|
|
52
|
+
// which provides more granular severity classification (info/low/medium/high)
|
|
53
|
+
// based on truncation length and context
|
|
54
|
+
];
|
|
55
|
+
if (cosmeticLinePatterns.some(p => p.test(lineContent))) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// Check surrounding context (5 lines before and after)
|
|
59
|
+
const contextStart = Math.max(0, lineNumber - 5);
|
|
60
|
+
const contextEnd = Math.min(lines.length, lineNumber + 5);
|
|
61
|
+
const context = lines.slice(contextStart, contextEnd).join('\n');
|
|
62
|
+
// Context indicators of cosmetic use
|
|
63
|
+
const cosmeticContextPatterns = [
|
|
64
|
+
// UI component files - REMOVED, let severity classification handle these
|
|
65
|
+
// Style-related variables/functions
|
|
66
|
+
/\b(style|styles|css|className|animation|transition)/i,
|
|
67
|
+
/\b(width|height|opacity|color|transform|rotate|scale|translate)/i,
|
|
68
|
+
// Demo/example data
|
|
69
|
+
/\b(demo|example|placeholder|mock|fake|sample|test)Data/i,
|
|
70
|
+
/\b(random|shuffle|pick|choose).*\b(color|item|element|option)/i,
|
|
71
|
+
// Animation/timing
|
|
72
|
+
/setTimeout.*Math\.random/i,
|
|
73
|
+
/setInterval.*Math\.random/i,
|
|
74
|
+
/delay.*Math\.random/i,
|
|
75
|
+
/duration.*Math\.random/i,
|
|
76
|
+
// UI state variations
|
|
77
|
+
/\b(variant|theme|layout|position).*Math\.random/i,
|
|
78
|
+
// NOTE: Removed UI identifier patterns (key, id, tempId, etc.) - these should be
|
|
79
|
+
// classified with info/low severity by the severity classification logic, not skipped entirely
|
|
80
|
+
];
|
|
81
|
+
if (cosmeticContextPatterns.some(p => p.test(context))) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
// Security-sensitive patterns that override cosmetic detection
|
|
85
|
+
const securityPatterns = [
|
|
86
|
+
/\b(token|secret|key|password|credential|signature)/i,
|
|
87
|
+
/\b(auth|crypto|encrypt|decrypt|hash)/i,
|
|
88
|
+
/\b(session|nonce|salt)\b/i,
|
|
89
|
+
/Math\.random.*\*\s*1e\d+/, // Math.random() * 1e16 (large numbers for IDs)
|
|
90
|
+
];
|
|
91
|
+
if (securityPatterns.some(p => p.test(lineContent) || p.test(context))) {
|
|
92
|
+
return false; // Not cosmetic - this is security-sensitive
|
|
93
|
+
}
|
|
94
|
+
// Check for .toString(36) WITHOUT substring/slice/substr (security token pattern)
|
|
95
|
+
// If it has substring/slice/substr, it's already caught by cosmeticLinePatterns above
|
|
96
|
+
const hasToString36WithoutTruncation = /Math\.random\(\)\.toString\(36\)/.test(lineContent) &&
|
|
97
|
+
!/\.(substring|substr|slice)\(/.test(lineContent);
|
|
98
|
+
const hasToString16WithoutTruncation = /Math\.random\(\)\.toString\(16\)/.test(lineContent) &&
|
|
99
|
+
!/\.(substring|substr|slice)\(/.test(lineContent);
|
|
100
|
+
if (hasToString36WithoutTruncation || hasToString16WithoutTruncation) {
|
|
101
|
+
return false; // Full-length toString() without truncation - likely security token
|
|
102
|
+
}
|
|
103
|
+
return false; // Default to flagging if unclear
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Classify function intent based on function name
|
|
107
|
+
* Used to determine if Math.random() usage is legitimate
|
|
108
|
+
*/
|
|
109
|
+
function classifyFunctionIntent(functionName) {
|
|
110
|
+
if (!functionName)
|
|
111
|
+
return 'unknown';
|
|
112
|
+
const lower = functionName.toLowerCase();
|
|
113
|
+
// UUID/ID generation (UI correlation, not security)
|
|
114
|
+
// Check for specific UUID patterns and generic ID generation functions
|
|
115
|
+
const uuidPatterns = ['uuid', 'guid', 'uniqueid', 'correlationid', 'tempid', 'temp_id'];
|
|
116
|
+
// Match patterns like generateId, generateTempId, createId, etc.
|
|
117
|
+
const idGenerationPatterns = /^(generate|create|make|build)(\w*)?(id|identifier)$/i;
|
|
118
|
+
if (uuidPatterns.some(p => lower.includes(p)) ||
|
|
119
|
+
idGenerationPatterns.test(lower)) {
|
|
120
|
+
return 'uuid';
|
|
121
|
+
}
|
|
122
|
+
// CAPTCHA/puzzle generation (legitimate non-security)
|
|
123
|
+
const captchaPatterns = ['captcha', 'puzzle', 'mathproblem'];
|
|
124
|
+
// Also check for 'challenge' but only if not in security context
|
|
125
|
+
if (captchaPatterns.some(p => lower.includes(p)))
|
|
126
|
+
return 'captcha';
|
|
127
|
+
if (lower.includes('challenge') && !lower.includes('auth'))
|
|
128
|
+
return 'captcha';
|
|
129
|
+
// Demo/seed/fixture data
|
|
130
|
+
const demoPatterns = ['seed', 'fixture', 'demo', 'mock', 'fake'];
|
|
131
|
+
if (demoPatterns.some(p => lower.includes(p)))
|
|
132
|
+
return 'demo';
|
|
133
|
+
// Security-sensitive (check this after id generation to avoid false positives)
|
|
134
|
+
const securityPatterns = [
|
|
135
|
+
'token',
|
|
136
|
+
'secret',
|
|
137
|
+
'key',
|
|
138
|
+
'password',
|
|
139
|
+
'credential',
|
|
140
|
+
'signature',
|
|
141
|
+
];
|
|
142
|
+
// Also match generate/create + security term combinations
|
|
143
|
+
const securityFunctionPattern = /^(generate|create|make)(token|secret|key|session|password|credential)/i;
|
|
144
|
+
if (securityPatterns.some(p => lower.includes(p)) ||
|
|
145
|
+
securityFunctionPattern.test(lower)) {
|
|
146
|
+
return 'security';
|
|
147
|
+
}
|
|
148
|
+
return 'unknown';
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Analyze toString() pattern in Math.random() usage
|
|
152
|
+
* Determines intent based on base and truncation length
|
|
153
|
+
*/
|
|
154
|
+
function analyzeToStringPattern(lineContent) {
|
|
155
|
+
const toString36Match = lineContent.match(/Math\.random\(\)\.toString\(36\)/);
|
|
156
|
+
const toString16Match = lineContent.match(/Math\.random\(\)\.toString\(16\)/);
|
|
157
|
+
if (!toString36Match && !toString16Match) {
|
|
158
|
+
return {
|
|
159
|
+
hasToString: false,
|
|
160
|
+
base: null,
|
|
161
|
+
isTruncated: false,
|
|
162
|
+
truncationLength: null,
|
|
163
|
+
intent: 'unknown',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const base = toString36Match ? 36 : 16;
|
|
167
|
+
// Check for truncation methods
|
|
168
|
+
const substringMatch = lineContent.match(/\.substring\((\d+)(?:,\s*(\d+))?\)/);
|
|
169
|
+
const sliceMatch = lineContent.match(/\.slice\((\d+)(?:,\s*(\d+))?\)/);
|
|
170
|
+
const substrMatch = lineContent.match(/\.substr\((\d+)(?:,\s*(\d+))?\)/);
|
|
171
|
+
const truncMatch = substringMatch || sliceMatch || substrMatch;
|
|
172
|
+
if (!truncMatch) {
|
|
173
|
+
return {
|
|
174
|
+
hasToString: true,
|
|
175
|
+
base,
|
|
176
|
+
isTruncated: false,
|
|
177
|
+
truncationLength: null,
|
|
178
|
+
intent: 'full-token',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// Calculate truncation length
|
|
182
|
+
const start = parseInt(truncMatch[1]);
|
|
183
|
+
const end = truncMatch[2] ? parseInt(truncMatch[2]) : null;
|
|
184
|
+
// If no end specified (e.g., .substring(7)), the result is from start to end of string
|
|
185
|
+
// Math.random().toString(36) produces ~11 chars like "0.abc123def"
|
|
186
|
+
// .substring(2) gives ~9 chars, .substring(7) gives ~4 chars
|
|
187
|
+
// Estimate remaining length: ~11 - start
|
|
188
|
+
const estimatedFullLength = 11;
|
|
189
|
+
const length = end ? end - start : (start >= 2 ? estimatedFullLength - start : null);
|
|
190
|
+
// Classify intent by length
|
|
191
|
+
// Short (2-9 chars): UI correlation IDs, React keys
|
|
192
|
+
// Medium (10-15 chars): Business IDs, order numbers
|
|
193
|
+
if (length && length <= 9) {
|
|
194
|
+
return {
|
|
195
|
+
hasToString: true,
|
|
196
|
+
base,
|
|
197
|
+
isTruncated: true,
|
|
198
|
+
truncationLength: length,
|
|
199
|
+
intent: 'short-ui-id',
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else if (length && length <= 15) {
|
|
203
|
+
return {
|
|
204
|
+
hasToString: true,
|
|
205
|
+
base,
|
|
206
|
+
isTruncated: true,
|
|
207
|
+
truncationLength: length,
|
|
208
|
+
intent: 'business-id',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return {
|
|
213
|
+
hasToString: true,
|
|
214
|
+
base,
|
|
215
|
+
isTruncated: true,
|
|
216
|
+
truncationLength: length,
|
|
217
|
+
intent: 'business-id',
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Extract variable name from Math.random() assignment
|
|
223
|
+
* Examples:
|
|
224
|
+
* const token = Math.random() -> "token"
|
|
225
|
+
* const businessId = Math.random().toString(36) -> "businessId"
|
|
226
|
+
* return Math.random() -> null (no variable)
|
|
227
|
+
*/
|
|
228
|
+
function extractMathRandomVariableName(lineContent) {
|
|
229
|
+
// const/let/var variableName = Math.random...
|
|
230
|
+
const assignmentMatch = lineContent.match(/(?:const|let|var)\s+(\w+)\s*=.*Math\.random/);
|
|
231
|
+
if (assignmentMatch)
|
|
232
|
+
return assignmentMatch[1];
|
|
233
|
+
// object.property = Math.random...
|
|
234
|
+
const propertyMatch = lineContent.match(/(\w+)\s*[:=]\s*Math\.random/);
|
|
235
|
+
if (propertyMatch)
|
|
236
|
+
return propertyMatch[1];
|
|
237
|
+
// function parameter default: functionName(param = Math.random())
|
|
238
|
+
const paramMatch = lineContent.match(/(\w+)\s*=\s*Math\.random/);
|
|
239
|
+
if (paramMatch)
|
|
240
|
+
return paramMatch[1];
|
|
241
|
+
return null; // No variable name found
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Classify variable name security risk based on naming patterns
|
|
245
|
+
*
|
|
246
|
+
* High risk: Security-sensitive names (token, secret, key, etc.)
|
|
247
|
+
* Medium risk: Unclear context
|
|
248
|
+
* Low risk: Non-security names (id, businessId, orderId, etc.)
|
|
249
|
+
*/
|
|
250
|
+
function classifyVariableNameRisk(varName) {
|
|
251
|
+
if (!varName)
|
|
252
|
+
return 'medium'; // Unknown usage, moderate risk
|
|
253
|
+
const lower = varName.toLowerCase();
|
|
254
|
+
// High risk: security-sensitive variable names
|
|
255
|
+
// Note: 'key' alone is NOT included - it often means React key, not crypto key
|
|
256
|
+
// Instead, we match specific security key patterns
|
|
257
|
+
const highRiskPatterns = [
|
|
258
|
+
'token',
|
|
259
|
+
'secret',
|
|
260
|
+
'password',
|
|
261
|
+
'credential',
|
|
262
|
+
'signature',
|
|
263
|
+
'salt',
|
|
264
|
+
'nonce',
|
|
265
|
+
'session',
|
|
266
|
+
'csrf',
|
|
267
|
+
'auth',
|
|
268
|
+
'apikey',
|
|
269
|
+
'secretkey',
|
|
270
|
+
'privatekey',
|
|
271
|
+
'encryptionkey',
|
|
272
|
+
'accesstoken',
|
|
273
|
+
'refreshtoken',
|
|
274
|
+
'jwt',
|
|
275
|
+
'bearer',
|
|
276
|
+
'oauth',
|
|
277
|
+
'sessionid',
|
|
278
|
+
];
|
|
279
|
+
if (highRiskPatterns.some(p => lower.includes(p))) {
|
|
280
|
+
return 'high';
|
|
281
|
+
}
|
|
282
|
+
// Low risk: clearly non-security contexts
|
|
283
|
+
const lowRiskPatterns = [
|
|
284
|
+
// Business identifiers
|
|
285
|
+
'id',
|
|
286
|
+
'uid',
|
|
287
|
+
'guid',
|
|
288
|
+
'business',
|
|
289
|
+
'order',
|
|
290
|
+
'invoice',
|
|
291
|
+
'customer',
|
|
292
|
+
'user',
|
|
293
|
+
'product',
|
|
294
|
+
'item',
|
|
295
|
+
'transaction',
|
|
296
|
+
'request',
|
|
297
|
+
'reference',
|
|
298
|
+
'tracking',
|
|
299
|
+
'confirmation',
|
|
300
|
+
// Test/demo data
|
|
301
|
+
'test',
|
|
302
|
+
'mock',
|
|
303
|
+
'demo',
|
|
304
|
+
'sample',
|
|
305
|
+
'example',
|
|
306
|
+
'fixture',
|
|
307
|
+
'random',
|
|
308
|
+
'temp',
|
|
309
|
+
'temporary',
|
|
310
|
+
'generated',
|
|
311
|
+
'dummy',
|
|
312
|
+
// UI identifiers (checked after high-risk, so 'apikey' etc. already caught)
|
|
313
|
+
'key',
|
|
314
|
+
'toast',
|
|
315
|
+
'notification',
|
|
316
|
+
'element',
|
|
317
|
+
'component',
|
|
318
|
+
'widget',
|
|
319
|
+
'modal',
|
|
320
|
+
'dialog',
|
|
321
|
+
'popup',
|
|
322
|
+
'unique',
|
|
323
|
+
'react',
|
|
324
|
+
// Non-security randomness usage (backoff/sampling/experiments)
|
|
325
|
+
'jitter',
|
|
326
|
+
'retry',
|
|
327
|
+
'backoff',
|
|
328
|
+
'delay',
|
|
329
|
+
'timeout',
|
|
330
|
+
'latency',
|
|
331
|
+
'sample',
|
|
332
|
+
'sampling',
|
|
333
|
+
'probability',
|
|
334
|
+
'chance',
|
|
335
|
+
'rollout',
|
|
336
|
+
'experiment',
|
|
337
|
+
'abtest',
|
|
338
|
+
'cohort',
|
|
339
|
+
'bucket',
|
|
340
|
+
'variant',
|
|
341
|
+
];
|
|
342
|
+
if (lowRiskPatterns.some(p => lower.includes(p))) {
|
|
343
|
+
return 'low';
|
|
344
|
+
}
|
|
345
|
+
return 'medium'; // Unclear context, moderate risk
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Analyze surrounding code context for security signals
|
|
349
|
+
* Returns context type and description for severity classification
|
|
350
|
+
*/
|
|
351
|
+
function analyzeMathRandomContext(content, filePath, lineNumber) {
|
|
352
|
+
const lines = content.split('\n');
|
|
353
|
+
const start = Math.max(0, lineNumber - 10);
|
|
354
|
+
const end = Math.min(lines.length, lineNumber + 5);
|
|
355
|
+
const context = lines.slice(start, end).join('\n');
|
|
356
|
+
// Security context indicators (functions, imports, comments)
|
|
357
|
+
const securityPatterns = [
|
|
358
|
+
/\b(generate|create)(Token|Secret|Key|Password|Nonce|Salt|Session|Signature)/i,
|
|
359
|
+
/\b(auth|crypto|encrypt|decrypt|hash|sign)\b/i,
|
|
360
|
+
/function\s+.*(?:token|secret|key|auth|crypto)/i,
|
|
361
|
+
/\bimport.*(?:crypto|jsonwebtoken|bcrypt|argon2|jose)/i,
|
|
362
|
+
/\/\*.*(?:security|authentication|cryptograph|authorization)/i,
|
|
363
|
+
/\/\/.*(?:security|auth|crypto|token|secret)/i,
|
|
364
|
+
];
|
|
365
|
+
const inSecurityContext = securityPatterns.some(p => p.test(context));
|
|
366
|
+
// Test context
|
|
367
|
+
const testFilePatterns = /\.(test|spec)\.(ts|tsx|js|jsx)$/i;
|
|
368
|
+
const testContextPatterns = [
|
|
369
|
+
/\b(describe|it|test|expect|mock|jest|vitest|mocha|chai)\b/i,
|
|
370
|
+
/\b(beforeEach|afterEach|beforeAll|afterAll)\b/i,
|
|
371
|
+
/\b(fixture|stub|spy)\b/i,
|
|
372
|
+
];
|
|
373
|
+
const inTestContext = testFilePatterns.test(filePath) ||
|
|
374
|
+
testContextPatterns.some(p => p.test(context));
|
|
375
|
+
// UI/cosmetic context (reuse existing logic)
|
|
376
|
+
const lineContent = lines[lineNumber];
|
|
377
|
+
const inUIContext = isCosmeticMathRandom(lineContent, content, lineNumber);
|
|
378
|
+
// Business logic context (non-security ID generation)
|
|
379
|
+
// Note: UUID/CAPTCHA patterns excluded - handled by functionIntent classification
|
|
380
|
+
const businessLogicPatterns = [
|
|
381
|
+
/\b(business|order|invoice|customer|product|transaction)Id\b/i,
|
|
382
|
+
/\b(reference|tracking|confirmation)Number\b/i,
|
|
383
|
+
/\b(backoff|retry|jitter|delay|timeout|latency)\b/i,
|
|
384
|
+
/\b(sample|sampling|probability|chance|rollout|experiment|abtest|cohort|bucket|variant)\b/i,
|
|
385
|
+
];
|
|
386
|
+
const inBusinessLogicContext = businessLogicPatterns.some(p => p.test(context)) && !inSecurityContext;
|
|
387
|
+
// Determine context description
|
|
388
|
+
let contextDescription = 'unknown context';
|
|
389
|
+
if (inSecurityContext) {
|
|
390
|
+
contextDescription = 'security-sensitive function';
|
|
391
|
+
}
|
|
392
|
+
else if (inTestContext) {
|
|
393
|
+
contextDescription = 'test/mock data generation';
|
|
394
|
+
}
|
|
395
|
+
else if (inUIContext) {
|
|
396
|
+
contextDescription = 'UI/cosmetic usage';
|
|
397
|
+
}
|
|
398
|
+
else if (inBusinessLogicContext) {
|
|
399
|
+
contextDescription = 'non-security usage';
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
inSecurityContext,
|
|
403
|
+
inTestContext,
|
|
404
|
+
inUIContext,
|
|
405
|
+
inBusinessLogicContext,
|
|
406
|
+
contextDescription,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Check if Math.random() should be skipped entirely
|
|
411
|
+
* Returns true for seed files, test fixtures, captcha/puzzle, uuid, and pure cosmetic uses
|
|
412
|
+
*/
|
|
413
|
+
function shouldSkipMathRandom(content, filePath, lineNumber) {
|
|
414
|
+
// Seed/data generation files - skip entirely
|
|
415
|
+
if ((0, context_helpers_1.isSeedOrDataGenFile)(filePath)) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
// Educational/intentional vulnerability files - skip entirely
|
|
419
|
+
// These include OWASP Juice Shop, intentionally-vulnerable examples, etc.
|
|
420
|
+
if ((0, context_helpers_1.isEducationalVulnerabilityFile)(filePath)) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
// Test files with test fixture patterns
|
|
424
|
+
if ((0, context_helpers_1.isTestOrMockFile)(filePath)) {
|
|
425
|
+
const lines = content.split('\n');
|
|
426
|
+
const line = lines[lineNumber];
|
|
427
|
+
// If in a test file and generating test data, skip
|
|
428
|
+
if (/\b(mock|fake|fixture|test)Data/i.test(line) ||
|
|
429
|
+
/\b(it|test|describe)\s*\(/.test(line)) {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
// Pure cosmetic usage (CSS values, animations)
|
|
434
|
+
const lines = content.split('\n');
|
|
435
|
+
const lineContent = lines[lineNumber] || '';
|
|
436
|
+
if (isCosmeticMathRandom(lineContent, content, lineNumber)) {
|
|
437
|
+
// Additional check: if this is for animation/style, truly skip
|
|
438
|
+
const pureStylePatterns = [
|
|
439
|
+
/\.style\./,
|
|
440
|
+
/animation/i,
|
|
441
|
+
/transform/i,
|
|
442
|
+
/opacity/i,
|
|
443
|
+
/\brgb/i,
|
|
444
|
+
/\bhsl/i,
|
|
445
|
+
];
|
|
446
|
+
if (pureStylePatterns.some(p => p.test(lineContent))) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// Check function context for demo/seed/captcha/uuid functions
|
|
451
|
+
const functionName = (0, control_flow_1.extractFunctionContext)(content, lineNumber);
|
|
452
|
+
const functionIntent = classifyFunctionIntent(functionName);
|
|
453
|
+
// Skip demo, captcha, and uuid functions entirely - these are legitimate uses
|
|
454
|
+
if (functionIntent === 'demo' || functionIntent === 'captcha' || functionIntent === 'uuid') {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=math-random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-random.js","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/math-random.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAcH,oDAkGC;AAMD,wDAiDC;AAMD,wDAgFC;AASD,sEAkBC;AASD,4DAqGC;AAMD,4DAwEC;AAMD,oDAyDC;AAjhBD,iEAIoC;AACpC,uDAA6D;AAE7D;;;;GAIG;AACH,SAAgB,oBAAoB,CAClC,WAAmB,EACnB,OAAe,EACf,UAAkB;IAElB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEjC,gDAAgD;IAChD,MAAM,oBAAoB,GAAG;QAC3B,mBAAmB;QACnB,yCAAyC,EAAE,gCAAgC;QAC3E,mCAAmC,EAAE,2BAA2B;QAChE,iDAAiD,EAAE,iBAAiB;QACpE,8BAA8B,EAAE,mBAAmB;QACnD,+BAA+B,EAAE,gCAAgC;QACjE,gCAAgC,EAAE,iCAAiC;QACnE,kCAAkC,EAAE,yBAAyB;QAC7D,oCAAoC,EAAE,4BAA4B;QAClE,yBAAyB,EAAE,8BAA8B;QACzD,4BAA4B,EAAE,iCAAiC;QAC/D,wBAAwB,EAAE,2BAA2B;QACrD,yBAAyB;QACzB,wBAAwB,EAAE,gCAAgC;QAC1D,sBAAsB,EAAE,gCAAgC;QACxD,wBAAwB,EAAE,oCAAoC;QAC9D,wBAAwB,EAAE,mCAAmC;QAC7D,kCAAkC;QAClC,uCAAuC,EAAE,2CAA2C;QACpF,6BAA6B,EAAE,sCAAsC;QACrE,wBAAwB;QACxB,4CAA4C,EAAE,kCAAkC;QAChF,4CAA4C,EAAE,oCAAoC;QAClF,2CAA2C,EAAE,8BAA8B;QAC3E,4EAA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AC;YAC5C,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,EACtC,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IAC3C,IAAI,oBAAoB,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;QAC3D,+DAA+D;QAC/D,MAAM,iBAAiB,GAAG;YACxB,WAAW;YACX,YAAY;YACZ,YAAY;YACZ,UAAU;YACV,QAAQ;YACR,QAAQ;SACT,CAAA;QACD,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YACrD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,8DAA8D;IAC9D,MAAM,YAAY,GAAG,IAAA,qCAAsB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAChE,MAAM,cAAc,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAA;IAE3D,8EAA8E;IAC9E,IAAI,cAAc,KAAK,MAAM,IAAI,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;QAC3F,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dangerous Function Pattern Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module defines the patterns for detecting dangerous function calls.
|
|
5
|
+
* These patterns are used by the main detection engine.
|
|
6
|
+
*/
|
|
7
|
+
import type { VulnerabilitySeverity } from '../../types';
|
|
8
|
+
export interface DangerousFunctionPattern {
|
|
9
|
+
name: string;
|
|
10
|
+
pattern: RegExp;
|
|
11
|
+
severity: VulnerabilitySeverity;
|
|
12
|
+
description: string;
|
|
13
|
+
suggestedFix: string;
|
|
14
|
+
languages?: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const DANGEROUS_FUNCTIONS: DangerousFunctionPattern[];
|
|
17
|
+
/**
|
|
18
|
+
* Check if file matches language filter
|
|
19
|
+
*/
|
|
20
|
+
export declare function matchesLanguage(filePath: string, languages?: string[]): boolean;
|
|
21
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../../src/layer2/dangerous-functions/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAED,eAAO,MAAM,mBAAmB,EAAE,wBAAwB,EA4IzD,CAAA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAU/E"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dangerous Function Pattern Definitions
|
|
4
|
+
*
|
|
5
|
+
* This module defines the patterns for detecting dangerous function calls.
|
|
6
|
+
* These patterns are used by the main detection engine.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DANGEROUS_FUNCTIONS = void 0;
|
|
10
|
+
exports.matchesLanguage = matchesLanguage;
|
|
11
|
+
exports.DANGEROUS_FUNCTIONS = [
|
|
12
|
+
// Code execution
|
|
13
|
+
{
|
|
14
|
+
name: 'eval() usage',
|
|
15
|
+
pattern: /\beval\s*\(/gi,
|
|
16
|
+
severity: 'critical',
|
|
17
|
+
description: 'eval() executes arbitrary code and is a major security risk',
|
|
18
|
+
suggestedFix: 'Use JSON.parse() for JSON data, or refactor to avoid dynamic code execution',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'Function constructor',
|
|
22
|
+
pattern: /new\s+Function\s*\(/gi,
|
|
23
|
+
severity: 'critical',
|
|
24
|
+
description: 'Function constructor can execute arbitrary code like eval()',
|
|
25
|
+
suggestedFix: 'Refactor to use static functions or safe alternatives',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'setTimeout/setInterval with string',
|
|
29
|
+
pattern: /set(Timeout|Interval)\s*\(\s*['"`]/gi,
|
|
30
|
+
severity: 'high',
|
|
31
|
+
description: 'setTimeout/setInterval with string argument acts like eval()',
|
|
32
|
+
suggestedFix: 'Pass a function reference instead of a string',
|
|
33
|
+
},
|
|
34
|
+
// Command injection
|
|
35
|
+
{
|
|
36
|
+
name: 'child_process exec',
|
|
37
|
+
pattern: /\b(exec|execSync|spawn|spawnSync|execFile)\s*\(/gi,
|
|
38
|
+
severity: 'high',
|
|
39
|
+
description: 'Shell command execution can lead to command injection',
|
|
40
|
+
suggestedFix: 'Validate and sanitize all inputs, prefer execFile over exec',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'os.system/subprocess (Python)',
|
|
44
|
+
pattern: /\b(os\.system|subprocess\.(call|run|Popen|check_output))\s*\(/gi,
|
|
45
|
+
severity: 'high',
|
|
46
|
+
description: 'Shell command execution can lead to command injection',
|
|
47
|
+
suggestedFix: 'Use subprocess with shell=False and pass arguments as a list',
|
|
48
|
+
languages: ['py'],
|
|
49
|
+
},
|
|
50
|
+
// SQL injection risks
|
|
51
|
+
{
|
|
52
|
+
name: 'Raw SQL query construction',
|
|
53
|
+
pattern: /\.(query|execute|raw)\s*\(\s*[`'"].*\$\{|\.query\s*\(\s*['"].*\+/gi,
|
|
54
|
+
severity: 'critical',
|
|
55
|
+
description: 'String concatenation in SQL queries can lead to SQL injection',
|
|
56
|
+
suggestedFix: 'Use parameterized queries or prepared statements',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'SQL template literal',
|
|
60
|
+
pattern: /`SELECT.*FROM.*WHERE.*\$\{|`INSERT.*INTO.*VALUES.*\$\{|`UPDATE.*SET.*\$\{|`DELETE.*FROM.*WHERE.*\$\{/gi,
|
|
61
|
+
severity: 'critical',
|
|
62
|
+
description: 'Template literals in SQL queries can lead to SQL injection',
|
|
63
|
+
suggestedFix: 'Use parameterized queries with placeholders (?, $1, etc.)',
|
|
64
|
+
},
|
|
65
|
+
// XSS risks
|
|
66
|
+
{
|
|
67
|
+
name: 'innerHTML assignment',
|
|
68
|
+
pattern: /\.innerHTML\s*=|\.outerHTML\s*=/gi,
|
|
69
|
+
severity: 'high',
|
|
70
|
+
description: 'Direct innerHTML assignment can lead to XSS vulnerabilities',
|
|
71
|
+
suggestedFix: 'Use textContent for text, or sanitize HTML with DOMPurify',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'document.write',
|
|
75
|
+
pattern: /document\.write\s*\(/gi,
|
|
76
|
+
severity: 'high',
|
|
77
|
+
description: 'document.write can introduce XSS vulnerabilities',
|
|
78
|
+
suggestedFix: 'Use DOM manipulation methods instead',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'dangerouslySetInnerHTML',
|
|
82
|
+
pattern: /dangerouslySetInnerHTML\s*=\s*\{\s*\{\s*__html\s*:/gi,
|
|
83
|
+
severity: 'high',
|
|
84
|
+
description: 'dangerouslySetInnerHTML can lead to XSS if content is not sanitized',
|
|
85
|
+
suggestedFix: 'Sanitize HTML content with DOMPurify before rendering',
|
|
86
|
+
},
|
|
87
|
+
// Deserialization
|
|
88
|
+
{
|
|
89
|
+
name: 'Unsafe deserialization',
|
|
90
|
+
pattern: /\b(pickle\.loads?|yaml\.load\s*\((?!.*Loader)|unserialize|Marshal\.load)\s*\(/gi,
|
|
91
|
+
severity: 'critical',
|
|
92
|
+
description: 'Unsafe deserialization can lead to remote code execution',
|
|
93
|
+
suggestedFix: 'Use safe loaders (yaml.safe_load) or validate input before deserializing',
|
|
94
|
+
},
|
|
95
|
+
// Note: JSON.parse is handled specially with source-aware severity - see json-parse.ts
|
|
96
|
+
// Note: request.json() is NOT a dangerous function - see request-validation.ts
|
|
97
|
+
// File system risks
|
|
98
|
+
{
|
|
99
|
+
name: 'Dynamic file path',
|
|
100
|
+
pattern: /\b(readFile|writeFile|readFileSync|writeFileSync|createReadStream|createWriteStream)\s*\(\s*[^'"]/gi,
|
|
101
|
+
severity: 'medium',
|
|
102
|
+
description: 'Dynamic file paths can lead to path traversal attacks',
|
|
103
|
+
suggestedFix: 'Validate and sanitize file paths, use path.resolve with a base directory',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'Path traversal risk',
|
|
107
|
+
pattern: /path\.(join|resolve)\s*\([^)]*req\.(params|query|body)/gi,
|
|
108
|
+
severity: 'high',
|
|
109
|
+
description: 'User input in file paths can lead to path traversal attacks',
|
|
110
|
+
suggestedFix: 'Validate paths and ensure they stay within allowed directories',
|
|
111
|
+
},
|
|
112
|
+
// Crypto weaknesses
|
|
113
|
+
{
|
|
114
|
+
name: 'Math.random for security',
|
|
115
|
+
pattern: /Math\.random\s*\(\s*\)/gi,
|
|
116
|
+
severity: 'medium',
|
|
117
|
+
description: 'Math.random() is not cryptographically secure',
|
|
118
|
+
suggestedFix: 'Use crypto.randomBytes() or crypto.getRandomValues() for security-sensitive operations',
|
|
119
|
+
},
|
|
120
|
+
// Regex DoS
|
|
121
|
+
{
|
|
122
|
+
name: 'Potentially unsafe regex',
|
|
123
|
+
pattern: /new\s+RegExp\s*\(\s*[^'"]/gi,
|
|
124
|
+
severity: 'medium',
|
|
125
|
+
description: 'Dynamic regex construction can lead to ReDoS attacks',
|
|
126
|
+
suggestedFix: 'Validate regex patterns and consider using safe-regex library',
|
|
127
|
+
},
|
|
128
|
+
// Prototype pollution
|
|
129
|
+
{
|
|
130
|
+
name: 'Object.assign with user input',
|
|
131
|
+
pattern: /Object\.assign\s*\(\s*\{\s*\}\s*,\s*(req\.|request\.|body|params|query)/gi,
|
|
132
|
+
severity: 'high',
|
|
133
|
+
description: 'Object.assign with user input can lead to prototype pollution',
|
|
134
|
+
suggestedFix: 'Validate and sanitize input, or use a safe merge function',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'Spread operator with user input',
|
|
138
|
+
pattern: /\{\s*\.\.\.req\.(body|params|query)|\.\.\.request\.(body|params|query)/gi,
|
|
139
|
+
severity: 'medium',
|
|
140
|
+
description: 'Spreading user input can lead to mass assignment vulnerabilities',
|
|
141
|
+
suggestedFix: 'Explicitly pick allowed properties instead of spreading all input',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
/**
|
|
145
|
+
* Check if file matches language filter
|
|
146
|
+
*/
|
|
147
|
+
function matchesLanguage(filePath, languages) {
|
|
148
|
+
if (!languages || languages.length === 0)
|
|
149
|
+
return true;
|
|
150
|
+
const ext = filePath.split('.').pop()?.toLowerCase() || '';
|
|
151
|
+
return languages.some(lang => {
|
|
152
|
+
if (lang === 'py')
|
|
153
|
+
return ext === 'py';
|
|
154
|
+
if (lang === 'js')
|
|
155
|
+
return ['js', 'jsx', 'mjs', 'cjs'].includes(ext);
|
|
156
|
+
if (lang === 'ts')
|
|
157
|
+
return ['ts', 'tsx'].includes(ext);
|
|
158
|
+
return ext === lang;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=patterns.js.map
|