octocode-cli 1.2.6 → 1.2.8
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 +7063 -6934
- 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,332 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import { isFunctionLike } from '../ast/helpers.js';
|
|
4
|
+
import { getLineAndCharacter } from '../common/utils.js';
|
|
5
|
+
|
|
6
|
+
import type { TopLevelEffect } from '../types/index.js';
|
|
7
|
+
|
|
8
|
+
const SYNC_IO_TOP_LEVEL = new Set([
|
|
9
|
+
'readFileSync',
|
|
10
|
+
'writeFileSync',
|
|
11
|
+
'existsSync',
|
|
12
|
+
'mkdirSync',
|
|
13
|
+
'readdirSync',
|
|
14
|
+
'statSync',
|
|
15
|
+
'lstatSync',
|
|
16
|
+
'unlinkSync',
|
|
17
|
+
'rmdirSync',
|
|
18
|
+
'renameSync',
|
|
19
|
+
'copyFileSync',
|
|
20
|
+
'accessSync',
|
|
21
|
+
'appendFileSync',
|
|
22
|
+
'chmodSync',
|
|
23
|
+
'chownSync',
|
|
24
|
+
'openSync',
|
|
25
|
+
'closeSync',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
const EXEC_SYNC_TOP_LEVEL = new Set(['execSync', 'execFileSync', 'spawnSync']);
|
|
29
|
+
|
|
30
|
+
export function collectTopLevelEffects(
|
|
31
|
+
sourceFile: ts.SourceFile,
|
|
32
|
+
_fileRelative: string
|
|
33
|
+
): TopLevelEffect[] {
|
|
34
|
+
const effects: TopLevelEffect[] = [];
|
|
35
|
+
|
|
36
|
+
for (const stmt of sourceFile.statements) {
|
|
37
|
+
if (ts.isImportDeclaration(stmt)) {
|
|
38
|
+
if (!stmt.importClause) {
|
|
39
|
+
const spec = stmt.moduleSpecifier;
|
|
40
|
+
const moduleName = ts.isStringLiteral(spec) ? spec.text : '<unknown>';
|
|
41
|
+
const loc = getLineAndCharacter(sourceFile, stmt);
|
|
42
|
+
effects.push({
|
|
43
|
+
kind: 'side-effect-import',
|
|
44
|
+
lineStart: loc.lineStart,
|
|
45
|
+
lineEnd: loc.lineEnd,
|
|
46
|
+
detail: `import '${moduleName}'`,
|
|
47
|
+
weight: 3,
|
|
48
|
+
confidence: 'medium',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (ts.isExportDeclaration(stmt) || ts.isExportAssignment(stmt)) continue;
|
|
55
|
+
if (
|
|
56
|
+
ts.isTypeAliasDeclaration(stmt) ||
|
|
57
|
+
ts.isInterfaceDeclaration(stmt) ||
|
|
58
|
+
ts.isEnumDeclaration(stmt)
|
|
59
|
+
)
|
|
60
|
+
continue;
|
|
61
|
+
if (ts.isModuleDeclaration(stmt)) continue;
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
isFunctionLike(stmt) ||
|
|
65
|
+
ts.isFunctionDeclaration(stmt) ||
|
|
66
|
+
ts.isClassDeclaration(stmt)
|
|
67
|
+
)
|
|
68
|
+
continue;
|
|
69
|
+
|
|
70
|
+
if (ts.isVariableStatement(stmt)) {
|
|
71
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
72
|
+
if (decl.initializer) {
|
|
73
|
+
scanExpressionForEffects(decl.initializer, sourceFile, effects);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (ts.isExpressionStatement(stmt)) {
|
|
80
|
+
scanExpressionForEffects(stmt.expression, sourceFile, effects);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
ts.isIfStatement(stmt) ||
|
|
86
|
+
ts.isForStatement(stmt) ||
|
|
87
|
+
ts.isWhileStatement(stmt) ||
|
|
88
|
+
ts.isDoStatement(stmt) ||
|
|
89
|
+
ts.isForOfStatement(stmt) ||
|
|
90
|
+
ts.isForInStatement(stmt) ||
|
|
91
|
+
ts.isSwitchStatement(stmt) ||
|
|
92
|
+
ts.isTryStatement(stmt)
|
|
93
|
+
) {
|
|
94
|
+
scanNodeForEffects(stmt, sourceFile, effects);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return effects;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function scanExpressionForEffects(
|
|
102
|
+
expr: ts.Expression,
|
|
103
|
+
sourceFile: ts.SourceFile,
|
|
104
|
+
effects: TopLevelEffect[]
|
|
105
|
+
): void {
|
|
106
|
+
if (ts.isAwaitExpression(expr)) {
|
|
107
|
+
const loc = getLineAndCharacter(sourceFile, expr);
|
|
108
|
+
effects.push({
|
|
109
|
+
kind: 'top-level-await',
|
|
110
|
+
lineStart: loc.lineStart,
|
|
111
|
+
lineEnd: loc.lineEnd,
|
|
112
|
+
detail: 'top-level await',
|
|
113
|
+
weight: 4,
|
|
114
|
+
confidence: 'high',
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (ts.isCallExpression(expr)) {
|
|
120
|
+
classifyCall(expr, sourceFile, effects);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
ts.isNewExpression(expr) &&
|
|
126
|
+
expr.expression.getText(sourceFile) === 'Function'
|
|
127
|
+
) {
|
|
128
|
+
const loc = getLineAndCharacter(sourceFile, expr);
|
|
129
|
+
effects.push({
|
|
130
|
+
kind: 'eval',
|
|
131
|
+
lineStart: loc.lineStart,
|
|
132
|
+
lineEnd: loc.lineEnd,
|
|
133
|
+
detail: 'new Function()',
|
|
134
|
+
weight: 8,
|
|
135
|
+
confidence: 'high',
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
ts.isBinaryExpression(expr) &&
|
|
142
|
+
expr.operatorToken.kind === ts.SyntaxKind.EqualsToken
|
|
143
|
+
) {
|
|
144
|
+
if (ts.isCallExpression(expr.right)) {
|
|
145
|
+
classifyCall(expr.right, sourceFile, effects);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function classifyCall(
|
|
151
|
+
call: ts.CallExpression,
|
|
152
|
+
sourceFile: ts.SourceFile,
|
|
153
|
+
effects: TopLevelEffect[]
|
|
154
|
+
): void {
|
|
155
|
+
const text = call.expression.getText(sourceFile);
|
|
156
|
+
const loc = getLineAndCharacter(sourceFile, call);
|
|
157
|
+
|
|
158
|
+
if (text === 'eval' || text === 'Function') {
|
|
159
|
+
effects.push({
|
|
160
|
+
kind: 'eval',
|
|
161
|
+
lineStart: loc.lineStart,
|
|
162
|
+
lineEnd: loc.lineEnd,
|
|
163
|
+
detail: `${text}()`,
|
|
164
|
+
weight: 8,
|
|
165
|
+
confidence: 'high',
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (text === 'setInterval' || text === 'setTimeout') {
|
|
171
|
+
effects.push({
|
|
172
|
+
kind: 'timer',
|
|
173
|
+
lineStart: loc.lineStart,
|
|
174
|
+
lineEnd: loc.lineEnd,
|
|
175
|
+
detail: `${text}()`,
|
|
176
|
+
weight: 4,
|
|
177
|
+
confidence: 'high',
|
|
178
|
+
});
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (ts.isPropertyAccessExpression(call.expression)) {
|
|
183
|
+
const method = call.expression.name.getText(sourceFile);
|
|
184
|
+
const obj = call.expression.expression.getText(sourceFile);
|
|
185
|
+
|
|
186
|
+
if (EXEC_SYNC_TOP_LEVEL.has(method) || EXEC_SYNC_TOP_LEVEL.has(text)) {
|
|
187
|
+
effects.push({
|
|
188
|
+
kind: 'exec-sync',
|
|
189
|
+
lineStart: loc.lineStart,
|
|
190
|
+
lineEnd: loc.lineEnd,
|
|
191
|
+
detail: text,
|
|
192
|
+
weight: 8,
|
|
193
|
+
confidence: 'high',
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (SYNC_IO_TOP_LEVEL.has(method)) {
|
|
199
|
+
effects.push({
|
|
200
|
+
kind: 'sync-io',
|
|
201
|
+
lineStart: loc.lineStart,
|
|
202
|
+
lineEnd: loc.lineEnd,
|
|
203
|
+
detail: text,
|
|
204
|
+
weight: 5,
|
|
205
|
+
confidence: 'high',
|
|
206
|
+
});
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
obj === 'process' &&
|
|
212
|
+
(method === 'on' || method === 'once' || method === 'addListener')
|
|
213
|
+
) {
|
|
214
|
+
effects.push({
|
|
215
|
+
kind: 'process-handler',
|
|
216
|
+
lineStart: loc.lineStart,
|
|
217
|
+
lineEnd: loc.lineEnd,
|
|
218
|
+
detail: `${text}()`,
|
|
219
|
+
weight: 4,
|
|
220
|
+
confidence: 'high',
|
|
221
|
+
});
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (
|
|
226
|
+
method === 'addEventListener' ||
|
|
227
|
+
method === 'on' ||
|
|
228
|
+
method === 'addListener'
|
|
229
|
+
) {
|
|
230
|
+
effects.push({
|
|
231
|
+
kind: 'listener',
|
|
232
|
+
lineStart: loc.lineStart,
|
|
233
|
+
lineEnd: loc.lineEnd,
|
|
234
|
+
detail: `${text}()`,
|
|
235
|
+
weight: 4,
|
|
236
|
+
confidence: 'medium',
|
|
237
|
+
});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (ts.isCallExpression(call.expression) || text === 'import') {
|
|
243
|
+
if (
|
|
244
|
+
text.startsWith('import(') ||
|
|
245
|
+
(ts.isCallExpression(call) &&
|
|
246
|
+
call.expression.kind === ts.SyntaxKind.ImportKeyword)
|
|
247
|
+
) {
|
|
248
|
+
effects.push({
|
|
249
|
+
kind: 'dynamic-import',
|
|
250
|
+
lineStart: loc.lineStart,
|
|
251
|
+
lineEnd: loc.lineEnd,
|
|
252
|
+
detail: 'dynamic import()',
|
|
253
|
+
weight: 3,
|
|
254
|
+
confidence: 'medium',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function scanNodeForEffects(
|
|
261
|
+
node: ts.Node,
|
|
262
|
+
sourceFile: ts.SourceFile,
|
|
263
|
+
effects: TopLevelEffect[]
|
|
264
|
+
): void {
|
|
265
|
+
if (isFunctionLike(node) || ts.isClassDeclaration(node)) return;
|
|
266
|
+
if (ts.isCallExpression(node)) {
|
|
267
|
+
classifyCall(node, sourceFile, effects);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (ts.isAwaitExpression(node)) {
|
|
271
|
+
const loc = getLineAndCharacter(sourceFile, node);
|
|
272
|
+
effects.push({
|
|
273
|
+
kind: 'top-level-await',
|
|
274
|
+
lineStart: loc.lineStart,
|
|
275
|
+
lineEnd: loc.lineEnd,
|
|
276
|
+
detail: 'top-level await',
|
|
277
|
+
weight: 4,
|
|
278
|
+
confidence: 'high',
|
|
279
|
+
});
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (
|
|
283
|
+
ts.isNewExpression(node) &&
|
|
284
|
+
node.expression.getText(sourceFile) === 'Function'
|
|
285
|
+
) {
|
|
286
|
+
const loc = getLineAndCharacter(sourceFile, node);
|
|
287
|
+
effects.push({
|
|
288
|
+
kind: 'eval',
|
|
289
|
+
lineStart: loc.lineStart,
|
|
290
|
+
lineEnd: loc.lineEnd,
|
|
291
|
+
detail: 'new Function()',
|
|
292
|
+
weight: 8,
|
|
293
|
+
confidence: 'high',
|
|
294
|
+
});
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
ts.forEachChild(node, child =>
|
|
298
|
+
scanNodeForEffects(child, sourceFile, effects)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function findParentBlock(
|
|
303
|
+
node: ts.Node
|
|
304
|
+
): ts.Block | ts.SourceFile | null {
|
|
305
|
+
let current = node.parent;
|
|
306
|
+
while (current) {
|
|
307
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) return current;
|
|
308
|
+
current = current.parent;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function blockContainsCall(
|
|
314
|
+
block: ts.Node,
|
|
315
|
+
sourceFile: ts.SourceFile,
|
|
316
|
+
callName: string
|
|
317
|
+
): boolean {
|
|
318
|
+
let found = false;
|
|
319
|
+
const search = (n: ts.Node): void => {
|
|
320
|
+
if (found) return;
|
|
321
|
+
if (
|
|
322
|
+
ts.isCallExpression(n) &&
|
|
323
|
+
n.expression.getText(sourceFile) === callName
|
|
324
|
+
) {
|
|
325
|
+
found = true;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
ts.forEachChild(n, search);
|
|
329
|
+
};
|
|
330
|
+
ts.forEachChild(block, search);
|
|
331
|
+
return found;
|
|
332
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { collectInputSourceProfile } from './input-sources.js';
|
|
5
|
+
|
|
6
|
+
import type { FileEntry } from '../types/index.js';
|
|
7
|
+
|
|
8
|
+
function parse(code: string, fileName = '/repo/src/test.ts'): ts.SourceFile {
|
|
9
|
+
return ts.createSourceFile(fileName, code, ts.ScriptTarget.ESNext, true);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function emptyFileEntry(): FileEntry {
|
|
13
|
+
return {
|
|
14
|
+
package: 'test',
|
|
15
|
+
file: 'test.ts',
|
|
16
|
+
parseEngine: 'typescript',
|
|
17
|
+
nodeCount: 0,
|
|
18
|
+
kindCounts: {},
|
|
19
|
+
functions: [],
|
|
20
|
+
flows: [],
|
|
21
|
+
dependencyProfile: {
|
|
22
|
+
internalDependencies: [],
|
|
23
|
+
externalDependencies: [],
|
|
24
|
+
unresolvedDependencies: [],
|
|
25
|
+
declaredExports: [],
|
|
26
|
+
importedSymbols: [],
|
|
27
|
+
reExports: [],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('collectInputSourceProfile', () => {
|
|
33
|
+
it('function with req param → detects input source with high confidence', () => {
|
|
34
|
+
const code = `function handler(req: Request) { return req.url; }`;
|
|
35
|
+
const sourceFile = parse(code);
|
|
36
|
+
const fileEntry = emptyFileEntry();
|
|
37
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
38
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
39
|
+
expect(fileEntry.inputSources!.length).toBeGreaterThan(0);
|
|
40
|
+
const src = fileEntry.inputSources![0];
|
|
41
|
+
expect(src.sourceParams).toContain('req');
|
|
42
|
+
expect(src.paramConfidence).toBe('high');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('function with input param → detects with medium confidence', () => {
|
|
46
|
+
const code = `function process(input: string) { return input.trim(); }`;
|
|
47
|
+
const sourceFile = parse(code);
|
|
48
|
+
const fileEntry = emptyFileEntry();
|
|
49
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
50
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
51
|
+
expect(fileEntry.inputSources!.length).toBeGreaterThan(0);
|
|
52
|
+
const src = fileEntry.inputSources![0];
|
|
53
|
+
expect(src.sourceParams).toContain('input');
|
|
54
|
+
expect(src.paramConfidence).toBe('medium');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('function with count param → no input source detected', () => {
|
|
58
|
+
const code = `function increment(count: number) { return count + 1; }`;
|
|
59
|
+
const sourceFile = parse(code);
|
|
60
|
+
const fileEntry = emptyFileEntry();
|
|
61
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
62
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
63
|
+
expect(fileEntry.inputSources!.length).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('function with req and eval() sink → hasSinkInBody=true', () => {
|
|
67
|
+
const code = `function bad(req: Request) { eval(req.body); }`;
|
|
68
|
+
const sourceFile = parse(code);
|
|
69
|
+
const fileEntry = emptyFileEntry();
|
|
70
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
71
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
72
|
+
expect(fileEntry.inputSources!.length).toBeGreaterThan(0);
|
|
73
|
+
const src = fileEntry.inputSources![0];
|
|
74
|
+
expect(src.hasSinkInBody).toBe(true);
|
|
75
|
+
expect(src.sinkKinds).toContain('eval');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('function with validation (typeof check) → hasValidation=true', () => {
|
|
79
|
+
const code = `function safe(input: unknown) { if (typeof input === 'string') return input; }`;
|
|
80
|
+
const sourceFile = parse(code);
|
|
81
|
+
const fileEntry = emptyFileEntry();
|
|
82
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
83
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
84
|
+
expect(fileEntry.inputSources!.length).toBeGreaterThan(0);
|
|
85
|
+
const src = fileEntry.inputSources![0];
|
|
86
|
+
expect(src.hasValidation).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('no false positive on non-source parameters', () => {
|
|
90
|
+
const code = `function util(count: number, limit: number) { return count * limit; }`;
|
|
91
|
+
const sourceFile = parse(code);
|
|
92
|
+
const fileEntry = emptyFileEntry();
|
|
93
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
94
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
95
|
+
expect(fileEntry.inputSources!.length).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('detects instanceof validation for source param', () => {
|
|
99
|
+
const code = `
|
|
100
|
+
class UserInput {}
|
|
101
|
+
function parseReq(req: unknown) {
|
|
102
|
+
if (req instanceof UserInput) return req;
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
const sourceFile = parse(code);
|
|
107
|
+
const fileEntry = emptyFileEntry();
|
|
108
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
109
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
110
|
+
expect(fileEntry.inputSources!.length).toBeGreaterThan(0);
|
|
111
|
+
expect(fileEntry.inputSources![0].hasValidation).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('detects optional chaining usage as validation signal', () => {
|
|
115
|
+
const code = `
|
|
116
|
+
function read(req: { body?: { id?: string } }) {
|
|
117
|
+
return req?.body?.id ?? '';
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
const sourceFile = parse(code);
|
|
121
|
+
const fileEntry = emptyFileEntry();
|
|
122
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
123
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
124
|
+
expect(fileEntry.inputSources!.length).toBe(1);
|
|
125
|
+
expect(fileEntry.inputSources![0].hasValidation).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('captures callsWithInputArgs when source param is passed to sink-like calls', () => {
|
|
129
|
+
const code = `
|
|
130
|
+
function route(req: any, res: any) {
|
|
131
|
+
res.send(req.body);
|
|
132
|
+
return req;
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
const sourceFile = parse(code);
|
|
136
|
+
const fileEntry = emptyFileEntry();
|
|
137
|
+
collectInputSourceProfile(sourceFile, 'test.ts', fileEntry);
|
|
138
|
+
expect(fileEntry.inputSources).toBeDefined();
|
|
139
|
+
expect(fileEntry.inputSources!.length).toBe(1);
|
|
140
|
+
const calls = fileEntry.inputSources![0].callsWithInputArgs;
|
|
141
|
+
expect(calls.length).toBeGreaterThan(0);
|
|
142
|
+
expect(calls.some(c => c.callee.includes('res.send'))).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
import { getFunctionName, isFunctionLike } from '../ast/helpers.js';
|
|
4
|
+
import { getLineAndCharacter } from '../common/utils.js';
|
|
5
|
+
|
|
6
|
+
import type { FileEntry, InputSourceInfo } from '../types/index.js';
|
|
7
|
+
|
|
8
|
+
const HIGH_CONFIDENCE_PARAM =
|
|
9
|
+
/^(req|request|body|rawBody|formData|payload|query|headers|params)$/i;
|
|
10
|
+
const MEDIUM_CONFIDENCE_PARAM = /^(input|event|message)$/i;
|
|
11
|
+
const SOURCE_PARAM_PATTERNS =
|
|
12
|
+
/^(req|request|body|input|payload|data|params|query|headers|event|message|ctx|context|args|rawBody|formData)/i;
|
|
13
|
+
|
|
14
|
+
function getParamConfidence(params: string[]): 'high' | 'medium' | 'low' {
|
|
15
|
+
let hasMedium = false;
|
|
16
|
+
for (const p of params) {
|
|
17
|
+
if (HIGH_CONFIDENCE_PARAM.test(p)) return 'high';
|
|
18
|
+
if (MEDIUM_CONFIDENCE_PARAM.test(p)) hasMedium = true;
|
|
19
|
+
}
|
|
20
|
+
return hasMedium ? 'medium' : 'low';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const SINK_CALL_PATTERNS: Array<{ pattern: RegExp; kind: string }> = [
|
|
24
|
+
{ pattern: /^eval$/, kind: 'eval' },
|
|
25
|
+
{ pattern: /^Function$/, kind: 'eval' },
|
|
26
|
+
{ pattern: /\.exec(Sync)?$/, kind: 'exec' },
|
|
27
|
+
{ pattern: /^child_process\.(exec|spawn|fork)/, kind: 'exec' },
|
|
28
|
+
{ pattern: /^execSync$|^spawnSync$/, kind: 'exec' },
|
|
29
|
+
{ pattern: /^cp\.exec$|^cp\.spawn$/, kind: 'exec' },
|
|
30
|
+
{ pattern: /\.innerHTML$|\.outerHTML$/, kind: 'innerHTML' },
|
|
31
|
+
{ pattern: /dangerouslySetInnerHTML/, kind: 'innerHTML' },
|
|
32
|
+
{ pattern: /\.query$|\.execute$/, kind: 'sql' },
|
|
33
|
+
{ pattern: /\.redirect$/, kind: 'redirect' },
|
|
34
|
+
{ pattern: /\.send$|\.json$|\.write$/, kind: 'response' },
|
|
35
|
+
{ pattern: /fs\.(writeFile|appendFile)/, kind: 'fs-write' },
|
|
36
|
+
{ pattern: /writeFileSync|appendFileSync/, kind: 'fs-write' },
|
|
37
|
+
{ pattern: /fs\.(readFile|readFileSync|createReadStream)/, kind: 'fs-read' },
|
|
38
|
+
{ pattern: /readFileSync|readFile/, kind: 'fs-read' },
|
|
39
|
+
{ pattern: /path\.(resolve|join)/, kind: 'path-resolve' },
|
|
40
|
+
{ pattern: /^fetch$/, kind: 'ssrf' },
|
|
41
|
+
{ pattern: /^(http|https)\.(request|get)/, kind: 'ssrf' },
|
|
42
|
+
{ pattern: /axios\.(get|post|put|delete|request)/, kind: 'ssrf' },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const SCHEMA_VALIDATOR_PATTERNS =
|
|
46
|
+
/\.(validate|parse|safeParse|parseAsync|check|verify)\s*\(/;
|
|
47
|
+
const VALIDATOR_LIB_PATTERNS =
|
|
48
|
+
/^(z|zod|Joi|yup|ajv|validator|superstruct|io-ts)\./;
|
|
49
|
+
|
|
50
|
+
export function collectInputSourceProfile(
|
|
51
|
+
sourceFile: ts.SourceFile,
|
|
52
|
+
_fileRelative: string,
|
|
53
|
+
fileEntry: FileEntry
|
|
54
|
+
): void {
|
|
55
|
+
const inputSources: InputSourceInfo[] = [];
|
|
56
|
+
|
|
57
|
+
const visitFn = (node: ts.Node): void => {
|
|
58
|
+
if (!isFunctionLike(node)) {
|
|
59
|
+
ts.forEachChild(node, visitFn);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const fnNode = node as ts.FunctionLikeDeclaration;
|
|
64
|
+
const params = fnNode.parameters;
|
|
65
|
+
const sourceParams: string[] = [];
|
|
66
|
+
for (const p of params) {
|
|
67
|
+
const name = p.name.getText(sourceFile);
|
|
68
|
+
if (SOURCE_PARAM_PATTERNS.test(name)) sourceParams.push(name);
|
|
69
|
+
}
|
|
70
|
+
if (sourceParams.length === 0) {
|
|
71
|
+
ts.forEachChild(node, visitFn);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const body = fnNode.body;
|
|
76
|
+
if (!body) {
|
|
77
|
+
ts.forEachChild(node, visitFn);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const sinkKinds = new Set<string>();
|
|
82
|
+
let hasValidation = false;
|
|
83
|
+
const callsWithInputArgs: Array<{ callee: string; lineStart: number }> = [];
|
|
84
|
+
const sourceParamSet = new Set(sourceParams);
|
|
85
|
+
|
|
86
|
+
const walkBody = (child: ts.Node): void => {
|
|
87
|
+
if (isFunctionLike(child) && child !== node) return;
|
|
88
|
+
|
|
89
|
+
if (ts.isCallExpression(child)) {
|
|
90
|
+
const callText = child.expression.getText(sourceFile);
|
|
91
|
+
for (const sink of SINK_CALL_PATTERNS) {
|
|
92
|
+
if (sink.pattern.test(callText)) {
|
|
93
|
+
sinkKinds.add(sink.kind);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (
|
|
98
|
+
SCHEMA_VALIDATOR_PATTERNS.test(callText) ||
|
|
99
|
+
VALIDATOR_LIB_PATTERNS.test(callText)
|
|
100
|
+
) {
|
|
101
|
+
hasValidation = true;
|
|
102
|
+
}
|
|
103
|
+
for (const arg of child.arguments) {
|
|
104
|
+
const argText = arg.getText(sourceFile);
|
|
105
|
+
for (const sp of sourceParamSet) {
|
|
106
|
+
if (
|
|
107
|
+
argText === sp ||
|
|
108
|
+
argText.startsWith(sp + '.') ||
|
|
109
|
+
argText.startsWith(sp + '[')
|
|
110
|
+
) {
|
|
111
|
+
const loc = getLineAndCharacter(sourceFile, child);
|
|
112
|
+
callsWithInputArgs.push({
|
|
113
|
+
callee: callText,
|
|
114
|
+
lineStart: loc.lineStart,
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (ts.isTypeOfExpression(child)) {
|
|
123
|
+
const operand = child.expression.getText(sourceFile);
|
|
124
|
+
if (sourceParamSet.has(operand)) hasValidation = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
ts.isPrefixUnaryExpression(child) &&
|
|
129
|
+
child.operator === ts.SyntaxKind.ExclamationToken
|
|
130
|
+
) {
|
|
131
|
+
const operand = child.operand.getText(sourceFile);
|
|
132
|
+
if (sourceParamSet.has(operand)) hasValidation = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (ts.isIfStatement(child) || ts.isConditionalExpression(child)) {
|
|
136
|
+
const cond = ts.isIfStatement(child)
|
|
137
|
+
? child.expression
|
|
138
|
+
: child.condition;
|
|
139
|
+
const condText = cond.getText(sourceFile);
|
|
140
|
+
for (const sp of sourceParamSet) {
|
|
141
|
+
if (condText.includes(sp)) {
|
|
142
|
+
hasValidation = true;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (
|
|
149
|
+
ts.isCallExpression(child) &&
|
|
150
|
+
child.expression.getText(sourceFile).endsWith('instanceof')
|
|
151
|
+
) {
|
|
152
|
+
hasValidation = true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
ts.isBinaryExpression(child) &&
|
|
157
|
+
child.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword
|
|
158
|
+
) {
|
|
159
|
+
const leftText = child.left.getText(sourceFile);
|
|
160
|
+
if (sourceParamSet.has(leftText)) hasValidation = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
ts.forEachChild(child, walkBody);
|
|
164
|
+
};
|
|
165
|
+
ts.forEachChild(body, walkBody);
|
|
166
|
+
|
|
167
|
+
if (ts.isTemplateExpression(body) || ts.isBlock(body)) {
|
|
168
|
+
const bodyText = body.getText(sourceFile);
|
|
169
|
+
for (const sp of sourceParamSet) {
|
|
170
|
+
if (bodyText.includes(sp + '?.')) {
|
|
171
|
+
hasValidation = true;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const fnLoc = getLineAndCharacter(sourceFile, node);
|
|
178
|
+
const fnName = getFunctionName(node, sourceFile);
|
|
179
|
+
inputSources.push({
|
|
180
|
+
functionName: fnName,
|
|
181
|
+
lineStart: fnLoc.lineStart,
|
|
182
|
+
lineEnd: fnLoc.lineEnd,
|
|
183
|
+
sourceParams,
|
|
184
|
+
hasSinkInBody: sinkKinds.size > 0,
|
|
185
|
+
sinkKinds: [...sinkKinds],
|
|
186
|
+
hasValidation,
|
|
187
|
+
callsWithInputArgs,
|
|
188
|
+
paramConfidence: getParamConfidence(sourceParams),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
ts.forEachChild(node, visitFn);
|
|
192
|
+
};
|
|
193
|
+
ts.forEachChild(sourceFile, visitFn);
|
|
194
|
+
|
|
195
|
+
fileEntry.inputSources = inputSources;
|
|
196
|
+
}
|