1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 10:10:00 +00:00

Fix open redirect (#519)

The funny thing is that we don't even use this anywhere, and the
referrer is useless on forms. But hey, maybe someday.
This commit is contained in:
TheAMM 2018-09-16 21:14:25 +03:00
parent 8c892f09cc
commit b2ddba994c

View file

@ -211,14 +211,22 @@ def profile():
def redirect_url(): def redirect_url():
home_url = flask.url_for('main.home') next_url = flask.request.args.get('next', '')
referrer = flask.request.referrer or ''
url = flask.request.args.get('next') or \ target_url = (
flask.request.referrer or \ # Use ?next= param if it's a local (/foo/bar) path
home_url (next_url.startswith('/') and next_url) or
if url == flask.request.url: # Use referrer if it's on our own host
return home_url (referrer.startswith(flask.request.host_url) and referrer)
return url )
# Return the target, avoiding infinite loops
if target_url and target_url != flask.request.url:
return target_url
# Default to index
return flask.url_for('main.home')
def send_verification_email(user): def send_verification_email(user):