Audit a post-login redirect
The application redirects to a destination copied from a request parameter.
def after_login(request):
return redirect(request.args.get("next", "/dashboard"))
Choose a destination from a small allowlist instead of trusting an arbitrary URL supplied by the caller.
What is the safest way to choose the post-login destination?
An explicit allowlist prevents external or unexpected destinations.
A value beginning with two slashes can still be interpreted as an external URL.
Other URL forms and encodings can still point off-site.
Encoding does not restrict which destination the browser navigates to.
Why it matters: Unvalidated redirects can send users to attacker-controlled sites after a trusted login.