Skip to content

Commit 4e44fda

Browse files
committed
JS: Use hasUnderlyingStringOrAnyType in Nest model
1 parent 6fdd7fe commit 4e44fda

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,6 @@ module NestJS {
318318
}
319319
}
320320

321-
private predicate isStringType(Type type) {
322-
type instanceof StringType
323-
or
324-
type instanceof AnyType
325-
or
326-
isStringType(type.(PromiseType).getElementType().unfold())
327-
}
328-
329321
/**
330322
* A return value from a route handler, seen as an argument to `res.send()`.
331323
*
@@ -344,10 +336,10 @@ module NestJS {
344336
ReturnValueAsResponseSend() {
345337
handler.isReturnValueReflected() and
346338
this = handler.getAReturn() and
347-
// Only returned strings are sinks
348-
not exists(Type type |
349-
type = this.asExpr().getType() and
350-
not isStringType(type.unfold())
339+
// 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)
351343
)
352344
}
353345

javascript/ql/test/library-tests/frameworks/Nest/test.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ responseSendArgument
7171
| local/customPipe.ts:37:16:37:31 | '' + unsanitized |
7272
| local/customPipe.ts:42:16:42:31 | '' + unsanitized |
7373
| local/customPipe.ts:48:16:48:31 | '' + unsanitized |
74+
| local/routes.ts:7:12:7:16 | 'foo' |
75+
| local/routes.ts:12:12:12:16 | 'foo' |
76+
| local/routes.ts:17:12:17:16 | 'foo' |
7477
| local/routes.ts:32:31:32:31 | x |
7578
| local/routes.ts:33:31:33:38 | queryObj |
7679
| local/routes.ts:34:31:34:34 | name |

0 commit comments

Comments
 (0)