|
4 | 4 | import logging |
5 | 5 | import re |
6 | 6 | import time |
7 | | -import xml.etree.ElementTree as ET |
8 | 7 | from datetime import datetime |
9 | 8 |
|
10 | 9 | import six |
11 | 10 | import tagulous |
| 11 | +from defusedxml import ElementTree as ET |
12 | 12 | from django.conf import settings |
13 | 13 | from django.contrib.auth.models import Group, Permission |
14 | 14 | from django.contrib.auth.password_validation import validate_password |
@@ -2394,14 +2394,14 @@ def process_scan( |
2394 | 2394 | duration = time.perf_counter() - start_time |
2395 | 2395 | LargeScanSizeProductAnnouncement(response_data=data, duration=duration) |
2396 | 2396 | ScanTypeProductAnnouncement(response_data=data, scan_type=context.get("scan_type")) |
| 2397 | + except ET.ParseError as e: |
| 2398 | + raise serializers.ValidationError({"file": f"Malformed XML: {e}"}) |
2397 | 2399 | # convert to exception otherwise django rest framework will swallow them as 400 error |
2398 | 2400 | # exceptions are already logged in the importer |
2399 | 2401 | except SyntaxError as se: |
2400 | 2402 | raise Exception(se) |
2401 | 2403 | except ValueError as ve: |
2402 | 2404 | raise Exception(ve) |
2403 | | - except ET.ParseError as e: |
2404 | | - raise serializers.ValidationError(f"Malformed XML: {e}") |
2405 | 2405 |
|
2406 | 2406 | def validate(self, data: dict) -> dict: |
2407 | 2407 | scan_type = data.get("scan_type") |
@@ -2704,14 +2704,14 @@ def process_scan( |
2704 | 2704 | duration = time.perf_counter() - start_time |
2705 | 2705 | LargeScanSizeProductAnnouncement(response_data=data, duration=duration) |
2706 | 2706 | ScanTypeProductAnnouncement(response_data=data, scan_type=context.get("scan_type")) |
| 2707 | + except ET.ParseError as e: |
| 2708 | + raise serializers.ValidationError({"file": f"Malformed XML: {e}"}) |
2707 | 2709 | # convert to exception otherwise django rest framework will swallow them as 400 error |
2708 | 2710 | # exceptions are already logged in the importer |
2709 | 2711 | except SyntaxError as se: |
2710 | 2712 | raise Exception(se) |
2711 | 2713 | except ValueError as ve: |
2712 | 2714 | raise Exception(ve) |
2713 | | - except ET.ParseError as e: |
2714 | | - raise serializers.ValidationError(f"Malformed XML: {e}") |
2715 | 2715 |
|
2716 | 2716 | def save(self, *, push_to_jira=False): |
2717 | 2717 | # Go through the validate method |
@@ -2788,12 +2788,12 @@ def save(self): |
2788 | 2788 | create_dojo_meta, |
2789 | 2789 | origin="API", |
2790 | 2790 | ) |
| 2791 | + except ET.ParseError as e: |
| 2792 | + raise serializers.ValidationError({"file": f"Malformed XML: {e}"}) |
2791 | 2793 | except SyntaxError as se: |
2792 | 2794 | raise Exception(se) |
2793 | 2795 | except ValueError as ve: |
2794 | 2796 | raise Exception(ve) |
2795 | | - except ET.ParseError as e: |
2796 | | - raise serializers.ValidationError(f"Malformed XML: {e}") |
2797 | 2797 |
|
2798 | 2798 |
|
2799 | 2799 | class LanguageTypeSerializer(serializers.ModelSerializer): |
|
0 commit comments