octocode-cli 1.2.6 → 1.2.7
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/LICENSE +21 -63
- package/README.md +85 -142
- package/out/octocode-cli.js +7026 -6945
- package/package.json +8 -6
- package/skills/README.md +97 -120
- package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
- package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
- package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
- package/skills/octocode-code-engineer/README.md +178 -0
- package/skills/octocode-code-engineer/SKILL.md +418 -0
- package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
- package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
- package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
- package/skills/octocode-code-engineer/coverage/base.css +224 -0
- package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
- package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
- package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
- package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
- package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
- package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
- package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
- package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
- package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
- package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
- package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
- package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
- package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
- package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
- package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
- package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
- package/skills/octocode-code-engineer/coverage/index.html +536 -0
- package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
- package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
- package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
- package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
- package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
- package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
- package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
- package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
- package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
- package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
- package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
- package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
- package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
- package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
- package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
- package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
- package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
- package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
- package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
- package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
- package/skills/octocode-code-engineer/package.json +54 -0
- package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
- package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
- package/skills/octocode-code-engineer/references/ast-search.md +210 -0
- package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
- package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
- package/skills/octocode-code-engineer/references/concepts.md +107 -0
- package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
- package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
- package/skills/octocode-code-engineer/references/output-files.md +144 -0
- package/skills/octocode-code-engineer/references/playbooks.md +204 -0
- package/skills/octocode-code-engineer/references/present-results.md +136 -0
- package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
- package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
- package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
- package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
- package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
- package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
- package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
- package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
- package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
- package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
- package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
- package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
- package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
- package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
- package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
- package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
- package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
- package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
- package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
- package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
- package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
- package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
- package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
- package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
- package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
- package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
- package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
- package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
- package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
- package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
- package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
- package/skills/octocode-code-engineer/src/index.ts +403 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
- package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
- package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
- package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
- package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
- package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
- package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
- package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
- package/skills/octocode-code-engineer/src/types/index.ts +80 -0
- package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
- package/skills/octocode-code-engineer/tsconfig.json +17 -0
- package/skills/octocode-code-engineer/vitest.config.ts +8 -0
- package/skills/octocode-documentation-writer/README.md +113 -0
- package/skills/octocode-documentation-writer/SKILL.md +886 -0
- package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
- package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
- package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
- package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
- package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
- package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
- package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
- package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
- package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
- package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
- package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
- package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
- package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
- package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
- package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
- package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
- package/skills/octocode-plan/SKILL.md +122 -116
- package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
- package/skills/octocode-pull-request-reviewer/README.md +249 -0
- package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
- package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
- package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
- package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
- package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
- package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
- package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
- package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
- package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
- package/skills/octocode-research/.claude/settings.local.json +46 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
- package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
- package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
- package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
- package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
- package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
- package/skills/octocode-research/AGENTS.md +349 -0
- package/skills/octocode-research/README.md +494 -0
- package/skills/octocode-research/SKILL.md +652 -274
- package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
- package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
- package/skills/octocode-research/docs/FLOWS.md +577 -0
- package/skills/octocode-research/docs/OVERVIEW.md +564 -0
- package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
- package/skills/octocode-research/ecosystem.config.cjs +88 -0
- package/skills/octocode-research/eslint.config.mjs +27 -0
- package/skills/octocode-research/package.json +84 -0
- package/skills/octocode-research/references/GUARDRAILS.md +40 -0
- package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
- package/skills/octocode-research/references/roast-prompt.md +149 -0
- package/skills/octocode-research/scripts/server-init.d.ts +2 -0
- package/skills/octocode-research/scripts/server-init.js +2 -0
- package/skills/octocode-research/scripts/server.d.ts +8 -0
- package/skills/octocode-research/scripts/server.js +445 -0
- package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
- package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
- package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
- package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
- package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
- package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
- package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
- package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
- package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
- package/skills/octocode-research/src/index.ts +186 -0
- package/skills/octocode-research/src/mcpCache.ts +49 -0
- package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
- package/skills/octocode-research/src/middleware/logger.ts +61 -0
- package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
- package/skills/octocode-research/src/middleware/readiness.ts +17 -0
- package/skills/octocode-research/src/routes/github.ts +197 -0
- package/skills/octocode-research/src/routes/local.ts +175 -0
- package/skills/octocode-research/src/routes/lsp.ts +177 -0
- package/skills/octocode-research/src/routes/package.ts +127 -0
- package/skills/octocode-research/src/routes/prompts.ts +138 -0
- package/skills/octocode-research/src/routes/tools.ts +677 -0
- package/skills/octocode-research/src/server-init.ts +363 -0
- package/skills/octocode-research/src/server.ts +285 -0
- package/skills/octocode-research/src/types/errorGuards.ts +151 -0
- package/skills/octocode-research/src/types/express.d.ts +76 -0
- package/skills/octocode-research/src/types/guards.ts +98 -0
- package/skills/octocode-research/src/types/mcp.ts +119 -0
- package/skills/octocode-research/src/types/responses.ts +199 -0
- package/skills/octocode-research/src/types/toolTypes.ts +33 -0
- package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
- package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
- package/skills/octocode-research/src/utils/colors.ts +53 -0
- package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
- package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
- package/skills/octocode-research/src/utils/logger.ts +413 -0
- package/skills/octocode-research/src/utils/resilience.ts +169 -0
- package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
- package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
- package/skills/octocode-research/src/utils/responseParser.ts +272 -0
- package/skills/octocode-research/src/utils/retry.ts +280 -0
- package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
- package/skills/octocode-research/src/utils/url.ts +20 -0
- package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
- package/skills/octocode-research/src/validation/index.ts +2 -0
- package/skills/octocode-research/src/validation/schemas.ts +578 -0
- package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
- package/skills/octocode-research/tsconfig.json +21 -0
- package/skills/octocode-research/tsdown.config.ts +42 -0
- package/skills/octocode-research/vitest.config.ts +20 -0
- package/skills/octocode-researcher/SKILL.md +461 -0
- package/skills/octocode-researcher/references/fallbacks.md +120 -0
- package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
- package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
- package/skills/octocode-rfc-generator/SKILL.md +223 -0
- package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
- package/skills/octocode-roast/SKILL.md +63 -21
- package/skills/octocode-implement/SKILL.md +0 -293
- package/skills/octocode-implement/references/execution-phases.md +0 -317
- package/skills/octocode-implement/references/tool-reference.md +0 -403
- package/skills/octocode-implement/references/workflow-patterns.md +0 -385
- package/skills/octocode-local-search/SKILL.md +0 -449
- package/skills/octocode-pr-review/SKILL.md +0 -391
- package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
- package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
- package/skills/octocode-pr-review/references/research-flows.md +0 -75
- package/skills/octocode-research/references/tool-reference.md +0 -304
- package/skills/octocode-research/references/workflow-patterns.md +0 -325
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
import { isTestFile } from '../common/utils.js';
|
|
2
|
+
|
|
3
|
+
import type { FileEntry, Finding } from '../types/index.js';
|
|
4
|
+
|
|
5
|
+
type FindingDraft = Omit<Finding, 'id'>;
|
|
6
|
+
|
|
7
|
+
const NESTED_QUANTIFIER_RE = /(\(.+[+*]\))[+*]|(\(.+\?\))\{/;
|
|
8
|
+
|
|
9
|
+
const toSecurityFinding = (
|
|
10
|
+
draft: FindingDraft,
|
|
11
|
+
ruleId: string,
|
|
12
|
+
confidence: 'high' | 'medium' | 'low',
|
|
13
|
+
evidence: Record<string, unknown>
|
|
14
|
+
): FindingDraft => ({
|
|
15
|
+
...draft,
|
|
16
|
+
ruleId,
|
|
17
|
+
confidence,
|
|
18
|
+
evidence,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export function detectHardcodedSecrets(
|
|
22
|
+
fileSummaries: FileEntry[]
|
|
23
|
+
): FindingDraft[] {
|
|
24
|
+
const findings: FindingDraft[] = [];
|
|
25
|
+
for (const entry of fileSummaries) {
|
|
26
|
+
if (isTestFile(entry.file)) continue;
|
|
27
|
+
const secrets = (entry.suspiciousStrings || []).filter(
|
|
28
|
+
s =>
|
|
29
|
+
s.kind === 'hardcoded-secret' &&
|
|
30
|
+
s.context !== 'regex-definition' &&
|
|
31
|
+
s.context !== 'error-message'
|
|
32
|
+
);
|
|
33
|
+
if (secrets.length === 0) continue;
|
|
34
|
+
for (const s of secrets) {
|
|
35
|
+
findings.push(
|
|
36
|
+
toSecurityFinding(
|
|
37
|
+
{
|
|
38
|
+
severity: 'high',
|
|
39
|
+
category: 'hardcoded-secret',
|
|
40
|
+
file: entry.file,
|
|
41
|
+
lineStart: s.lineStart,
|
|
42
|
+
lineEnd: s.lineEnd,
|
|
43
|
+
title: `Potential hardcoded secret${s.snippet ? `: ${s.snippet.slice(0, 20)}…` : ''}`,
|
|
44
|
+
reason: `String literal matches a secret pattern (password, API key, token, high-entropy string). Secrets in source code risk credential leaks. Validate: use localSearchCode to find the variable, then lspFindReferences to check if it is used in auth or network calls.`,
|
|
45
|
+
files: [entry.file],
|
|
46
|
+
suggestedFix: {
|
|
47
|
+
strategy:
|
|
48
|
+
'Move secret to environment variable or secrets manager.',
|
|
49
|
+
steps: [
|
|
50
|
+
'Replace the hardcoded value with process.env.YOUR_SECRET.',
|
|
51
|
+
'Add the variable to your .env file (excluded from git).',
|
|
52
|
+
'Verify the secret is not committed in git history.',
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
impact:
|
|
56
|
+
'Credential leak in source code exposes API access, database credentials, or authentication tokens to anyone with repo access.',
|
|
57
|
+
tags: ['security', 'secrets'],
|
|
58
|
+
lspHints: [
|
|
59
|
+
{
|
|
60
|
+
tool: 'lspFindReferences',
|
|
61
|
+
symbolName: s.snippet?.split(/[=:]/)[0]?.trim() || 'secret',
|
|
62
|
+
lineHint: s.lineStart,
|
|
63
|
+
file: entry.file,
|
|
64
|
+
expectedResult: `find all usages of this secret value — if used only in tests or as a regex pattern, it is a false positive`,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
'security.hardcoded-secret',
|
|
69
|
+
'high',
|
|
70
|
+
{
|
|
71
|
+
source: s.snippet || '',
|
|
72
|
+
sink: 'runtime usage',
|
|
73
|
+
context: s.context || 'literal',
|
|
74
|
+
sanitizerStatus: 'missing',
|
|
75
|
+
propagationSteps: [`${entry.file}:${s.lineStart}`],
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return findings;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function detectEvalUsage(fileSummaries: FileEntry[]): FindingDraft[] {
|
|
85
|
+
const findings: FindingDraft[] = [];
|
|
86
|
+
for (const entry of fileSummaries) {
|
|
87
|
+
if (isTestFile(entry.file)) continue;
|
|
88
|
+
for (const loc of entry.evalUsages || []) {
|
|
89
|
+
findings.push(
|
|
90
|
+
toSecurityFinding(
|
|
91
|
+
{
|
|
92
|
+
severity: 'critical',
|
|
93
|
+
category: 'eval-usage',
|
|
94
|
+
file: entry.file,
|
|
95
|
+
lineStart: loc.lineStart,
|
|
96
|
+
lineEnd: loc.lineEnd,
|
|
97
|
+
title: 'Dynamic code execution (eval/Function)',
|
|
98
|
+
reason:
|
|
99
|
+
'eval(), new Function(), or string-based setTimeout/setInterval allows arbitrary code execution. This is a code injection vector.',
|
|
100
|
+
files: [entry.file],
|
|
101
|
+
suggestedFix: {
|
|
102
|
+
strategy:
|
|
103
|
+
'Replace dynamic code execution with safe alternatives.',
|
|
104
|
+
steps: [
|
|
105
|
+
'For JSON parsing: use JSON.parse() instead of eval().',
|
|
106
|
+
'For dynamic dispatch: use a lookup table or switch statement.',
|
|
107
|
+
'For setTimeout: pass a function reference, not a string.',
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
impact:
|
|
111
|
+
'Arbitrary code execution enables full application takeover — the most severe class of injection vulnerability.',
|
|
112
|
+
tags: ['security', 'injection', 'critical'],
|
|
113
|
+
lspHints: [
|
|
114
|
+
{
|
|
115
|
+
tool: 'lspCallHierarchy',
|
|
116
|
+
symbolName: 'eval',
|
|
117
|
+
lineHint: loc.lineStart,
|
|
118
|
+
file: entry.file,
|
|
119
|
+
expectedResult: `trace callers to find how user input reaches the eval site`,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
'security.eval-usage',
|
|
124
|
+
'high',
|
|
125
|
+
{
|
|
126
|
+
sink: `eval at ${entry.file}:${loc.lineStart}-${loc.lineEnd}`,
|
|
127
|
+
sanitizerStatus: 'missing',
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return findings;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function detectUnsafeHtml(fileSummaries: FileEntry[]): FindingDraft[] {
|
|
137
|
+
const findings: FindingDraft[] = [];
|
|
138
|
+
for (const entry of fileSummaries) {
|
|
139
|
+
if (isTestFile(entry.file)) continue;
|
|
140
|
+
for (const loc of entry.unsafeHtmlAssignments || []) {
|
|
141
|
+
findings.push(
|
|
142
|
+
toSecurityFinding(
|
|
143
|
+
{
|
|
144
|
+
severity: 'high',
|
|
145
|
+
category: 'unsafe-html',
|
|
146
|
+
file: entry.file,
|
|
147
|
+
lineStart: loc.lineStart,
|
|
148
|
+
lineEnd: loc.lineEnd,
|
|
149
|
+
title: 'Unsafe HTML manipulation',
|
|
150
|
+
reason:
|
|
151
|
+
'innerHTML, outerHTML, dangerouslySetInnerHTML, or document.write can execute unsanitized user input as HTML/script. XSS vector.',
|
|
152
|
+
files: [entry.file],
|
|
153
|
+
suggestedFix: {
|
|
154
|
+
strategy: 'Use safe DOM APIs or sanitize input before insertion.',
|
|
155
|
+
steps: [
|
|
156
|
+
'Replace innerHTML with textContent for plain text.',
|
|
157
|
+
'Use a sanitizer library (e.g. DOMPurify) if HTML is required.',
|
|
158
|
+
'In React, avoid dangerouslySetInnerHTML — use JSX instead.',
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
impact:
|
|
162
|
+
'Unsanitized HTML insertion enables cross-site scripting (XSS) — attackers can steal sessions, credentials, or execute actions as the victim.',
|
|
163
|
+
tags: ['security', 'xss'],
|
|
164
|
+
},
|
|
165
|
+
'security.unsafe-html',
|
|
166
|
+
'high',
|
|
167
|
+
{
|
|
168
|
+
sink: 'DOM assignment',
|
|
169
|
+
sanitizerStatus: 'missing',
|
|
170
|
+
propagationSteps: ['html assignment'],
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return findings;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function detectSqlInjectionRisk(
|
|
180
|
+
fileSummaries: FileEntry[]
|
|
181
|
+
): FindingDraft[] {
|
|
182
|
+
const findings: FindingDraft[] = [];
|
|
183
|
+
for (const entry of fileSummaries) {
|
|
184
|
+
if (isTestFile(entry.file)) continue;
|
|
185
|
+
const sqls = (entry.suspiciousStrings || []).filter(
|
|
186
|
+
s => s.kind === 'sql-injection'
|
|
187
|
+
);
|
|
188
|
+
for (const s of sqls) {
|
|
189
|
+
findings.push(
|
|
190
|
+
toSecurityFinding(
|
|
191
|
+
{
|
|
192
|
+
severity: 'high',
|
|
193
|
+
category: 'sql-injection-risk',
|
|
194
|
+
file: entry.file,
|
|
195
|
+
lineStart: s.lineStart,
|
|
196
|
+
lineEnd: s.lineEnd,
|
|
197
|
+
title: 'SQL query built with template literal interpolation',
|
|
198
|
+
reason:
|
|
199
|
+
'Template literals with SQL keywords and interpolated expressions risk SQL injection if user input flows into the query.',
|
|
200
|
+
files: [entry.file],
|
|
201
|
+
suggestedFix: {
|
|
202
|
+
strategy: 'Use parameterized queries or a query builder.',
|
|
203
|
+
steps: [
|
|
204
|
+
'Replace template literal with parameterized query (e.g. db.query(sql, [param])).',
|
|
205
|
+
'Use an ORM or query builder that handles escaping.',
|
|
206
|
+
'If raw SQL is necessary, validate and sanitize all interpolated values.',
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
impact:
|
|
210
|
+
'SQL injection can expose, modify, or destroy database contents and potentially escalate to full server compromise.',
|
|
211
|
+
tags: ['security', 'injection', 'sql'],
|
|
212
|
+
},
|
|
213
|
+
'security.sql-injection-risk',
|
|
214
|
+
'high',
|
|
215
|
+
{
|
|
216
|
+
sink: `sql template literal`,
|
|
217
|
+
sanitizerStatus: 'missing',
|
|
218
|
+
propagationSteps: [`${entry.file}:${s.lineStart}-${s.lineEnd}`],
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return findings;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function detectUnsafeRegex(fileSummaries: FileEntry[]): FindingDraft[] {
|
|
228
|
+
const findings: FindingDraft[] = [];
|
|
229
|
+
for (const entry of fileSummaries) {
|
|
230
|
+
if (isTestFile(entry.file)) continue;
|
|
231
|
+
for (const re of entry.regexLiterals || []) {
|
|
232
|
+
if (NESTED_QUANTIFIER_RE.test(re.pattern)) {
|
|
233
|
+
findings.push(
|
|
234
|
+
toSecurityFinding(
|
|
235
|
+
{
|
|
236
|
+
severity: 'medium',
|
|
237
|
+
category: 'unsafe-regex',
|
|
238
|
+
file: entry.file,
|
|
239
|
+
lineStart: re.lineStart,
|
|
240
|
+
lineEnd: re.lineEnd,
|
|
241
|
+
title: 'Regex with catastrophic backtracking risk',
|
|
242
|
+
reason: `Pattern "${re.pattern.slice(0, 40)}" has nested quantifiers that can cause exponential backtracking (ReDoS).`,
|
|
243
|
+
files: [entry.file],
|
|
244
|
+
suggestedFix: {
|
|
245
|
+
strategy:
|
|
246
|
+
'Simplify the regex or use atomic groups / possessive quantifiers.',
|
|
247
|
+
steps: [
|
|
248
|
+
'Remove nested quantifiers — e.g. change (a+)+ to a+.',
|
|
249
|
+
'Use a regex linter (e.g. safe-regex) to validate patterns.',
|
|
250
|
+
'Consider using string methods instead of complex regexes.',
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
impact:
|
|
254
|
+
'Catastrophic backtracking causes CPU exhaustion — a single crafted input string can hang the event loop (ReDoS).',
|
|
255
|
+
tags: ['security', 'regex', 'performance'],
|
|
256
|
+
lspHints: [
|
|
257
|
+
{
|
|
258
|
+
tool: 'lspFindReferences',
|
|
259
|
+
symbolName: re.pattern.slice(0, 20),
|
|
260
|
+
lineHint: re.lineStart,
|
|
261
|
+
file: entry.file,
|
|
262
|
+
expectedResult: `find where this regex is used to assess if user input reaches it`,
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
},
|
|
266
|
+
'security.unsafe-regex',
|
|
267
|
+
'medium',
|
|
268
|
+
{
|
|
269
|
+
source: re.pattern,
|
|
270
|
+
sink: `Regex execution`,
|
|
271
|
+
sanitizerStatus: 'not-applicable',
|
|
272
|
+
propagationSteps: [`${entry.file}:${re.lineStart}-${re.lineEnd}`],
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return findings;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function detectPrototypePollutionRisk(
|
|
283
|
+
fileSummaries: FileEntry[]
|
|
284
|
+
): FindingDraft[] {
|
|
285
|
+
const findings: FindingDraft[] = [];
|
|
286
|
+
for (const entry of fileSummaries) {
|
|
287
|
+
if (isTestFile(entry.file)) continue;
|
|
288
|
+
if (
|
|
289
|
+
!entry.prototypePollutionSites ||
|
|
290
|
+
entry.prototypePollutionSites.length === 0
|
|
291
|
+
)
|
|
292
|
+
continue;
|
|
293
|
+
for (const site of entry.prototypePollutionSites) {
|
|
294
|
+
let severity: Finding['severity'];
|
|
295
|
+
let confidence: 'high' | 'medium' | 'low';
|
|
296
|
+
if (site.kind === 'computed-property-write') {
|
|
297
|
+
if (site.guarded) {
|
|
298
|
+
severity = 'low';
|
|
299
|
+
confidence = 'low';
|
|
300
|
+
} else {
|
|
301
|
+
severity = 'high';
|
|
302
|
+
confidence = 'medium';
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
severity = 'medium';
|
|
306
|
+
confidence = 'medium';
|
|
307
|
+
}
|
|
308
|
+
findings.push(
|
|
309
|
+
toSecurityFinding(
|
|
310
|
+
{
|
|
311
|
+
severity,
|
|
312
|
+
category: 'prototype-pollution-risk',
|
|
313
|
+
file: entry.file,
|
|
314
|
+
lineStart: site.lineStart,
|
|
315
|
+
lineEnd: site.lineEnd,
|
|
316
|
+
title: `Prototype pollution risk: ${site.kind}${site.guarded ? ' (guarded)' : ''}`,
|
|
317
|
+
reason: `${site.detail}${site.guarded ? ' — guards detected (internal iteration or key check), likely false positive. Verify the key variable does not trace to external input.' : ''}`,
|
|
318
|
+
files: [entry.file],
|
|
319
|
+
suggestedFix: {
|
|
320
|
+
strategy:
|
|
321
|
+
'Guard against __proto__, constructor, and prototype keys before merging.',
|
|
322
|
+
steps: [
|
|
323
|
+
'Validate keys: reject "__proto__", "constructor", "prototype" before assignment.',
|
|
324
|
+
'Use Object.create(null) as the target for merges when possible.',
|
|
325
|
+
'Replace custom deep-merge with a hardened library (e.g. lodash.merge with prototype guard).',
|
|
326
|
+
'For Object.assign, ensure the source is sanitized or use structuredClone().',
|
|
327
|
+
],
|
|
328
|
+
},
|
|
329
|
+
impact:
|
|
330
|
+
'Prototype pollution can override built-in methods, bypass security checks, or achieve remote code execution.',
|
|
331
|
+
tags: ['security', 'prototype-pollution', 'injection'],
|
|
332
|
+
lspHints: [
|
|
333
|
+
{
|
|
334
|
+
tool: 'lspCallHierarchy',
|
|
335
|
+
symbolName:
|
|
336
|
+
site.kind === 'computed-property-write'
|
|
337
|
+
? 'bracket-assignment'
|
|
338
|
+
: site.detail.split('(')[0],
|
|
339
|
+
lineHint: site.lineStart,
|
|
340
|
+
file: entry.file,
|
|
341
|
+
expectedResult: `trace callers to determine if user-controlled data reaches this site — if key comes from Object.keys() on internal object, dismiss as false positive`,
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
'security.prototype-pollution-risk',
|
|
346
|
+
confidence,
|
|
347
|
+
{
|
|
348
|
+
source: site.kind,
|
|
349
|
+
sink: site.detail,
|
|
350
|
+
guarded: site.guarded,
|
|
351
|
+
sanitizerStatus: site.guarded ? 'present' : 'missing',
|
|
352
|
+
propagationSteps: [`${entry.file}:${site.lineStart}`],
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return findings;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export function detectUnvalidatedInputSink(
|
|
362
|
+
fileSummaries: FileEntry[]
|
|
363
|
+
): FindingDraft[] {
|
|
364
|
+
const findings: FindingDraft[] = [];
|
|
365
|
+
for (const entry of fileSummaries) {
|
|
366
|
+
if (isTestFile(entry.file)) continue;
|
|
367
|
+
for (const src of entry.inputSources || []) {
|
|
368
|
+
if (!src.hasSinkInBody || src.hasValidation) continue;
|
|
369
|
+
const sinkLabel = src.sinkKinds.join(', ');
|
|
370
|
+
const severity = src.paramConfidence === 'low' ? 'medium' : 'high';
|
|
371
|
+
findings.push(
|
|
372
|
+
toSecurityFinding(
|
|
373
|
+
{
|
|
374
|
+
severity,
|
|
375
|
+
category: 'unvalidated-input-sink',
|
|
376
|
+
file: entry.file,
|
|
377
|
+
lineStart: src.lineStart,
|
|
378
|
+
lineEnd: src.lineEnd,
|
|
379
|
+
title: `Unvalidated input reaches ${sinkLabel} sink in ${src.functionName}(${src.sourceParams.join(', ')})`,
|
|
380
|
+
reason: `Parameter${src.sourceParams.length > 1 ? 's' : ''} '${src.sourceParams.join("', '")}' (external input) flow${src.sourceParams.length === 1 ? 's' : ''} into ${sinkLabel} without validation (no type guard, schema call, or conditional check).`,
|
|
381
|
+
files: [entry.file],
|
|
382
|
+
suggestedFix: {
|
|
383
|
+
strategy: 'Add input validation before the sink operation.',
|
|
384
|
+
steps: [
|
|
385
|
+
'Add schema validation (e.g. zod, joi) for input parameters.',
|
|
386
|
+
'Use parameterized APIs instead of template interpolation for SQL/exec.',
|
|
387
|
+
`Trace data flow: lspCallHierarchy(outgoing) on ${src.functionName}.`,
|
|
388
|
+
],
|
|
389
|
+
},
|
|
390
|
+
impact:
|
|
391
|
+
'Unvalidated external input reaching a dangerous sink (eval, SQL, exec, innerHTML, file write) enables injection attacks.',
|
|
392
|
+
tags: ['security', 'input-validation', 'injection'],
|
|
393
|
+
lspHints: [
|
|
394
|
+
{
|
|
395
|
+
tool: 'lspCallHierarchy',
|
|
396
|
+
symbolName: src.functionName,
|
|
397
|
+
lineHint: src.lineStart,
|
|
398
|
+
file: entry.file,
|
|
399
|
+
expectedResult: `trace outgoing calls to see where ${src.sourceParams.join(', ')} data flows`,
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
tool: 'lspFindReferences',
|
|
403
|
+
symbolName: src.sourceParams[0],
|
|
404
|
+
lineHint: src.lineStart,
|
|
405
|
+
file: entry.file,
|
|
406
|
+
expectedResult: `check all usages of ${src.sourceParams[0]} parameter within function`,
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
'security.unvalidated-input-sink',
|
|
411
|
+
severity === 'high' ? 'high' : 'medium',
|
|
412
|
+
{
|
|
413
|
+
sourceParameters: src.sourceParams,
|
|
414
|
+
sink: sinkLabel,
|
|
415
|
+
sanitizerStatus: src.hasValidation ? 'present' : 'missing',
|
|
416
|
+
propagationSteps: src.callsWithInputArgs.map(
|
|
417
|
+
call => `${call.callee}:${call.lineStart}`
|
|
418
|
+
),
|
|
419
|
+
}
|
|
420
|
+
)
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return findings;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function detectInputPassthroughRisk(
|
|
428
|
+
fileSummaries: FileEntry[]
|
|
429
|
+
): FindingDraft[] {
|
|
430
|
+
const findings: FindingDraft[] = [];
|
|
431
|
+
for (const entry of fileSummaries) {
|
|
432
|
+
if (isTestFile(entry.file)) continue;
|
|
433
|
+
for (const src of entry.inputSources || []) {
|
|
434
|
+
if (src.callsWithInputArgs.length === 0 || src.hasValidation) continue;
|
|
435
|
+
if (src.hasSinkInBody) continue;
|
|
436
|
+
if (src.paramConfidence === 'low') continue;
|
|
437
|
+
const callees = src.callsWithInputArgs.map(c => c.callee);
|
|
438
|
+
const uniqueCallees = [...new Set(callees)];
|
|
439
|
+
const severity = src.paramConfidence === 'high' ? 'medium' : 'low';
|
|
440
|
+
findings.push(
|
|
441
|
+
toSecurityFinding(
|
|
442
|
+
{
|
|
443
|
+
severity,
|
|
444
|
+
category: 'input-passthrough-risk',
|
|
445
|
+
file: entry.file,
|
|
446
|
+
lineStart: src.lineStart,
|
|
447
|
+
lineEnd: src.lineEnd,
|
|
448
|
+
title: `Input passthrough without validation in ${src.functionName}(${src.sourceParams.join(', ')})`,
|
|
449
|
+
reason: `Parameter${src.sourceParams.length > 1 ? 's' : ''} '${src.sourceParams.join("', '")}' (external input) ${src.sourceParams.length === 1 ? 'is' : 'are'} passed to ${uniqueCallees.join(', ')} without validation. Downstream callees may not validate either.`,
|
|
450
|
+
files: [entry.file],
|
|
451
|
+
suggestedFix: {
|
|
452
|
+
strategy:
|
|
453
|
+
'Validate input before passing to downstream functions.',
|
|
454
|
+
steps: [
|
|
455
|
+
'Add schema validation (e.g. zod, joi) at the entry point.',
|
|
456
|
+
`Trace downstream: lspCallHierarchy(outgoing) on ${src.functionName} to verify callees validate.`,
|
|
457
|
+
'Search for validation middleware: localSearchCode for guard/validate/sanitize patterns.',
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
impact:
|
|
461
|
+
'Unchecked input passed downstream can reach sinks in callees — validation gaps compound across the call chain.',
|
|
462
|
+
tags: ['security', 'input-validation', 'passthrough'],
|
|
463
|
+
lspHints: [
|
|
464
|
+
{
|
|
465
|
+
tool: 'lspCallHierarchy',
|
|
466
|
+
symbolName: src.functionName,
|
|
467
|
+
lineHint: src.lineStart,
|
|
468
|
+
file: entry.file,
|
|
469
|
+
expectedResult: `trace outgoing calls to verify downstream validation of ${src.sourceParams.join(', ')}`,
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
tool: 'lspFindReferences',
|
|
473
|
+
symbolName: src.sourceParams[0],
|
|
474
|
+
lineHint: src.lineStart,
|
|
475
|
+
file: entry.file,
|
|
476
|
+
expectedResult: `find all usages of ${src.sourceParams[0]} to check if validation occurs upstream`,
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
},
|
|
480
|
+
'security.input-passthrough-risk',
|
|
481
|
+
severity,
|
|
482
|
+
{
|
|
483
|
+
sourceParameters: src.sourceParams,
|
|
484
|
+
sink: uniqueCallees.join(', '),
|
|
485
|
+
sanitizerStatus: src.hasValidation ? 'present' : 'missing',
|
|
486
|
+
propagationSteps: src.callsWithInputArgs.map(
|
|
487
|
+
call => `${call.callee}:${call.lineStart}`
|
|
488
|
+
),
|
|
489
|
+
}
|
|
490
|
+
)
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return findings;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export function detectPathTraversalRisk(
|
|
498
|
+
fileSummaries: FileEntry[]
|
|
499
|
+
): FindingDraft[] {
|
|
500
|
+
const findings: FindingDraft[] = [];
|
|
501
|
+
for (const entry of fileSummaries) {
|
|
502
|
+
if (isTestFile(entry.file)) continue;
|
|
503
|
+
for (const src of entry.inputSources || []) {
|
|
504
|
+
const fsReadSinks = src.sinkKinds.filter(
|
|
505
|
+
k => k === 'fs-read' || k === 'path-resolve'
|
|
506
|
+
);
|
|
507
|
+
if (fsReadSinks.length === 0) continue;
|
|
508
|
+
if (src.paramConfidence === 'low') continue;
|
|
509
|
+
|
|
510
|
+
const hasValidation = src.hasValidation;
|
|
511
|
+
const severity: Finding['severity'] = hasValidation ? 'medium' : 'high';
|
|
512
|
+
const sinkLabel = fsReadSinks.join(', ');
|
|
513
|
+
|
|
514
|
+
findings.push(
|
|
515
|
+
toSecurityFinding(
|
|
516
|
+
{
|
|
517
|
+
severity,
|
|
518
|
+
category: 'path-traversal-risk',
|
|
519
|
+
file: entry.file,
|
|
520
|
+
lineStart: src.lineStart,
|
|
521
|
+
lineEnd: src.lineEnd,
|
|
522
|
+
title: `Path traversal risk: ${src.functionName}(${src.sourceParams.join(', ')}) → ${sinkLabel}`,
|
|
523
|
+
reason: `Parameter${src.sourceParams.length > 1 ? 's' : ''} '${src.sourceParams.join("', '")}' (external input) flow${src.sourceParams.length === 1 ? 's' : ''} into ${sinkLabel} ${hasValidation ? 'with partial validation — verify path normalization + prefix check + realpath resolution' : 'without validation. Path traversal (e.g. ../../etc/passwd) can read or write arbitrary files'}.`,
|
|
524
|
+
files: [entry.file],
|
|
525
|
+
suggestedFix: {
|
|
526
|
+
strategy:
|
|
527
|
+
'Add multi-layer path validation before file system operations.',
|
|
528
|
+
steps: [
|
|
529
|
+
'Normalize the path: path.resolve(basePath, userInput).',
|
|
530
|
+
'Prefix check: resolvedPath.startsWith(basePath + path.sep).',
|
|
531
|
+
'Resolve symlinks: fs.realpathSync() to prevent symlink escape.',
|
|
532
|
+
'Re-validate after symlink resolution.',
|
|
533
|
+
],
|
|
534
|
+
},
|
|
535
|
+
impact:
|
|
536
|
+
'Path traversal enables reading sensitive files (credentials, configs, source code) or writing to arbitrary locations (code injection via file overwrite).',
|
|
537
|
+
tags: ['security', 'path-traversal', 'agentic'],
|
|
538
|
+
lspHints: [
|
|
539
|
+
{
|
|
540
|
+
tool: 'lspCallHierarchy',
|
|
541
|
+
symbolName: src.functionName,
|
|
542
|
+
lineHint: src.lineStart,
|
|
543
|
+
file: entry.file,
|
|
544
|
+
expectedResult: `trace incoming callers to determine if path parameter comes from user input — then trace outgoing to the fs/path call`,
|
|
545
|
+
},
|
|
546
|
+
],
|
|
547
|
+
},
|
|
548
|
+
'security.path-traversal-risk',
|
|
549
|
+
src.paramConfidence === 'high' ? 'high' : 'medium',
|
|
550
|
+
{
|
|
551
|
+
sourceParameters: src.sourceParams,
|
|
552
|
+
sink: sinkLabel,
|
|
553
|
+
sanitizerStatus: hasValidation ? 'partial' : 'missing',
|
|
554
|
+
propagationSteps: src.callsWithInputArgs.map(
|
|
555
|
+
call => `${call.callee}:${call.lineStart}`
|
|
556
|
+
),
|
|
557
|
+
}
|
|
558
|
+
)
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return findings;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function detectCommandInjectionRisk(
|
|
566
|
+
fileSummaries: FileEntry[]
|
|
567
|
+
): FindingDraft[] {
|
|
568
|
+
const findings: FindingDraft[] = [];
|
|
569
|
+
for (const entry of fileSummaries) {
|
|
570
|
+
if (isTestFile(entry.file)) continue;
|
|
571
|
+
for (const src of entry.inputSources || []) {
|
|
572
|
+
const execSinks = src.sinkKinds.filter(k => k === 'exec');
|
|
573
|
+
if (execSinks.length === 0) continue;
|
|
574
|
+
if (src.paramConfidence === 'low') continue;
|
|
575
|
+
|
|
576
|
+
const execCallees = src.callsWithInputArgs.filter(c =>
|
|
577
|
+
/\.exec\b|^exec$|^execSync$|child_process\.exec/.test(c.callee)
|
|
578
|
+
);
|
|
579
|
+
const spawnCallees = src.callsWithInputArgs.filter(c =>
|
|
580
|
+
/\.spawn\b|^spawn$|^spawnSync$|child_process\.spawn/.test(c.callee)
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
if (execCallees.length > 0) {
|
|
584
|
+
const severity: Finding['severity'] =
|
|
585
|
+
src.paramConfidence === 'high' ? 'critical' : 'high';
|
|
586
|
+
findings.push(
|
|
587
|
+
toSecurityFinding(
|
|
588
|
+
{
|
|
589
|
+
severity,
|
|
590
|
+
category: 'command-injection-risk',
|
|
591
|
+
file: entry.file,
|
|
592
|
+
lineStart: src.lineStart,
|
|
593
|
+
lineEnd: src.lineEnd,
|
|
594
|
+
title: `Command injection risk: ${src.functionName}(${src.sourceParams.join(', ')}) → exec`,
|
|
595
|
+
reason: `Parameter${src.sourceParams.length > 1 ? 's' : ''} '${src.sourceParams.join("', '")}' (external input) flow${src.sourceParams.length === 1 ? 's' : ''} into exec/execSync. exec() runs commands through a shell — string interpolation enables command injection.`,
|
|
596
|
+
files: [entry.file],
|
|
597
|
+
suggestedFix: {
|
|
598
|
+
strategy:
|
|
599
|
+
'Replace exec with spawn using array arguments (no shell interpretation).',
|
|
600
|
+
steps: [
|
|
601
|
+
'Replace child_process.exec(cmd) with child_process.spawn(binary, [args]).',
|
|
602
|
+
'Never interpolate user input into command strings.',
|
|
603
|
+
'Use an allowlist for permitted commands if dynamic dispatch is needed.',
|
|
604
|
+
'If shell features are required, validate input against a strict allowlist.',
|
|
605
|
+
],
|
|
606
|
+
},
|
|
607
|
+
impact:
|
|
608
|
+
'Command injection enables arbitrary OS command execution — full server compromise, data exfiltration, or lateral movement.',
|
|
609
|
+
tags: ['security', 'command-injection', 'critical', 'agentic'],
|
|
610
|
+
lspHints: [
|
|
611
|
+
{
|
|
612
|
+
tool: 'lspCallHierarchy',
|
|
613
|
+
symbolName: src.functionName,
|
|
614
|
+
lineHint: src.lineStart,
|
|
615
|
+
file: entry.file,
|
|
616
|
+
expectedResult: `trace incoming callers to verify if user input reaches the exec call — check for allowlist or sanitization`,
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
},
|
|
620
|
+
'security.command-injection-risk',
|
|
621
|
+
src.paramConfidence === 'high' ? 'high' : 'medium',
|
|
622
|
+
{
|
|
623
|
+
sourceParameters: src.sourceParams,
|
|
624
|
+
sink: 'exec',
|
|
625
|
+
sanitizerStatus: src.hasValidation ? 'partial' : 'missing',
|
|
626
|
+
propagationSteps: execCallees.map(
|
|
627
|
+
call => `${call.callee}:${call.lineStart}`
|
|
628
|
+
),
|
|
629
|
+
}
|
|
630
|
+
)
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (spawnCallees.length > 0 && execCallees.length === 0) {
|
|
635
|
+
findings.push(
|
|
636
|
+
toSecurityFinding(
|
|
637
|
+
{
|
|
638
|
+
severity: 'high',
|
|
639
|
+
category: 'command-injection-risk',
|
|
640
|
+
file: entry.file,
|
|
641
|
+
lineStart: src.lineStart,
|
|
642
|
+
lineEnd: src.lineEnd,
|
|
643
|
+
title: `Potential command injection: ${src.functionName}(${src.sourceParams.join(', ')}) → spawn`,
|
|
644
|
+
reason: `Parameter${src.sourceParams.length > 1 ? 's' : ''} '${src.sourceParams.join("', '")}' (external input) flow${src.sourceParams.length === 1 ? 's' : ''} into spawn. If shell:true is set, this is equivalent to exec. Verify spawn uses array args without shell option.`,
|
|
645
|
+
files: [entry.file],
|
|
646
|
+
suggestedFix: {
|
|
647
|
+
strategy:
|
|
648
|
+
'Ensure spawn uses array arguments without shell: true.',
|
|
649
|
+
steps: [
|
|
650
|
+
'Verify spawn is called as spawn(binary, [arg1, arg2]) — NOT spawn(cmd, { shell: true }).',
|
|
651
|
+
'Remove shell: true if present.',
|
|
652
|
+
'Validate command arguments against an allowlist.',
|
|
653
|
+
],
|
|
654
|
+
},
|
|
655
|
+
impact:
|
|
656
|
+
'spawn with shell:true enables the same command injection as exec. Without shell:true, spawn with array args is safe from injection.',
|
|
657
|
+
tags: ['security', 'command-injection', 'agentic'],
|
|
658
|
+
lspHints: [
|
|
659
|
+
{
|
|
660
|
+
tool: 'lspCallHierarchy',
|
|
661
|
+
symbolName: src.functionName,
|
|
662
|
+
lineHint: src.lineStart,
|
|
663
|
+
file: entry.file,
|
|
664
|
+
expectedResult: `trace incoming callers — check if spawn uses shell:true option`,
|
|
665
|
+
},
|
|
666
|
+
],
|
|
667
|
+
},
|
|
668
|
+
'security.command-injection-risk',
|
|
669
|
+
'medium',
|
|
670
|
+
{
|
|
671
|
+
sourceParameters: src.sourceParams,
|
|
672
|
+
sink: 'spawn',
|
|
673
|
+
sanitizerStatus: src.hasValidation ? 'partial' : 'missing',
|
|
674
|
+
propagationSteps: spawnCallees.map(
|
|
675
|
+
call => `${call.callee}:${call.lineStart}`
|
|
676
|
+
),
|
|
677
|
+
}
|
|
678
|
+
)
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return findings;
|
|
684
|
+
}
|
|
685
|
+
export function detectDebugLogLeakage(
|
|
686
|
+
fileSummaries: FileEntry[]
|
|
687
|
+
): FindingDraft[] {
|
|
688
|
+
const findings: FindingDraft[] = [];
|
|
689
|
+
for (const entry of fileSummaries) {
|
|
690
|
+
if (isTestFile(entry.file)) continue;
|
|
691
|
+
for (const log of entry.consoleLogs || []) {
|
|
692
|
+
if (log.method === 'debugger') {
|
|
693
|
+
findings.push(
|
|
694
|
+
toSecurityFinding(
|
|
695
|
+
{
|
|
696
|
+
severity: 'high',
|
|
697
|
+
category: 'debug-log-leakage',
|
|
698
|
+
file: entry.file,
|
|
699
|
+
lineStart: log.lineStart,
|
|
700
|
+
lineEnd: log.lineEnd,
|
|
701
|
+
title: 'Debugger statement in production code',
|
|
702
|
+
reason:
|
|
703
|
+
'A `debugger` statement pauses execution when DevTools are open. In production it can expose internal state and halt the application.',
|
|
704
|
+
files: [entry.file],
|
|
705
|
+
suggestedFix: {
|
|
706
|
+
strategy: 'Remove the debugger statement before shipping.',
|
|
707
|
+
steps: [
|
|
708
|
+
'Delete the `debugger;` line.',
|
|
709
|
+
'Use structured logging (pino, winston) or feature-flagged debug helpers instead.',
|
|
710
|
+
],
|
|
711
|
+
},
|
|
712
|
+
impact:
|
|
713
|
+
'Debugger statements in production can halt request processing and expose internal runtime state to anyone with browser DevTools open.',
|
|
714
|
+
tags: ['security', 'debug', 'production-safety'],
|
|
715
|
+
},
|
|
716
|
+
'security.debug-log-leakage',
|
|
717
|
+
'high',
|
|
718
|
+
{ method: 'debugger', line: log.lineStart }
|
|
719
|
+
)
|
|
720
|
+
);
|
|
721
|
+
} else if (log.method === 'debug' || log.method === 'trace') {
|
|
722
|
+
findings.push(
|
|
723
|
+
toSecurityFinding(
|
|
724
|
+
{
|
|
725
|
+
severity: 'medium',
|
|
726
|
+
category: 'debug-log-leakage',
|
|
727
|
+
file: entry.file,
|
|
728
|
+
lineStart: log.lineStart,
|
|
729
|
+
lineEnd: log.lineEnd,
|
|
730
|
+
title: `console.${log.method}() in production code`,
|
|
731
|
+
reason: `console.${log.method}() is a development-only call. Left in production it leaks internal state, variable values, and execution paths — all useful to attackers.`,
|
|
732
|
+
files: [entry.file],
|
|
733
|
+
suggestedFix: {
|
|
734
|
+
strategy:
|
|
735
|
+
'Replace with a structured logger that respects log-level configuration.',
|
|
736
|
+
steps: [
|
|
737
|
+
`Remove or gate the console.${log.method}() call behind a LOG_LEVEL check.`,
|
|
738
|
+
'Use a structured logger (pino, winston) with level filtering instead.',
|
|
739
|
+
'Ensure debug/trace levels are disabled in production config.',
|
|
740
|
+
],
|
|
741
|
+
},
|
|
742
|
+
impact:
|
|
743
|
+
'Debug/trace logs expose internal object state and execution flow, making reconnaissance easier for attackers and violating minimal disclosure.',
|
|
744
|
+
tags: ['security', 'debug', 'information-disclosure'],
|
|
745
|
+
lspHints: [
|
|
746
|
+
{
|
|
747
|
+
tool: 'lspFindReferences',
|
|
748
|
+
symbolName: `console.${log.method}`,
|
|
749
|
+
lineHint: log.lineStart,
|
|
750
|
+
file: entry.file,
|
|
751
|
+
expectedResult: 'find all debug/trace log calls in this file to assess total leakage surface',
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
},
|
|
755
|
+
'security.debug-log-leakage',
|
|
756
|
+
'medium',
|
|
757
|
+
{ method: log.method, snippet: log.argSnippet, line: log.lineStart }
|
|
758
|
+
)
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return findings;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export function detectSensitiveDataLogging(
|
|
767
|
+
fileSummaries: FileEntry[]
|
|
768
|
+
): FindingDraft[] {
|
|
769
|
+
const findings: FindingDraft[] = [];
|
|
770
|
+
for (const entry of fileSummaries) {
|
|
771
|
+
if (isTestFile(entry.file)) continue;
|
|
772
|
+
for (const log of entry.consoleLogs || []) {
|
|
773
|
+
if (log.method === 'debugger' || !log.hasSensitiveArg) continue;
|
|
774
|
+
findings.push(
|
|
775
|
+
toSecurityFinding(
|
|
776
|
+
{
|
|
777
|
+
severity: 'high',
|
|
778
|
+
category: 'sensitive-data-logging',
|
|
779
|
+
file: entry.file,
|
|
780
|
+
lineStart: log.lineStart,
|
|
781
|
+
lineEnd: log.lineEnd,
|
|
782
|
+
title: `Sensitive data logged via console.${log.method}()${log.argSnippet ? `: ${log.argSnippet.slice(0, 40)}` : ''}`,
|
|
783
|
+
reason: `console.${log.method}() argument matches a sensitive-data pattern (password, token, secret, credential, API key, session, SSN). Logging secrets writes them to stdout/stderr, log aggregators, error monitoring services, and persistent log files.`,
|
|
784
|
+
files: [entry.file],
|
|
785
|
+
suggestedFix: {
|
|
786
|
+
strategy:
|
|
787
|
+
'Remove or redact sensitive values before logging.',
|
|
788
|
+
steps: [
|
|
789
|
+
'Never log raw passwords, tokens, API keys, or session identifiers.',
|
|
790
|
+
'If logging for debugging, redact: log({ ...user, password: "[REDACTED]" }).',
|
|
791
|
+
'Use a structured logger with field-level redaction hooks (e.g. pino redact option).',
|
|
792
|
+
'Audit all log aggregation pipelines (Datadog, Splunk, CloudWatch) for secret exposure.',
|
|
793
|
+
],
|
|
794
|
+
},
|
|
795
|
+
impact:
|
|
796
|
+
'Sensitive data in logs is written to stdout/stderr, forwarded to log aggregators (Splunk, Datadog, CloudWatch), and often stored long-term — creating a persistent credential leak accessible to anyone with log access.',
|
|
797
|
+
tags: ['security', 'sensitive-data', 'credential-leak', 'compliance'],
|
|
798
|
+
lspHints: [
|
|
799
|
+
{
|
|
800
|
+
tool: 'lspCallHierarchy',
|
|
801
|
+
symbolName: log.method,
|
|
802
|
+
lineHint: log.lineStart,
|
|
803
|
+
file: entry.file,
|
|
804
|
+
expectedResult: `trace incoming callers to understand where sensitive data originates before reaching console.${log.method}`,
|
|
805
|
+
},
|
|
806
|
+
],
|
|
807
|
+
},
|
|
808
|
+
'security.sensitive-data-logging',
|
|
809
|
+
'high',
|
|
810
|
+
{
|
|
811
|
+
method: log.method,
|
|
812
|
+
snippet: log.argSnippet,
|
|
813
|
+
line: log.lineStart,
|
|
814
|
+
sanitizerStatus: 'missing',
|
|
815
|
+
}
|
|
816
|
+
)
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return findings;
|
|
821
|
+
}
|