Skip to content

Commit

Permalink
[#1039] make sure came_from url is sane (local)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Jun 26, 2013
1 parent 09705da commit 6180c75
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ckan/controllers/user.py
@@ -1,5 +1,6 @@
import logging
from urllib import quote
from urlparse import urlparse

from pylons import config

Expand Down Expand Up @@ -332,7 +333,7 @@ def login(self, error=None):
def logged_in(self):
# redirect if needed
came_from = request.params.get('came_from', '')
if came_from:
if self._sane_came_from(came_from):
return h.redirect_to(str(came_from))

if c.user:
Expand Down Expand Up @@ -368,7 +369,7 @@ def logout(self):
def logged_out(self):
# redirect if needed
came_from = request.params.get('came_from', '')
if came_from:
if self._sane_came_from(came_from):
return h.redirect_to(str(came_from))
h.redirect_to(controller='user', action='logged_out_page')

Expand Down Expand Up @@ -640,3 +641,11 @@ def unfollow(self, id):
or e.error_dict)
h.flash_error(error_message)
h.redirect_to(controller='user', action='read', id=id)

def _sane_came_from(self, url):
'''Returns True if came_from is local'''
return not bool(not url
# url has a scheme eg http://
or urlparse(url).scheme
# url starts with // which can be none relative
or (len(url) >= 2 and url.startswith('//')))

0 comments on commit 6180c75

Please sign in to comment.