Skip to content

Commit be3f59a

Browse files
committed
Replaced StringMethod() with a restrained String method calls
1 parent d939f19 commit be3f59a

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

python/ql/src/experimental/Security/CWE-176/UnicodeBypassValidationQuery.qll

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,35 @@ class Configuration extends TaintTracking::Configuration {
4343
or
4444
exists(RegexExecution re | nodeFrom = re.getString() and nodeTo = re)
4545
or
46-
stringManipulation(nodeFrom, nodeTo)
46+
// String methods
47+
exists(MethodCallNode call, string method_name |
48+
nodeTo = call and call.getMethodName() = method_name
49+
|
50+
call.calls(nodeFrom, method_name) and
51+
method_name in [
52+
"capitalize", "casefold", "center", "expandtabs", "format", "format_map", "join",
53+
"ljust", "lstrip", "lower", "replace", "rjust", "rstrip", "strip", "swapcase", "title",
54+
"upper", "zfill", "encode", "decode"
55+
]
56+
or
57+
method_name = "replace" and
58+
nodeFrom = call.getArg(1)
59+
or
60+
method_name = "format" and
61+
nodeFrom = call.getArg(_)
62+
or
63+
// str -> List[str]
64+
call.calls(nodeFrom, method_name) and
65+
method_name in ["partition", "rpartition", "rsplit", "split", "splitlines"]
66+
or
67+
// Iterable[str] -> str
68+
method_name = "join" and
69+
nodeFrom = call.getArg(0)
70+
or
71+
// Mapping[str, Any] -> str
72+
method_name = "format_map" and
73+
nodeFrom = call.getArg(0)
74+
)
4775
) and
4876
stateFrom instanceof PreValidation and
4977
stateTo instanceof PostValidation

0 commit comments

Comments
 (0)