Skip to content
This repository was archived by the owner on May 20, 2019. It is now read-only.

Commit 2e8fc33

Browse files
committed
Fixed img tags are allowed without filtering of their attributes.
ORA-255
1 parent 1276b1d commit 2e8fc33

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

controller/tests.py

+9
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ def test_request_eta_for_submission_in_true(self):
395395
self.assertEqual(body['success'], True)
396396
self.assertEqual(body['eta'], settings.DEFAULT_ESTIMATED_GRADING_TIME)
397397

398+
def test_sanitize_html(self):
399+
feedback = "This is a sample feedback. <img src='abc' onerror=alert(1)>"
400+
401+
sanitized_feedback = util.sanitize_html(feedback)
402+
403+
# Sanitized feedback should not contain onerror attribute.
404+
self.assertFalse("onerror" in sanitized_feedback)
405+
406+
398407
class ExpireSubmissionsTests(unittest.TestCase):
399408
fixtures = ['/controller/test_data.json']
400409
def setUp(self):

controller/util.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,15 @@ def log_connection_data():
396396

397397
def sanitize_html(text):
398398
try:
399-
cleaner = Cleaner(style=True, links=True, add_nofollow=False, page_structure=True, safe_attrs_only=False, allow_tags = ["img", "a"])
399+
cleaner = Cleaner(
400+
style=True,
401+
links=True,
402+
add_nofollow=False,
403+
page_structure=True,
404+
safe_attrs_only=False,
405+
remove_unknown_tags=False,
406+
allow_tags=["img", "a"]
407+
)
400408
clean_html = cleaner.clean_html(text)
401409
clean_html = re.sub(r'</p>$', '', re.sub(r'^<p>', '', clean_html))
402410
except Exception:

0 commit comments

Comments
 (0)