Skip to content

Commit 53763c7

Browse files
authored
Merge pull request #2741 from esbena/js/split-and-slice-for-tainted-path
Approved by erik-krogh
2 parents 2928f9e + 8a2c81b commit 53763c7

File tree

5 files changed

+1021
-0
lines changed

5 files changed

+1021
-0
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations and ignores the first statement of a try block. |
4343
| Use of call stack introspection in strict mode (`js/strict-mode-call-stack-introspection`) | Fewer false positive results | The query no longer flags expression statements. |
4444
| Missing CSRF middleware (`js/missing-token-validation`) | Fewer false positive results | The query reports fewer duplicates and only flags handlers that explicitly access cookie data. |
45+
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed. |
4546

4647
## Changes to libraries
4748

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,40 @@ module TaintedPath {
6767
read.getPropertyName() != "length" and
6868
srclabel = dstlabel
6969
)
70+
or
71+
// string method calls of interest
72+
exists(DataFlow::MethodCallNode mcn, string name |
73+
srclabel = dstlabel and dst = mcn and mcn.calls(src, name)
74+
|
75+
exists(string substringMethodName |
76+
substringMethodName = "substr" or
77+
substringMethodName = "substring" or
78+
substringMethodName = "slice"
79+
|
80+
name = substringMethodName and
81+
// to avoid very dynamic transformations, require at least one fixed index
82+
exists(mcn.getAnArgument().asExpr().getIntValue())
83+
)
84+
or
85+
exists(string argumentlessMethodName |
86+
argumentlessMethodName = "toLocaleLowerCase" or
87+
argumentlessMethodName = "toLocaleUpperCase" or
88+
argumentlessMethodName = "toLowerCase" or
89+
argumentlessMethodName = "toUpperCase" or
90+
argumentlessMethodName = "trim" or
91+
argumentlessMethodName = "trimLeft" or
92+
argumentlessMethodName = "trimRight"
93+
|
94+
name = argumentlessMethodName
95+
)
96+
or
97+
name = "split" and
98+
not exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) |
99+
splitBy.mayHaveStringValue("/") or
100+
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/")
101+
.flowsTo(splitBy)
102+
)
103+
)
70104
}
71105

72106
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
| normalizedPaths.js:208:38:208:63 | // OK - ... anyway | Spurious alert |
2+
| tainted-string-steps.js:13:41:13:72 | // NOT ... flagged | Missing alert |
3+
| tainted-string-steps.js:14:41:14:72 | // NOT ... flagged | Missing alert |
4+
| tainted-string-steps.js:15:50:15:81 | // NOT ... flagged | Missing alert |
5+
| tainted-string-steps.js:25:43:25:74 | // NOT ... flagged | Missing alert |
6+
| tainted-string-steps.js:26:49:26:74 | // OK - ... flagged | Spurious alert |

0 commit comments

Comments
 (0)