Here's my goal:
http://olivier.life/today
, the button to login will have an url like http://olivier.life/login?back=today
back
" in the "GET
" request. if so then I make a redirect to the url in the GET
My problem is a security problem: I just want to know if the URL in the GET
is part of my application (is valid for one of the URLs in the urls.py
file).
How to do this?
Use resolve
. There's an example that's very close to this use case in the docs. I think for your case you want something like:
def some_view(request):
redirect_target = request.GET.get('back')
if redirect_target:
try:
resolve_match = django.core.urlresolvers.resolve(redirect_target)
except django.core.urlresolvers.Resolver404:
# do something on bad input
else:
return django.shortcuts.redirect(redirect_target)
else:
# empty string redirect target, or not provided at all
# do something else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With