Show More
@@ -58,21 +58,8 b' class LoginController(BaseController):' | |||||
58 |
|
58 | |||
59 | def _validate_came_from(self, came_from): |
|
59 | def _validate_came_from(self, came_from): | |
60 | """Return True if came_from is valid and can and should be used""" |
|
60 | """Return True if came_from is valid and can and should be used""" | |
61 | if not came_from: |
|
61 | url = urlparse.urlsplit(came_from) | |
62 | return False |
|
62 | return not url.scheme and not url.netloc | |
63 |
|
||||
64 | parsed = urlparse.urlparse(came_from) |
|
|||
65 | server_parsed = urlparse.urlparse(url.current()) |
|
|||
66 | allowed_schemes = ['http', 'https'] |
|
|||
67 | if parsed.scheme and parsed.scheme not in allowed_schemes: |
|
|||
68 | log.error('Suspicious URL scheme detected %s for url %s', |
|
|||
69 | parsed.scheme, parsed) |
|
|||
70 | return False |
|
|||
71 | if server_parsed.netloc != parsed.netloc: |
|
|||
72 | log.error('Suspicious NETLOC detected %s for url %s server url ' |
|
|||
73 | 'is: %s' % (parsed.netloc, parsed, server_parsed)) |
|
|||
74 | return False |
|
|||
75 | return True |
|
|||
76 |
|
63 | |||
77 | def index(self): |
|
64 | def index(self): | |
78 | c.came_from = safe_str(request.GET.pop('came_from', '')) |
|
65 | c.came_from = safe_str(request.GET.pop('came_from', '')) |
@@ -105,18 +105,14 b' class TestLoginController(TestController' | |||||
105 | ('file:///etc/passwd',), |
|
105 | ('file:///etc/passwd',), | |
106 | ('ftp://ftp.example.com',), |
|
106 | ('ftp://ftp.example.com',), | |
107 | ('http://other.example.com/bl%C3%A5b%C3%A6rgr%C3%B8d',), |
|
107 | ('http://other.example.com/bl%C3%A5b%C3%A6rgr%C3%B8d',), | |
|
108 | ('//evil.example.com/',), | |||
108 | ]) |
|
109 | ]) | |
109 | def test_login_bad_came_froms(self, url_came_from): |
|
110 | def test_login_bad_came_froms(self, url_came_from): | |
110 | response = self.app.post(url(controller='login', action='index', |
|
111 | response = self.app.post(url(controller='login', action='index', | |
111 | came_from=url_came_from), |
|
112 | came_from=url_came_from), | |
112 | {'username': TEST_USER_ADMIN_LOGIN, |
|
113 | {'username': TEST_USER_ADMIN_LOGIN, | |
113 |
'password': TEST_USER_ADMIN_PASS} |
|
114 | 'password': TEST_USER_ADMIN_PASS}, | |
114 | self.assertEqual(response.status, '302 Found') |
|
115 | status=400) | |
115 | self.assertEqual(response._environ['paste.testing_variables'] |
|
|||
116 | ['tmpl_context'].came_from, '/') |
|
|||
117 | response = response.follow() |
|
|||
118 |
|
||||
119 | self.assertEqual(response.status, '200 OK') |
|
|||
120 |
|
116 | |||
121 | def test_login_short_password(self): |
|
117 | def test_login_short_password(self): | |
122 | response = self.app.post(url(controller='login', action='index'), |
|
118 | response = self.app.post(url(controller='login', action='index'), |
General Comments 0
You need to be logged in to leave comments.
Login now