Skip to content

Commit 86c378b

Browse files
authored
Merge pull request #2907 from graphite-project/copilot/fix-issue-2870
Fix reflected XSS in /metrics/find via `from`/`until` parameters
2 parents 9c0e365 + 5df4cd4 commit 86c378b

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

webapp/tests/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
def is_unsafe_str(s):
66
for symbol in '<>':
7-
if s.find(symbol) > 0:
7+
if s.find(symbol) >= 0:
88
return True
9-
return False
9+
return False
1010

1111

1212
class TestCase(OriginalTestCase):

webapp/tests/test_xss.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_render_xss(self):
2929
xssStr = '<noscript><p title="</noscript><img src=x onerror=alert() onmouseover=alert()>">'
3030

3131
# Check for issue #2779 and others
32-
response = self.client.get(url, {'target': 'test', 'format': 'raw', 'cacheTimeout': xssStr, 'from': xssStr})
32+
response = self.client.get(url, {'target': 'test', 'format': 'raw', 'cacheTimeout': xssStr, 'from': xssStr, 'until': xssStr})
3333
self.assertXSS(response, status_code=400, msg_prefix='XSS detected: ')
3434

3535

@@ -38,5 +38,14 @@ def test_render_xss(self):
3838
url = reverse('metrics_find')
3939
xssStr = '<noscript><p title="</noscript><img src=x onerror=alert() onmouseover=alert()>">'
4040

41-
response = self.client.get(url, {'query': 'test', 'local': xssStr, 'from': xssStr, 'tz': xssStr})
41+
response = self.client.get(url, {'query': 'test', 'local': xssStr, 'from': xssStr, 'until': xssStr, 'tz': xssStr})
4242
self.assertXSS(response, status_code=400, msg_prefix='XSS detected: ')
43+
44+
def test_find_xss_script_tag(self):
45+
"""Test that <script> tags in from/until parameters are properly escaped (issue #2870)"""
46+
url = reverse('metrics_find')
47+
xssStr = "<script>alert('XSS')</script>"
48+
49+
for param in ('from', 'until'):
50+
response = self.client.get(url, {'query': 'test', param: xssStr})
51+
self.assertXSS(response, status_code=400, msg_prefix='XSS detected in %s: ' % param)

0 commit comments

Comments
 (0)