Skip to content

Commit 1e58262

Browse files
authored
Merge pull request #2908 from graphite-project/copilot/fix-issue-2794
Fix reflected XSS in composer mygraph view
2 parents 86c378b + ef54ae0 commit 1e58262

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

webapp/graphite/composer/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from django.http import HttpResponse
2222
from django.conf import settings
2323
from django.core.exceptions import ObjectDoesNotExist
24+
from django.utils.html import escape
2425

2526

2627
def composer(request):
@@ -65,7 +66,7 @@ def mygraph(request):
6566
newGraph.save()
6667
except Exception:
6768
log.exception("Failed to create new MyGraph in /composer/mygraph/, graphName=%s" % graphName)
68-
return HttpResponse("Failed to save graph %s" % graphName)
69+
return HttpResponse("Failed to save graph %s" % escape(graphName))
6970

7071
return HttpResponse("SAVED")
7172

@@ -75,9 +76,9 @@ def mygraph(request):
7576
existingGraph.delete()
7677

7778
except ObjectDoesNotExist:
78-
return HttpResponse("No such graph '%s'" % graphName)
79+
return HttpResponse("No such graph '%s'" % escape(graphName))
7980

8081
return HttpResponse("DELETED")
8182

8283
else:
83-
return HttpResponse("Invalid operation '%s'" % action)
84+
return HttpResponse("Invalid operation '%s'" % escape(action))

webapp/tests/test_xss.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
except ImportError: # Django < 1.10
77
from django.urls import reverse
88

9+
from django.contrib.auth.models import User
10+
911
from .base import TestCase
1012

1113
# Silence logging during tests
@@ -49,3 +51,25 @@ def test_find_xss_script_tag(self):
4951
for param in ('from', 'until'):
5052
response = self.client.get(url, {'query': 'test', param: xssStr})
5153
self.assertXSS(response, status_code=400, msg_prefix='XSS detected in %s: ' % param)
54+
55+
56+
class ComposerMyGraphXSSTest(TestCase):
57+
def setUp(self):
58+
self.user = User.objects.create_user('testxss', 'testxss@example.com', 'pass')
59+
self.client.login(username='testxss', password='pass')
60+
61+
def test_mygraph_xss_action(self):
62+
"""Test that XSS in the action parameter is properly escaped (issue #2794)"""
63+
url = reverse('composer_mygraph')
64+
xssStr = '"><script>alert(1)</script>'
65+
66+
response = self.client.get(url, {'action': xssStr, 'graphName': 'test'})
67+
self.assertXSS(response, msg_prefix='XSS detected in action: ')
68+
69+
def test_mygraph_xss_graphname(self):
70+
"""Test that XSS in the graphName parameter is properly escaped (issue #2794)"""
71+
url = reverse('composer_mygraph')
72+
xssStr = '"><script>alert(1)</script>'
73+
74+
response = self.client.get(url, {'action': 'delete', 'graphName': xssStr})
75+
self.assertXSS(response, msg_prefix='XSS detected in graphName: ')

0 commit comments

Comments
 (0)