Skip to content

Commit 17a687b

Browse files
committed
JS: Update type usage in Nest library model
1 parent b82e849 commit 17a687b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Nest.qll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import javascript
66
private import semmle.javascript.security.dataflow.ServerSideUrlRedirectCustomizations
77
private import semmle.javascript.dataflow.internal.PreCallGraphStep
8-
private import semmle.javascript.internal.NameResolution
9-
private import semmle.javascript.internal.TypeResolution
108

119
/**
1210
* Provides classes and predicates for reasoning about [Nest](https://nestjs.com/).
@@ -137,7 +135,7 @@ module NestJS {
137135
hasSanitizingPipe(this, true) and
138136
// Note: we could consider types with class-validator decorators to be sanitized here, but instead we consider the root
139137
// object to be tainted, but omit taint steps for the individual properties names that have sanitizing decorators. See ClassValidator.qll.
140-
TypeResolution::isSanitizingPrimitiveType(this.getParameter().getTypeAnnotation())
138+
this.getParameter().getTypeBinding().isSanitizingPrimitiveType()
141139
}
142140
}
143141

@@ -337,9 +335,10 @@ module NestJS {
337335
handler.isReturnValueReflected() and
338336
this = handler.getAReturn() and
339337
// Only returned strings are sinks. If we can find a type for the return value, it must be string-like.
340-
not exists(NameResolution::Node type |
341-
TypeResolution::valueHasType(this.asExpr(), type) and
342-
not TypeResolution::hasUnderlyingStringOrAnyType(type)
338+
(
339+
this.asExpr().getTypeBinding().hasUnderlyingStringOrAnyType()
340+
or
341+
not exists(this.asExpr().getTypeBinding())
343342
)
344343
}
345344

@@ -475,7 +474,7 @@ module NestJS {
475474

476475
/** Gets the class being referenced at `node` without relying on the call graph. */
477476
private DataFlow::ClassNode getClassFromNode(DataFlow::Node node) {
478-
result.getAstNode() = node.analyze().getAValue().(AbstractClass).getClass()
477+
result = node.asExpr().getNameBinding().getClassNode()
479478
}
480479

481480
private predicate providerClassPair(
@@ -491,7 +490,7 @@ module NestJS {
491490
private class DependencyInjectionStep extends PreCallGraphStep {
492491
override predicate classInstanceSource(DataFlow::ClassNode cls, DataFlow::Node node) {
493492
exists(DataFlow::ClassNode interfaceClass |
494-
node.asExpr().(Parameter).getType().(ClassType).getClass() = interfaceClass.getAstNode() and
493+
node.asExpr().getTypeBinding().getTypeDefinition() = interfaceClass.getAstNode() and
495494
providerClassPair(interfaceClass, cls)
496495
)
497496
}

javascript/ql/lib/semmle/javascript/internal/BindingInfo.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ class TypeNameBindingNode extends NameResolution::Node {
119119
DataFlow::ClassNode getAnUnderlyingClass() {
120120
UnderlyingTypes::nodeHasUnderlyingClassType(this, result)
121121
}
122+
123+
/**
124+
* Holds if this type contains `string` or `any`, possibly wrapped in a promise.
125+
*/
126+
predicate hasUnderlyingStringOrAnyType() { TypeResolution::hasUnderlyingStringOrAnyType(this) }
127+
128+
/**
129+
* Holds if this refers to a type that is considered untaintable (if actually enforced at runtime).
130+
*
131+
* Specifically, the types `number`, `boolean`, `null`, `undefined`, `void`, `never`, as well as literal types (`"foo"`)
132+
* and enums and enum members have this property.
133+
*/
134+
predicate isSanitizingPrimitiveType() { TypeResolution::isSanitizingPrimitiveType(this) }
122135
}
123136

124137
/**

0 commit comments

Comments
 (0)