mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Update bleach clean function (#3503)
* Update bleach clean function - Invalid tags are stripped out - & > < characters are accepted * Throw an error if any field contains HTML tags * Update unit tests
This commit is contained in:
@ -227,31 +227,40 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
|
||||
url = reverse('api-part-category-detail', kwargs={'pk': 1})
|
||||
|
||||
self.patch(
|
||||
url,
|
||||
{
|
||||
'description': '<img src=# onerror=alert("pwned")>',
|
||||
},
|
||||
expected_code=200
|
||||
)
|
||||
# Invalid values containing tags
|
||||
invalid_values = [
|
||||
'<img src="test"/>',
|
||||
'<a href="#">Link</a>',
|
||||
"<a href='#'>Link</a>",
|
||||
'<b>',
|
||||
]
|
||||
|
||||
cat = PartCategory.objects.get(pk=1)
|
||||
for v in invalid_values:
|
||||
response = self.patch(
|
||||
url,
|
||||
{
|
||||
'description': v
|
||||
},
|
||||
expected_code=400
|
||||
)
|
||||
|
||||
# Image tags have been stripped
|
||||
self.assertEqual(cat.description, '<img src=# onerror=alert("pwned")>')
|
||||
# Raw characters should be allowed
|
||||
allowed = [
|
||||
'<< hello',
|
||||
'Alpha & Omega',
|
||||
'A > B > C',
|
||||
]
|
||||
|
||||
self.patch(
|
||||
url,
|
||||
{
|
||||
'description': '<a href="www.google.com">LINK</a><script>alert("h4x0r")</script>',
|
||||
},
|
||||
expected_code=200,
|
||||
)
|
||||
for val in allowed:
|
||||
response = self.patch(
|
||||
url,
|
||||
{
|
||||
'description': val,
|
||||
},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
# Tags must have been bleached out
|
||||
cat.refresh_from_db()
|
||||
|
||||
self.assertEqual(cat.description, '<a href="www.google.com">LINK</a><script>alert("h4x0r")</script>')
|
||||
self.assertEqual(response.data['description'], val)
|
||||
|
||||
|
||||
class PartOptionsAPITest(InvenTreeAPITestCase):
|
||||
|
Reference in New Issue
Block a user