Skip to content

Commit 4dc596f

Browse files
authored
Merge pull request github#13381 from erik-krogh/mongooseFindByIdAndUpdate
JS: remove the second argument of findByIdAndUpdate as a NoSQL sink
2 parents 6413fcc + 3fd9f26 commit 4dc596f

File tree

4 files changed

+276
-245
lines changed

4 files changed

+276
-245
lines changed

javascript/ql/lib/semmle/javascript/security/TaintedObject.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ module TaintedObject {
120120
override predicate sanitizes(boolean outcome, Expr e) { e = x and outcome = polarity }
121121
}
122122

123+
/** A guard that checks whether an input a valid string identifier using `mongoose.Types.ObjectId.isValid` */
124+
class ObjectIdGuard extends SanitizerGuard instanceof API::CallNode {
125+
ObjectIdGuard() {
126+
this =
127+
API::moduleImport("mongoose")
128+
.getMember("Types")
129+
.getMember("ObjectId")
130+
.getMember("isValid")
131+
.getACall()
132+
}
133+
134+
override predicate sanitizes(boolean outcome, Expr e, FlowLabel lbl) {
135+
e = super.getAnArgument().asExpr() and outcome = true and lbl = label()
136+
}
137+
}
138+
123139
/**
124140
* A sanitizer guard that validates an input against a JSON schema.
125141
*/

javascript/ql/test/query-tests/Security/CWE-089/untyped/DatabaseAccesses.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| mongoose.js:63:2:63:34 | Documen ... then(X) |
2828
| mongoose.js:65:2:65:51 | Documen ... on(){}) |
2929
| mongoose.js:67:2:68:27 | new Mon ... on(){}) |
30-
| mongoose.js:71:5:78:9 | Documen ... .exec() |
30+
| mongoose.js:71:2:78:9 | Documen ... .exec() |
3131
| mongoose.js:85:2:85:52 | Documen ... query)) |
3232
| mongoose.js:86:2:86:52 | Documen ... query)) |
3333
| mongoose.js:87:2:87:57 | Documen ... query)) |
@@ -42,6 +42,8 @@
4242
| mongoose.js:97:2:97:52 | Documen ... query)) |
4343
| mongoose.js:99:2:99:50 | Documen ... query)) |
4444
| mongoose.js:113:2:113:53 | Documen ... () { }) |
45+
| mongoose.js:134:3:134:52 | Documen ... on(){}) |
46+
| mongoose.js:136:3:136:52 | Documen ... on(){}) |
4547
| mysql.js:8:9:11:47 | connect ... ds) {}) |
4648
| mysql.js:14:9:16:47 | connect ... ds) {}) |
4749
| mysql.js:19:9:20:48 | connect ... ds) {}) |

0 commit comments

Comments
 (0)