Skip to content

Commit 888c327

Browse files
committed
JS: Update API usage in Nest library model
1 parent b50d88a commit 888c327

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 8 additions & 7 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,7 +335,11 @@ 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-
this.asExpr().getTypeBinding().hasUnderlyingStringOrAnyType()
338+
(
339+
this.asExpr().getTypeBinding().hasUnderlyingStringOrAnyType()
340+
or
341+
not exists(this.asExpr().getTypeBinding())
342+
)
341343
}
342344

343345
override Http::RouteHandler getRouteHandler() { result = handler }
@@ -472,7 +474,7 @@ module NestJS {
472474

473475
/** Gets the class being referenced at `node` without relying on the call graph. */
474476
private DataFlow::ClassNode getClassFromNode(DataFlow::Node node) {
475-
NameResolution::trackClassValue(result.getAstNode()) = node.asExpr()
477+
result = node.asExpr().getNameBinding().getClassNode()
476478
}
477479

478480
private predicate providerClassPair(
@@ -488,8 +490,7 @@ module NestJS {
488490
private class DependencyInjectionStep extends PreCallGraphStep {
489491
override predicate classInstanceSource(DataFlow::ClassNode cls, DataFlow::Node node) {
490492
exists(DataFlow::ClassNode interfaceClass |
491-
TypeResolution::valueHasType(node.asExpr(),
492-
TypeResolution::trackType(interfaceClass.getAstNode())) and
493+
node.asExpr().getTypeBinding().getTypeDefinition() = interfaceClass.getAstNode() and
493494
providerClassPair(interfaceClass, cls)
494495
)
495496
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ class TypeNameBindingNode extends NameResolution::Node {
124124
* Holds if this type contains `string` or `any`, possibly wrapped in a promise.
125125
*/
126126
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) }
127135
}
128136

129137
/**

0 commit comments

Comments
 (0)