Skip to content

Commit 6ac46b8

Browse files
Add additional sanitizers to SSRF for methods that restrict the contents of a string.
1 parent fe8f13e commit 6ac46b8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

python/ql/lib/semmle/python/security/dataflow/ServerSideRequestForgeryCustomizations.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private import semmle.python.dataflow.new.DataFlow
99
private import semmle.python.Concepts
1010
private import semmle.python.dataflow.new.RemoteFlowSources
1111
private import semmle.python.dataflow.new.BarrierGuards
12+
private import semmle.python.ApiGraphs
1213

1314
/**
1415
* Provides default sources, sinks and sanitizers for detecting
@@ -137,4 +138,25 @@ module ServerSideRequestForgery {
137138
)
138139
}
139140
}
141+
142+
/** A validation that a string does not contain certain characters, considered as a sanitizer. */
143+
private class StringRestrictionSanitizerGuard extends Sanitizer {
144+
StringRestrictionSanitizerGuard() {
145+
this = DataFlow::BarrierGuard<stringRestriction/3>::getABarrierNode()
146+
}
147+
}
148+
149+
private predicate stringRestriction(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) {
150+
exists(DataFlow::MethodCallNode call, DataFlow::Node strNode |
151+
call.asCfgNode() = g and strNode.asCfgNode() = node
152+
|
153+
branch = true and
154+
call.calls(strNode,
155+
["isalnum", "isalpha", "isdecimal", "isdigit", "isidentifier", "isnumeric", "isspace"])
156+
or
157+
branch = true and
158+
call = API::moduleImport("re").getMember(["match", "fullmatch"]).getACall() and
159+
strNode = [call.getArg(1), call.getArgByName("string")]
160+
)
161+
}
140162
}

0 commit comments

Comments
 (0)