File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
lib/semmle/python/security/dataflow
test/query-tests/Security/CWE-918-ServerSideRequestForgery Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,15 @@ module ServerSideRequestForgery {
157
157
branch = true and
158
158
call = API:: moduleImport ( "re" ) .getMember ( [ "match" , "fullmatch" ] ) .getACall ( ) and
159
159
strNode = [ call .getArg ( 1 ) , call .getArgByName ( "string" ) ]
160
+ or
161
+ branch = true and
162
+ call =
163
+ API:: moduleImport ( "re" )
164
+ .getMember ( "compile" )
165
+ .getReturn ( )
166
+ .getMember ( [ "match" , "fullmatch" ] )
167
+ .getACall ( ) and
168
+ strNode = [ call .getArg ( 0 ) , call .getArgByName ( "string" ) ]
160
169
)
161
170
}
162
171
}
Original file line number Diff line number Diff line change @@ -164,3 +164,13 @@ def partial_ssrf_7():
164
164
if re .match (r'[a-zA-Z0-9]+' , user_input ):
165
165
url = f"https://example.com/foo#{ user_input } "
166
166
requests .get (url ) # NOT OK, but NOT FOUND - user input can contain arbitrary character as a suffix.
167
+
168
+ reg = re .compile (r'^[a-zA-Z0-9]+$' )
169
+
170
+ if reg .match (user_input ):
171
+ url = f"https://example.com/foo#{ user_input } "
172
+ requests .get (url ) # OK - user input can only contain alphanumerical characters
173
+
174
+ if reg .fullmatch (user_input ):
175
+ url = f"https://example.com/foo#{ user_input } "
176
+ requests .get (url ) # OK - user input can only contain alphanumerical characters
You can’t perform that action at this time.
0 commit comments