-
Notifications
You must be signed in to change notification settings - Fork 25
/
redirect.py
33 lines (25 loc) · 1.1 KB
/
redirect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import urlparse
from google.appengine.ext.webapp import RequestHandler
from config import config
import custom_exceptions
import os
from .gae_bingo import bingo, _iri_to_uri
class Redirect(RequestHandler):
def get(self):
""" Score conversions and redirect as specified by url params
Expects a 'continue' url parameter for the destination,
and a 'conversion_name' url parameter for each conversion to score.
"""
cont = self.request.get('continue', default_value='/')
# Check whether redirecting to an absolute or relative url
netloc = urlparse.urlsplit(cont).netloc
if (netloc and
netloc != os.environ["HTTP_HOST"] and
not config.is_safe_hostname(netloc)):
# Disallow open redirects to other domains.
raise custom_exceptions.InvalidRedirectURLError(
"Redirecting to an absolute url is not allowed.")
conversion_names = self.request.get_all('conversion_name')
if len(conversion_names):
bingo(conversion_names)
self.redirect(_iri_to_uri(cont))