Skip to content

Python: open redirect protection example is still vulnerable #16041

Closed
@stsewd

Description

@stsewd

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

Metadata

Metadata

Assignees

Labels

PythonquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions