feat: DI-aware call resolution for TypeScript/NestJS codebases#39
Draft
joshbouncesecurity wants to merge 2 commits intoknostic:masterfrom
Draft
feat: DI-aware call resolution for TypeScript/NestJS codebases#39joshbouncesecurity wants to merge 2 commits intoknostic:masterfrom
joshbouncesecurity wants to merge 2 commits intoknostic:masterfrom
Conversation
* feat: DI-aware call resolution for TypeScript/NestJS codebases The parser couldn't resolve dependency-injected service calls like `this.callService.getById()` because it didn't know that `callService` is an instance of `CallService`. This caused the agentic enhancer to miss critical authorization checks in service layers, producing false positive vulnerability findings. Changes: - typescript_analyzer.js: Extract constructor parameter types as `constructorDeps` metadata on class methods using ts-morph AST - dependency_resolver.js: Use constructorDeps for DI-aware resolution in _resolveMethodCall, with prefix matching for versioned implementations (e.g., CallService -> CallServiceV1) - Agentic enhancer: Add forward-tracing instructions to the prompt so the agent traces into called functions for auth/validation checks - Agentic enhancer: Add get_static_dependencies tool to surface parsed call graph data to the exploration agent - Agentic enhancer: Pass static deps to tool executor before analysis Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add tests for DI-aware call resolution and enhancer tools - test_di_resolution.py: Tests constructor deps extraction from TypeScript AST and DI-aware method resolution in call graphs, including versioned implementations and false positive prevention - test_enhancer_tools.py: Tests resolve_dependencies and the get_static_dependencies tool via ToolExecutor Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix(tests): replace missing run_utf8 import with subprocess.run test_di_resolution.py imported `run_utf8` from `utilities.file_io`, which does not exist in this repo. The import made the test module unimportable and broke pytest collection for the file (and any wider collection that included it). Mirror the helper used in test_js_parser.py and call subprocess.run directly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> @
Contributor
Author
Manual verificationSample NestJS-style TypeScript: @Injectable()
class UserService {
findById(id: string) { return null; }
}
class UserController {
constructor(private userService: UserService) {}
get(id: string) { return this.userService.findById(id); }
}
|
Contributor
Author
Local test resultsBuilt a tiny inline NestJS-style fixture with a constructor-injected service and ran the JS analyzer + unit_generator from this branch. Fixture ( // user.service.ts
export class UserService {
findById(id: string) { return { id, name: "alice" }; }
}
// user.controller.ts
import { UserService } from "./user.service";
export class UserController {
constructor(private userService: UserService) {}
get(id: string) { return this.userService.findById(id); }
}Commands run: Outcome:
Side note (unrelated to this PR): there is a self-edge ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
Summary
The TypeScript parser doesn't extract constructor parameter types, so dependency-injected service calls (e.g.,
this.userService.findById()) end up unresolved in the call graph. This means security analysis silently misses data flow through injected services — a significant blind spot for typical NestJS apps.This PR adds DI-aware resolution by:
constructorDepsmetadata from the TypeScript AST.this.service.method()calls to the correct target class.Addresses item 7 from #16 (does not close the issue).
Test plan
this.svc.method()resolves to the correct class in the call graph output.@