-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve NestJS sources and dependency injection #19769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vasco-jofra
wants to merge
6
commits into
github:main
Choose a base branch
from
trailofbits:VF/Nest-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−19
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
baf0d3e
Model NestJS middlewares as sources
Vasco-jofra 2b143c8
NestJS dependency Injection support useFactory provider
Vasco-jofra 477f32c
NestJS dependency injection support useValue provider
Vasco-jofra 9019879
Improve useFactory inter file function detection
Vasco-jofra 6920430
Improve dependency injection through import function calls
Vasco-jofra e2eca5b
Update test.expected
Vasco-jofra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
27 changes: 21 additions & 6 deletions
27
javascript/ql/test/library-tests/frameworks/Nest/global/app.module.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { Controller } from './validation'; | ||
import { Foo } from './foo.interface'; | ||
import { FooImpl } from './foo.impl'; | ||
import { Imports } from './imports'; | ||
import { Foo, Foo2, Foo3 } from './foo.interface'; | ||
import { FooImpl, Foo2Impl, Foo3Impl } from './foo.impl'; | ||
|
||
const foo3 = new Foo3Impl() | ||
|
||
@Module({ | ||
controllers: [Controller], | ||
providers: [{ | ||
provide: Foo, useClass: FooImpl | ||
}], | ||
controllers: [Controller], | ||
imports: [Imports.forRoot()], | ||
providers: [ | ||
{ | ||
provide: Foo, | ||
useClass: FooImpl | ||
}, | ||
{ | ||
provide: Foo2, | ||
useFactory: () => new Foo2Impl() | ||
}, | ||
{ | ||
provide: Foo3, | ||
useValue: foo3 | ||
} | ||
], | ||
}) | ||
export class AppModule { } |
20 changes: 19 additions & 1 deletion
20
javascript/ql/test/library-tests/frameworks/Nest/global/foo.impl.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import { Foo } from "./foo.interface"; | ||
import { Foo, Foo2, Foo3, Foo4 } from "./foo.interface"; | ||
|
||
export class FooImpl extends Foo { | ||
fooMethod(x: string) { | ||
sink(x); // $ hasValueFlow=x | ||
} | ||
} | ||
|
||
export class Foo2Impl extends Foo2 { | ||
fooMethod(x: string) { | ||
sink(x); // $ hasValueFlow=x | ||
} | ||
} | ||
|
||
export class Foo3Impl extends Foo3 { | ||
fooMethod(x: string) { | ||
sink(x); // $ hasValueFlow=x | ||
} | ||
} | ||
|
||
export class Foo4Impl extends Foo4 { | ||
fooMethod(x: string) { | ||
sink(x); // $ hasValueFlow=x | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
javascript/ql/test/library-tests/frameworks/Nest/global/foo.interface.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
export abstract class Foo { | ||
abstract fooMethod(x: string): void; | ||
} | ||
|
||
export abstract class Foo2 { | ||
abstract fooMethod(x: string): void; | ||
} | ||
|
||
export abstract class Foo3 { | ||
abstract fooMethod(x: string): void; | ||
} | ||
|
||
export abstract class Foo4 { | ||
abstract fooMethod(x: string): void; | ||
} |
16 changes: 16 additions & 0 deletions
16
javascript/ql/test/library-tests/frameworks/Nest/global/imports.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DynamicModule } from '@nestjs/common'; | ||
import { Foo4Impl } from './foo.impl'; | ||
import { Foo4 } from './foo.interface'; | ||
|
||
export class Imports { | ||
static forRoot(): DynamicModule { | ||
return { | ||
providers: [ | ||
{ | ||
provide: Foo4, | ||
useClass: Foo4Impl, | ||
}, | ||
], | ||
}; | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
javascript/ql/test/library-tests/frameworks/Nest/local/middleware.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Injectable, NestMiddleware } from '@nestjs/common'; | ||
import { Response, NextFunction } from 'express'; | ||
import { CustomRequest } from '@randomPackage/request'; | ||
|
||
@Injectable() | ||
export class LoggerMiddleware implements NestMiddleware { | ||
// The request can be a custom type that extends the express Request | ||
use(req: CustomRequest, res: Response, next: NextFunction) { | ||
console.log(req.query.abc); | ||
next(); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes the predicate mutually recursive with call graph construction, which might cause some performance issues. I've started some performance evaluations to help determine how expensive it is.