-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2799 from deniszh/backport/1.1.x/pr-2782
[1.1.x] Sanitize error output for prevent XSS security issues (#2782)
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
import sys | ||
|
||
try: | ||
from django.urls import reverse | ||
except ImportError: # Django < 1.10 | ||
from django.core.urlresolvers import reverse | ||
|
||
from .base import TestCase | ||
|
||
# Silence logging during tests | ||
LOGGER = logging.getLogger() | ||
|
||
# logging.NullHandler is a python 2.7ism | ||
if hasattr(logging, "NullHandler"): | ||
LOGGER.addHandler(logging.NullHandler()) | ||
|
||
if sys.version_info[0] >= 3: | ||
def resp_text(r): | ||
return r.content.decode('utf-8') | ||
else: | ||
def resp_text(r): | ||
return r.content | ||
|
||
|
||
class RenderXSSTest(TestCase): | ||
def test_render_xss(self): | ||
url = reverse('render') | ||
xssStr = '<noscript><p title="</noscript><img src=x onerror=alert() onmouseover=alert()>">' | ||
|
||
# Check for issue #2779 and others | ||
response = self.client.get(url, {'target': 'test', 'format': 'raw', 'cacheTimeout': xssStr, 'from': xssStr}) | ||
self.assertXSS(response, status_code=400, msg_prefix='XSS detected: ') | ||
|
||
|
||
class FindXSSTest(TestCase): | ||
def test_render_xss(self): | ||
url = reverse('metrics_find') | ||
xssStr = '<noscript><p title="</noscript><img src=x onerror=alert() onmouseover=alert()>">' | ||
|
||
response = self.client.get(url, {'query': 'test', 'local': xssStr, 'from': xssStr, 'tz': xssStr}) | ||
self.assertXSS(response, status_code=400, msg_prefix='XSS detected: ') |