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 {
157157 branch = true and
158158 call = API:: moduleImport ( "re" ) .getMember ( [ "match" , "fullmatch" ] ) .getACall ( ) and
159159 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" ) ]
160169 )
161170 }
162171}
Original file line number Diff line number Diff line change @@ -164,3 +164,13 @@ def partial_ssrf_7():
164164 if re .match (r'[a-zA-Z0-9]+' , user_input ):
165165 url = f"https://example.com/foo#{ user_input } "
166166 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