Skip to content

Commit 1c56925

Browse files
author
Jon Wayne Parrott
authored
Escape error reason for oauth2 callback in django_util (googleapis#724)
1 parent d94570e commit 1c56925

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

oauth2client/contrib/django_util/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from django.conf import settings
2929
from django.core import urlresolvers
3030
from django.shortcuts import redirect
31+
from django.utils import html
3132
import jsonpickle
3233
from six.moves.urllib import parse
3334

@@ -109,6 +110,7 @@ def oauth2_callback(request):
109110
if 'error' in request.GET:
110111
reason = request.GET.get(
111112
'error_description', request.GET.get('error', ''))
113+
reason = html.escape(reason)
112114
return http.HttpResponseBadRequest(
113115
'Authorization failed {0}'.format(reason))
114116

tests/contrib/django_util/test_views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ def test_error_returns_bad_request(self):
249249
self.assertIsInstance(response, http.HttpResponseBadRequest)
250250
self.assertIn(b'Authorization failed', response.content)
251251

252+
def test_error_escapes_html(self):
253+
request = self.factory.get('oauth2/oauth2callback', data={
254+
'error': '<script>bad</script>',
255+
})
256+
response = views.oauth2_callback(request)
257+
self.assertIsInstance(response, http.HttpResponseBadRequest)
258+
self.assertNotIn(b'<script>', response.content)
259+
self.assertIn(b'&lt;script&gt;', response.content)
260+
252261
def test_no_session(self):
253262
request = self.factory.get('oauth2/oauth2callback', data={
254263
'code': 123,

0 commit comments

Comments
 (0)