Skip to content

Commit 33559eb

Browse files
authored
Escape javascript breaking on backlash or special characters in finding title (#12514)
* Escape javascript breaking on backlash or special characters in finding titel * Ruff formatting and W605 ignore * Fix escape character issue with \ * Remove ruff noqa comments. * Fix ruff failure on w291
1 parent 69d0d57 commit 33559eb

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

dojo/templates/dojo/filter_js_snippet.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{% if title_words %}
3838
var title_words = [
3939
{% for word in title_words %}
40-
"{{word}}",
40+
"{{word|escapejs}}",
4141
{% endfor %}
4242
];
4343
{% comment %}ideally we use the form.prefix but then we have the trailing dash... django templates are hard{% endcomment %}
@@ -49,7 +49,7 @@
4949
{% if component_words %}
5050
var component_words = [
5151
{% for word in component_words %}
52-
"{{word}}",
52+
"{{word|escapejs}}",
5353
{% endfor %}
5454
];
5555

tests/finding_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,49 @@ def test_create_finding_from_template(self):
519519
self.assertTrue(self.is_success_message_present(text="Finding from template added successfully."))
520520
self.assertTrue(self.is_text_present_on_page(text="App Vulnerable to XSS From Template"))
521521

522+
@on_exception_html_source_logger
523+
def test_create_finding_with_unqiue_characters(self):
524+
driver = self.driver
525+
# Navigate to All Finding page
526+
# goto engagemnent list (and wait for javascript to load)
527+
self.goto_all_engagements_overview(driver)
528+
529+
# Select a previously created engagement title
530+
driver.find_element(By.PARTIAL_LINK_TEXT, "Ad Hoc Engagement").click()
531+
driver.find_element(By.PARTIAL_LINK_TEXT, "Pen Test").click()
532+
533+
# Click on the 'dropdownMenu1 button'
534+
# logger.info("\nClicking on dropdown menu \n")
535+
driver.find_element(By.ID, "dropdownMenu_test_add").click()
536+
self.assertNoConsoleErrors()
537+
# Click on `Apply Template to Finding`
538+
driver.find_element(By.LINK_TEXT, "Finding From Template").click()
539+
self.assertNoConsoleErrors()
540+
# click on the template of 'App Vulnerable to XSS'
541+
logger.info("\nClicking on the template \n")
542+
driver.find_element(By.LINK_TEXT, "Use This Template").click()
543+
self.assertNoConsoleErrors()
544+
driver.find_element(By.ID, "id_title").clear()
545+
# Backslash causes error
546+
driver.find_element(By.ID, "id_title").send_keys("App Vulnerable to XSS from \\Template")
547+
self.assertNoConsoleErrors()
548+
# Click the 'finished' button to submit
549+
driver.find_element(By.ID, "id_finished").click()
550+
self.assertNoConsoleErrors()
551+
# Query the site to determine if the finding has been added
552+
# Assert to the query to determine status of failure
553+
self.assertTrue(self.is_success_message_present(text="Finding from template added successfully."))
554+
self.assertTrue(self.is_text_present_on_page(text="App Vulnerable to XSS From \\Template"))
555+
556+
# Navigate back to the finding list
557+
driver.find_element(By.LINK_TEXT, "Findings").click()
558+
self.assertNoConsoleErrors()
559+
driver.find_element(By.LINK_TEXT, "App Vulnerable to XSS from \\Template").click()
560+
self.assertNoConsoleErrors()
561+
562+
# Assert that the finding is present
563+
self.assertTrue(self.is_text_present_on_page(text="App Vulnerable to XSS from \\Template"))
564+
522565
@on_exception_html_source_logger
523566
def test_delete_finding_template(self):
524567
driver = self.driver

0 commit comments

Comments
 (0)