Skip to content

Commit cf13958

Browse files
author
Jon Wayne Parrott
authored
Escape callback error code (googleapis#710)
1 parent feec15f commit cf13958

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

oauth2client/contrib/flask_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def requires_calendar():
176176
from flask import request
177177
from flask import session
178178
from flask import url_for
179+
import markupsafe
179180
except ImportError: # pragma: NO COVER
180181
raise ImportError('The flask utilities require flask 0.9 or newer.')
181182

@@ -388,6 +389,7 @@ def callback_view(self):
388389
if 'error' in request.args:
389390
reason = request.args.get(
390391
'error_description', request.args.get('error', ''))
392+
reason = markupsafe.escape(reason)
391393
return ('Authorization failed: {0}'.format(reason),
392394
httplib.BAD_REQUEST)
393395

tests/contrib/test_flask_util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ def test_callback_view_errors(self):
258258
self.assertEqual(response.status_code, httplib.BAD_REQUEST)
259259
self.assertIn('something', response.data.decode('utf-8'))
260260

261+
# Error supplied to callback with html
262+
with self.app.test_client() as client:
263+
with client.session_transaction() as session:
264+
session['google_oauth2_csrf_token'] = 'tokenz'
265+
266+
response = client.get(
267+
'/oauth2callback?state={}&error=<script>something<script>')
268+
self.assertEqual(response.status_code, httplib.BAD_REQUEST)
269+
self.assertIn(
270+
'&lt;script&gt;something&lt;script&gt;',
271+
response.data.decode('utf-8'))
272+
261273
# CSRF mismatch
262274
with self.app.test_client() as client:
263275
with client.session_transaction() as session:

0 commit comments

Comments
 (0)