Skip to content

Commit a5d3966

Browse files
committed
Python: Refactor StringKind.getTaintOfMethodResult
no need to match on ControlFlowNodes manually anymore 🎉
1 parent 10b36bb commit a5d3966

File tree

1 file changed

+5
-15
lines changed
  • python/ql/src/semmle/python/security/strings

1 file changed

+5
-15
lines changed

python/ql/src/semmle/python/security/strings/Basic.qll

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ abstract class StringKind extends TaintKind {
77
bindingset[this]
88
StringKind() { this = this }
99

10+
override TaintKind getTaintOfMethodResult(string name) {
11+
name in ["strip", "format", "lstrip", "rstrip", "ljust", "rjust", "title", "capitalize"] and
12+
result = this
13+
}
14+
1015
override TaintKind getTaintForFlowStep(ControlFlowNode fromnode, ControlFlowNode tonode) {
1116
result = this and
1217
(
13-
str_method_call(fromnode, tonode) or
1418
slice(fromnode, tonode) or
1519
tonode.(BinaryExprNode).getAnOperand() = fromnode or
1620
os_path_join(fromnode, tonode) or
@@ -50,20 +54,6 @@ private class StringEqualitySanitizer extends Sanitizer {
5054
}
5155
}
5256

53-
/* tonode = fromnode.xxx() where the call to xxx returns an identical or similar string */
54-
private predicate str_method_call(ControlFlowNode fromnode, CallNode tonode) {
55-
exists(string method_name | tonode.getFunction().(AttrNode).getObject(method_name) = fromnode |
56-
method_name = "strip" or
57-
method_name = "format" or
58-
method_name = "lstrip" or
59-
method_name = "rstrip" or
60-
method_name = "ljust" or
61-
method_name = "rjust" or
62-
method_name = "title" or
63-
method_name = "capitalize"
64-
)
65-
}
66-
6757
/* tonode = ....format(fromnode) */
6858
private predicate str_format(ControlFlowNode fromnode, CallNode tonode) {
6959
tonode.getFunction().(AttrNode).getName() = "format" and

0 commit comments

Comments
 (0)