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

Commit

Permalink
Escape callback error code (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed May 9, 2017
1 parent feec15f commit cf13958
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit cf13958

Please sign in to comment.