diff --git a/python/ql/lib/semmle/python/security/dataflow/ServerSideRequestForgeryCustomizations.qll b/python/ql/lib/semmle/python/security/dataflow/ServerSideRequestForgeryCustomizations.qll index 9d4350cb8a1..a4e3ecc9ee1 100644 --- a/python/ql/lib/semmle/python/security/dataflow/ServerSideRequestForgeryCustomizations.qll +++ b/python/ql/lib/semmle/python/security/dataflow/ServerSideRequestForgeryCustomizations.qll @@ -157,6 +157,15 @@ module ServerSideRequestForgery { branch = true and call = API::moduleImport("re").getMember(["match", "fullmatch"]).getACall() and strNode = [call.getArg(1), call.getArgByName("string")] + or + branch = true and + call = + API::moduleImport("re") + .getMember("compile") + .getReturn() + .getMember(["match", "fullmatch"]) + .getACall() and + strNode = [call.getArg(0), call.getArgByName("string")] ) } } diff --git a/python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/full_partial_test.py b/python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/full_partial_test.py index 4f915104272..95ff9d64944 100644 --- a/python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/full_partial_test.py +++ b/python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/full_partial_test.py @@ -164,3 +164,13 @@ def partial_ssrf_7(): if re.match(r'[a-zA-Z0-9]+', user_input): url = f"https://example.com/foo#{user_input}" requests.get(url) # NOT OK, but NOT FOUND - user input can contain arbitrary character as a suffix. + + reg = re.compile(r'^[a-zA-Z0-9]+$') + + if reg.match(user_input): + url = f"https://example.com/foo#{user_input}" + requests.get(url) # OK - user input can only contain alphanumerical characters + + if reg.fullmatch(user_input): + url = f"https://example.com/foo#{user_input}" + requests.get(url) # OK - user input can only contain alphanumerical characters