|
6 | 6 | from pyt.constraint_table import constraint_table, initialize_constraint_table
|
7 | 7 | from pyt.fixed_point import analyse
|
8 | 8 | from pyt.framework_adaptor import FrameworkAdaptor
|
9 |
| -from pyt.framework_helper import is_flask_route_function |
| 9 | +from pyt.framework_helper import is_flask_route_function, is_django_view_function |
10 | 10 | from pyt.lattice import Lattice
|
11 | 11 | from pyt.reaching_definitions_taint import ReachingDefinitionsTaintAnalysis
|
12 | 12 |
|
@@ -318,7 +318,7 @@ def test_XSS_url_result(self):
|
318 | 318 | vulnerability_description = str(vulnerability_log.vulnerabilities[0])
|
319 | 319 | EXPECTED_VULNERABILITY_DESCRIPTION = """
|
320 | 320 | File: example/vulnerable_code/XSS_url.py
|
321 |
| - > User input at line 4, trigger word "Flask function URL parameter": |
| 321 | + > User input at line 4, trigger word "Framework function URL parameter": |
322 | 322 | url
|
323 | 323 | Reassigned in:
|
324 | 324 | File: example/vulnerable_code/XSS_url.py
|
@@ -454,3 +454,39 @@ def test_XSS_variable_multiple_assign_result(self):
|
454 | 454 | """
|
455 | 455 |
|
456 | 456 | self.assertTrue(self.string_compare_alpha(vulnerability_description, EXPECTED_VULNERABILITY_DESCRIPTION))
|
| 457 | + |
| 458 | + |
| 459 | +class EngineDjangoTest(BaseTestCase): |
| 460 | + def run_empty(self): |
| 461 | + return |
| 462 | + |
| 463 | + def run_analysis(self, path): |
| 464 | + self.cfg_create_from_file(path) |
| 465 | + cfg_list = [self.cfg] |
| 466 | + |
| 467 | + FrameworkAdaptor(cfg_list, [], [], is_django_view_function) |
| 468 | + initialize_constraint_table(cfg_list) |
| 469 | + |
| 470 | + analyse(cfg_list, analysis_type=ReachingDefinitionsTaintAnalysis) |
| 471 | + |
| 472 | + trigger_word_file = os.path.join('pyt', 'trigger_definitions', 'django_trigger_words.pyt') |
| 473 | + |
| 474 | + return vulnerabilities.find_vulnerabilities(cfg_list, ReachingDefinitionsTaintAnalysis, trigger_word_file=trigger_word_file) |
| 475 | + |
| 476 | + def test_django_view_param(self): |
| 477 | + vulnerability_log = self.run_analysis('example/vulnerable_code/django_XSS.py') |
| 478 | + self.assert_length(vulnerability_log.vulnerabilities, expected_length=2) |
| 479 | + vulnerability_description = str(vulnerability_log.vulnerabilities[0]) |
| 480 | + |
| 481 | + EXPECTED_VULNERABILITY_DESCRIPTION = """ |
| 482 | + File: example/vulnerable_code/django_XSS.py |
| 483 | + > User input at line 4, trigger word "Framework function URL parameter": |
| 484 | + param |
| 485 | + Reassigned in: |
| 486 | + File: example/vulnerable_code/django_XSS.py |
| 487 | + > Line 5: ret_xss1 = ¤call_1 |
| 488 | + File: example/vulnerable_code/django_XSS.py |
| 489 | + > reaches line 5, trigger word "render(": |
| 490 | + ¤call_1 = ret_render(request, 'templates/xss.html', 'param'param) |
| 491 | + """ |
| 492 | + self.assertTrue(self.string_compare_alpha(vulnerability_description, EXPECTED_VULNERABILITY_DESCRIPTION)) |
0 commit comments