Skip to content

Commit ff6936c

Browse files
authored
Merge pull request github#3625 from erik-krogh/CVE714
Approved by asgerf
2 parents 69a1e11 + 82cf538 commit ff6936c

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,26 @@ module TaintTracking {
827827
override predicate appliesTo(Configuration cfg) { any() }
828828
}
829829

830+
/** A check of the form `type x === "undefined"`, which sanitized `x` in its "then" branch. */
831+
class TypeOfUndefinedSanitizer extends AdditionalSanitizerGuardNode, DataFlow::ValueNode {
832+
Expr x;
833+
override EqualityTest astNode;
834+
835+
TypeOfUndefinedSanitizer() {
836+
exists(StringLiteral str, TypeofExpr typeof | astNode.hasOperands(str, typeof) |
837+
str.getValue() = "undefined" and
838+
typeof.getOperand() = x
839+
)
840+
}
841+
842+
override predicate sanitizes(boolean outcome, Expr e) {
843+
outcome = astNode.getPolarity() and
844+
e = x
845+
}
846+
847+
override predicate appliesTo(Configuration cfg) { any() }
848+
}
849+
830850
/** DEPRECATED. This class has been renamed to `MembershipTestSanitizer`. */
831851
deprecated class StringInclusionSanitizer = MembershipTestSanitizer;
832852

javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction.expected

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ nodes
173173
| lib/lib.js:307:39:307:42 | name |
174174
| lib/lib.js:308:23:308:26 | name |
175175
| lib/lib.js:308:23:308:26 | name |
176+
| lib/lib.js:314:40:314:43 | name |
177+
| lib/lib.js:314:40:314:43 | name |
178+
| lib/lib.js:315:22:315:25 | name |
179+
| lib/lib.js:315:22:315:25 | name |
180+
| lib/lib.js:320:23:320:26 | name |
181+
| lib/lib.js:320:23:320:26 | name |
176182
edges
177183
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
178184
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
@@ -381,6 +387,14 @@ edges
381387
| lib/lib.js:307:39:307:42 | name | lib/lib.js:308:23:308:26 | name |
382388
| lib/lib.js:307:39:307:42 | name | lib/lib.js:308:23:308:26 | name |
383389
| lib/lib.js:307:39:307:42 | name | lib/lib.js:308:23:308:26 | name |
390+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name |
391+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name |
392+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name |
393+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name |
394+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
395+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
396+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
397+
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
384398
#select
385399
| lib/lib2.js:4:10:4:25 | "rm -rf " + name | lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name | $@ based on libary input is later used in $@. | lib/lib2.js:4:10:4:25 | "rm -rf " + name | String concatenation | lib/lib2.js:4:2:4:26 | cp.exec ... + name) | shell command |
386400
| lib/lib2.js:8:10:8:25 | "rm -rf " + name | lib/lib2.js:7:32:7:35 | name | lib/lib2.js:8:22:8:25 | name | $@ based on libary input is later used in $@. | lib/lib2.js:8:10:8:25 | "rm -rf " + name | String concatenation | lib/lib2.js:8:2:8:26 | cp.exec ... + name) | shell command |
@@ -433,3 +447,5 @@ edges
433447
| lib/lib.js:272:10:272:32 | "rm -rf ... version | lib/lib.js:267:46:267:48 | obj | lib/lib.js:272:22:272:32 | obj.version | $@ based on libary input is later used in $@. | lib/lib.js:272:10:272:32 | "rm -rf ... version | String concatenation | lib/lib.js:272:2:272:33 | cp.exec ... ersion) | shell command |
434448
| lib/lib.js:277:11:277:30 | "rm -rf " + opts.bla | lib/lib.js:276:8:276:11 | opts | lib/lib.js:277:23:277:30 | opts.bla | $@ based on libary input is later used in $@. | lib/lib.js:277:11:277:30 | "rm -rf " + opts.bla | String concatenation | lib/lib.js:277:3:277:31 | cp.exec ... ts.bla) | shell command |
435449
| lib/lib.js:308:11:308:26 | "rm -rf " + name | lib/lib.js:307:39:307:42 | name | lib/lib.js:308:23:308:26 | name | $@ based on libary input is later used in $@. | lib/lib.js:308:11:308:26 | "rm -rf " + name | String concatenation | lib/lib.js:308:3:308:27 | cp.exec ... + name) | shell command |
450+
| lib/lib.js:315:10:315:25 | "rm -rf " + name | lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name | $@ based on libary input is later used in $@. | lib/lib.js:315:10:315:25 | "rm -rf " + name | String concatenation | lib/lib.js:315:2:315:26 | cp.exec ... + name) | shell command |
451+
| lib/lib.js:320:11:320:26 | "rm -rf " + name | lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name | $@ based on libary input is later used in $@. | lib/lib.js:320:11:320:26 | "rm -rf " + name | String concatenation | lib/lib.js:320:3:320:27 | cp.exec ... + name) | shell command |

javascript/ql/test/query-tests/Security/CWE-078/lib/lib.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,14 @@ module.exports.sanitizer2 = function (name) {
309309

310310
var sanitized = sanitizeShellString(name);
311311
cp.exec("rm -rf " + sanitized); // OK
312+
}
313+
314+
module.exports.typeofcheck = function (name) {
315+
cp.exec("rm -rf " + name); // NOT OK
316+
317+
if (typeof name === "undefined") {
318+
cp.exec("rm -rf " + name); // OK
319+
} else {
320+
cp.exec("rm -rf " + name); // NOT OK
321+
}
312322
}

0 commit comments

Comments
 (0)