Skip to content

Commit 45ef3ec

Browse files
authored
Merge pull request github#3619 from erik-krogh/CWE022-Correctness
Approved by asgerf
2 parents bb9c888 + f70453c commit 45ef3ec

File tree

10 files changed

+3027
-2995
lines changed

10 files changed

+3027
-2995
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
| Prototype pollution in utility function (`js/prototype-pollution-utility`) | More results | This query now recognizes additional utility functions as vulnerable to prototype polution. |
6666
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional command execution calls. |
6767
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional file system calls. |
68+
| Uncontrolled data used in path expression (`js/path-injection`) | Fewer results | This query no longer flags paths that have been checked to be part of a collection. |
6869
| Unknown directive (`js/unknown-directive`) | Fewer results | This query no longer flags directives generated by the Babel compiler. |
6970
| Unneeded defensive code (`js/unneeded-defensive-code`) | Fewer false-positive results | This query now recognizes checks meant to handle the `document.all` object. |
7071
| Unused property (`js/unused-property`) | Fewer results | This query no longer flags properties of objects that are operands of `yield` expressions. |

javascript/ql/src/semmle/javascript/security/dataflow/TaintedPathCustomizations.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ module TaintedPath {
369369
}
370370
}
371371

372+
/**
373+
* A check of the form `whitelist.includes(x)` or equivalent, which sanitizes `x` in its "then" branch.
374+
*/
375+
class MembershipTestBarrierGuard extends BarrierGuardNode {
376+
MembershipCandidate candidate;
377+
378+
MembershipTestBarrierGuard() { this = candidate.getTest() }
379+
380+
override predicate blocks(boolean outcome, Expr e) {
381+
candidate = e.flow() and
382+
candidate.getTestPolarity() = outcome
383+
}
384+
}
385+
372386
/**
373387
* A check of form `x.startsWith(dir)` that sanitizes normalized absolute paths, since it is then
374388
* known to be in a subdirectory of `dir`.
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
| normalizedPaths.js:208:38:208:63 | // OK - ... anyway | Spurious alert |
2-
| tainted-string-steps.js:25:43:25:74 | // NOT ... flagged | Missing alert |
3-
| tainted-string-steps.js:26:49:26:74 | // OK - ... flagged | Spurious alert |
4-
| tainted-string-steps.js:28:39:28:70 | // NOT ... flagged | Missing alert |
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
11
import javascript
22
import semmle.javascript.security.dataflow.TaintedPath::TaintedPath
3-
4-
class Assertion extends LineComment {
5-
boolean shouldHaveAlert;
6-
7-
Assertion() {
8-
if getText().matches("%NOT OK%")
9-
then shouldHaveAlert = true
10-
else (
11-
getText().matches("%OK%") and shouldHaveAlert = false
12-
)
13-
}
14-
15-
predicate shouldHaveAlert() { shouldHaveAlert = true }
16-
17-
predicate hasAlert() {
18-
exists(Configuration cfg, DataFlow::Node src, DataFlow::Node sink, Location loc |
19-
cfg.hasFlow(src, sink) and
20-
loc = sink.getAstNode().getLocation() and
21-
loc.getFile() = getFile() and
22-
loc.getEndLine() = getLocation().getEndLine()
23-
)
24-
}
25-
}
26-
27-
from Assertion assertion, string message
28-
where
29-
assertion.shouldHaveAlert() and not assertion.hasAlert() and message = "Missing alert"
30-
or
31-
not assertion.shouldHaveAlert() and assertion.hasAlert() and message = "Spurious alert"
32-
select assertion, message
3+
import testUtilities.ConsistencyChecking

0 commit comments

Comments
 (0)