The open redirect protection for this example is still vulnerable
|
target = request.args.get('target', '') |
|
target = target.replace('\\', '') |
|
if not urlparse(target).netloc: |
|
# relative path, safe to redirect |
|
return redirect(target, code=302) |
A target like https:/example.com (notice the single /) will be parsed as having no netloc, but browsers will redirect to https://example.com (tested on Firefox and Chrome using Fedora).
from urllib.parse import urlparse
print(urlparse('https:/example.com'))
# ParseResult(scheme='https', netloc='', path='/example.com', params='', query='', fragment='')
See Django for example
https://github.com/django/django/blob/f339c4c8e4870f23d3ba8bf8ee68c57628739592/django/utils/http.py#L356-L361
The open redirect protection for this example is still vulnerable
codeql/python/ql/src/Security/CWE-601/examples/redirect_good2.py
Lines 8 to 12 in dea9229
A target like
https:/example.com(notice the single/) will be parsed as having no netloc, but browsers will redirect tohttps://example.com(tested on Firefox and Chrome using Fedora).See Django for example
https://github.com/django/django/blob/f339c4c8e4870f23d3ba8bf8ee68c57628739592/django/utils/http.py#L356-L361