Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Escape callback error code in flask_util #710

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oauth2client/contrib/flask_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def requires_calendar():
from flask import request
from flask import session
from flask import url_for
import markupsafe
except ImportError: # pragma: NO COVER
raise ImportError('The flask utilities require flask 0.9 or newer.')

Expand Down Expand Up @@ -388,6 +389,7 @@ def callback_view(self):
if 'error' in request.args:
reason = request.args.get(
'error_description', request.args.get('error', ''))
reason = markupsafe.escape(reason)
return ('Authorization failed: {0}'.format(reason),
httplib.BAD_REQUEST)

Expand Down
12 changes: 12 additions & 0 deletions tests/contrib/test_flask_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ def test_callback_view_errors(self):
self.assertEqual(response.status_code, httplib.BAD_REQUEST)
self.assertIn('something', response.data.decode('utf-8'))

# Error supplied to callback with html
with self.app.test_client() as client:
with client.session_transaction() as session:
session['google_oauth2_csrf_token'] = 'tokenz'

response = client.get(
'/oauth2callback?state={}&error=<script>something<script>')
self.assertEqual(response.status_code, httplib.BAD_REQUEST)
self.assertIn(
'&lt;script&gt;something&lt;script&gt;',
response.data.decode('utf-8'))

# CSRF mismatch
with self.app.test_client() as client:
with client.session_transaction() as session:
Expand Down