File tree Expand file tree Collapse file tree 6 files changed +37
-11
lines changed
lib/semmle/javascript/frameworks
test/library-tests/frameworks/Nest Expand file tree Collapse file tree 6 files changed +37
-11
lines changed Original file line number Diff line number Diff line change @@ -519,12 +519,20 @@ module NestJS {
519
519
.( DataFlow:: ArrayCreationNode )
520
520
.getAnElement ( )
521
521
}
522
+ private DataFlow:: Node getConcreteClassFromProviderTuple ( DataFlow:: SourceNode tuple ) {
523
+ result = tuple .getAPropertyWrite ( "useClass" ) .getRhs ( )
524
+ or
525
+ exists ( DataFlow:: FunctionNode f |
526
+ f = tuple .getAPropertyWrite ( "useFactory" ) .getRhs ( ) .getALocalSource ( ) and
527
+ result .getAstNode ( ) = f .getFunction ( ) .getAReturnedExpr ( ) .getType ( ) .( ClassType ) .getClass ( )
528
+ )
529
+ }
522
530
523
531
private predicate providerPair ( DataFlow:: Node interface , DataFlow:: Node concreteClass ) {
524
532
exists ( DataFlow:: SourceNode tuple |
525
533
tuple = providerTuple ( ) .getALocalSource ( ) and
526
534
interface = tuple .getAPropertyWrite ( "provide" ) .getRhs ( ) and
527
- concreteClass = tuple . getAPropertyWrite ( "useClass" ) . getRhs ( )
535
+ concreteClass = getConcreteClassFromProviderTuple ( tuple )
528
536
)
529
537
}
530
538
Original file line number Diff line number Diff line change 1
1
import { Module } from '@nestjs/common' ;
2
2
import { Controller } from './validation' ;
3
- import { Foo } from './foo.interface' ;
4
- import { FooImpl } from './foo.impl' ;
3
+ import { Foo , Foo2 } from './foo.interface' ;
4
+ import { FooImpl , Foo2Impl } from './foo.impl' ;
5
5
6
6
@Module ( {
7
- controllers : [ Controller ] ,
8
- providers : [ {
9
- provide : Foo , useClass : FooImpl
10
- } ] ,
7
+ controllers : [ Controller ] ,
8
+ providers : [
9
+ {
10
+ provide : Foo ,
11
+ useClass : FooImpl
12
+ } ,
13
+ {
14
+ provide : Foo2 ,
15
+ useFactory : ( ) => new Foo2Impl ( )
16
+ }
17
+ ] ,
11
18
} )
12
19
export class AppModule { }
Original file line number Diff line number Diff line change 1
- import { Foo } from "./foo.interface" ;
1
+ import { Foo , Foo2 } from "./foo.interface" ;
2
2
3
3
export class FooImpl extends Foo {
4
4
fooMethod ( x : string ) {
5
5
sink ( x ) ; // $ hasValueFlow=x
6
6
}
7
7
}
8
+
9
+ export class Foo2Impl extends Foo2 {
10
+ fooMethod ( x : string ) {
11
+ sink ( x ) ; // $ hasValueFlow=x
12
+ }
13
+ }
Original file line number Diff line number Diff line change 1
1
export abstract class Foo {
2
2
abstract fooMethod ( x : string ) : void ;
3
3
}
4
+
5
+ export abstract class Foo2 {
6
+ abstract fooMethod ( x : string ) : void ;
7
+ }
Original file line number Diff line number Diff line change 1
1
import { Get , Query } from '@nestjs/common' ;
2
2
import { IsIn } from 'class-validator' ;
3
- import { Foo } from './foo.interface' ;
3
+ import { Foo , Foo2 } from './foo.interface' ;
4
4
5
5
export class Controller {
6
6
constructor (
7
- private readonly foo : Foo
7
+ private readonly foo : Foo , private readonly foo2 : Foo2
8
8
) { }
9
9
10
10
@Get ( )
@@ -16,6 +16,7 @@ export class Controller {
16
16
@Get ( )
17
17
route2 ( @Query ( 'x' ) x : string ) {
18
18
this . foo . fooMethod ( x ) ;
19
+ this . foo2 . fooMethod ( x ) ;
19
20
}
20
21
}
21
22
Original file line number Diff line number Diff line change 1
1
testFailures
2
2
routeHandler
3
3
| global/validation.ts:11:3:14:3 | route1( ... OK\\n } |
4
- | global/validation.ts:17:3:19 :3 | route2( ... x);\\n } |
4
+ | global/validation.ts:17:3:20 :3 | route2( ... x);\\n } |
5
5
| local/customDecorator.ts:18:3:20:3 | sneaky( ... OK\\n } |
6
6
| local/customDecorator.ts:23:3:25:3 | safe(@S ... OK\\n } |
7
7
| local/customPipe.ts:20:5:22:5 | sanitiz ... K\\n } |
You can’t perform that action at this time.
0 commit comments