Files
codeql/python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/test_requests.py
Rasmus Wriedt Larsen 1cc5e54357 Python: Add SSRF queries
I've added 2 queries:

- one that detects full SSRF, where an attacker can control the full URL,
  which is always bad
- and one for partial SSRF, where an attacker can control parts of an
  URL (such as the path, query parameters, or fragment), which is not a
  big problem in many cases (but might still be exploitable)

full SSRF should run by default, and partial SSRF should not (but makes
it easy to see the other results).

Some elements of the full SSRF queries needs a bit more polishing, like
being able to detect `"https://" + user_input` is in fact controlling
the full URL.
2021-12-16 01:48:34 +01:00

12 lines
351 B
Python

from flask import request
import requests
def ssrf_test():
user_input = request.args['untrusted_input']
requests.get(user_input) # NOT OK -- user has full control
# since `requests`` always uses complete URLs, it's not interesting to test more of
# the framework directly. See `full_partial_test.py` for different ways to do SSRF.