Skip to content

Latest commit

 

History

History
108 lines (95 loc) · 9.49 KB

File metadata and controls

108 lines (95 loc) · 9.49 KB

Here is the combined list of vulnerabilities, formatted as markdown, with duplicate entries removed and information merged:

Combined Vulnerability List

This document details a Stored Cross-Site Scripting (XSS) vulnerability found within the Django admin interface when using the django-admin-interface application. The vulnerability arises from the ability of administrative users to upload SVG files as logos for admin themes without proper sanitization.

  • Vulnerability Name: Stored Cross-Site Scripting (XSS) via SVG Logo Upload

    • Description: The django-admin-interface application allows administrators to customize the admin panel's appearance by uploading logo and favicon files. These files are handled via Django's FileField in the Theme model. The application uses FileExtensionValidator to check if uploaded files for the "logo" and "favicon" fields have allowed extensions, including .svg. However, this validator only checks the file extension and does not inspect the file content. This oversight allows an attacker with administrative privileges to upload a maliciously crafted SVG file containing embedded JavaScript code. When an administrator views any page within the Django admin panel, the uploaded SVG logo or favicon is rendered. If the SVG contains malicious JavaScript, this script executes within the administrator's browser session, in the security context of the admin panel's domain.

      Step-by-step trigger scenario:

      1. An attacker with administrative privileges logs into the Django admin panel.
      2. The attacker navigates to the "Admin Interface" section and selects "Themes".
      3. The attacker edits the currently active theme or creates a new theme.
      4. In the "Logo" or "Favicon" field, the attacker uploads a malicious SVG file. This SVG file contains embedded JavaScript code, for example, <svg><script>alert("XSS")</script></svg>.
      5. The attacker saves the theme configuration.
      6. When any administrator subsequently accesses any page within the Django admin panel, the uploaded SVG logo or favicon is rendered as part of the admin interface.
      7. The browser renders the SVG and executes the embedded JavaScript code within the administrator's browser session.
    • Impact: Successful exploitation of this vulnerability allows an attacker to execute arbitrary JavaScript code within the browser of an administrator viewing the admin panel. The potential impacts include:

      • Account Takeover: By stealing session cookies or other authentication tokens, the attacker can hijack the administrator's session and gain full control over the Django application and its data.
      • Data Breach: The attacker can perform actions on behalf of the administrator, including viewing, modifying, or deleting sensitive data accessible through the admin panel. This data can then be exfiltrated to an attacker-controlled server.
      • Privilege Escalation: If the compromised administrator account has permissions to manage users or roles, the attacker might be able to escalate privileges, create new administrative accounts, or compromise other users.
      • Admin Panel Defacement: The attacker could deface the admin interface, causing disruption or misinformation.
    • Vulnerability Rank: High

    • Currently Implemented Mitigations:

      • File Extension Validation: The Theme model's logo and favicon fields utilize Django's FileExtensionValidator. This validator is implemented in /code/admin_interface/models.py and restricts the types of files that can be uploaded based on their extensions. Allowed extensions for logos are gif, jpg, jpeg, png, and svg, and for favicons, additionally ico is allowed.
      • Mitigation Location: admin_interface/models.py in the Theme model definition for logo and favicon fields.
    • Missing Mitigations:

      • SVG Sanitization: The most critical missing mitigation is the sanitization of uploaded SVG files. Before storing and serving SVG logos and favicons, the application should process these files to remove any potentially malicious or executable code, such as <script> tags, onclick attributes, and other event handlers. Libraries like defusedxml or specialized SVG sanitizers should be employed.
      • Content Security Policy (CSP): Implementing a Content Security Policy (CSP) would significantly reduce the impact of XSS vulnerabilities. A properly configured CSP can restrict the sources from which the admin panel can load resources and can prevent inline JavaScript execution, acting as a defense-in-depth measure.
      • Input Validation for Filenames: While not directly related to XSS, sanitizing filenames of uploaded files can prevent other potential issues, such as path traversal vulnerabilities if filenames are used in file system operations.
    • Preconditions:

      • The attacker must have administrative privileges to access the Django admin panel.
      • The attacker must have permissions to edit or create Theme objects within the admin panel.
      • The admin_interface application must be installed and configured in a Django project.
    • Source Code Analysis:

      1. File: admin_interface/models.py
      2. Theme Model Definition:
        class Theme(models.Model):
            # ...
            logo = models.FileField(
                upload_to="admin-interface/logo/",
                blank=True,
                validators=[
                    FileExtensionValidator(
                        allowed_extensions=["gif", "jpg", "jpeg", "png", "svg"]
                    )
                ],
                help_text=_("Leave blank to use the default Django logo"),
                verbose_name=_("logo"),
            )
            favicon = models.FileField(
                upload_to="admin-interface/favicon/",
                blank=True,
                validators=[
                    FileExtensionValidator(
                        allowed_extensions=["gif", "ico", "jpg", "jpeg", "png", "svg"]
                    )
                ],
                help_text=_("(.ico|.png|.gif - 16x16|32x32 px)"),
                verbose_name=_("favicon"),
            )
            # ...
      3. FileExtensionValidator Usage: The logo and favicon fields are defined as FileField and use FileExtensionValidator to validate the extension of uploaded files. The allowed extensions include svg.
      4. Extension-Based Validation: The FileExtensionValidator only checks if the uploaded file's extension is in the allowed list. It does not perform any content sanitization or inspection of the file's internal content.
      5. Vulnerability Mechanism: When an administrator uploads a malicious SVG file containing JavaScript code as the logo or favicon, and the application renders this SVG without sanitization, the JavaScript code within the SVG can be executed in the context of the admin user's browser, leading to Stored XSS.
    • Security Test Case:

      1. Pre-requisites:
        • Ensure you have a running Django application with django-admin-interface installed and configured.
        • Create a superuser account for administrative access.
      2. Create a malicious SVG file:
        • Create a new text file named xss.svg and paste the following content into it:
          <?xml version="1.0" standalone="no"?>
          <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
          <svg width="200" height="200" version="1.1" xmlns="http://www.w3.org/2000/svg">
            <script type="text/javascript">
              alert('XSS Vulnerability');
            </script>
            <text x="0" y="15" fill="red">SVG Image</text>
          </svg>
      3. Log in to the Django Admin Panel:
        • Open your web browser and navigate to the admin panel of your Django application (e.g., /admin/).
        • Log in using your superuser credentials.
      4. Navigate to Theme settings:
        • In the admin dashboard, find the "Admin Interface" section and click on "Themes".
        • You will see a list of themes. Either edit an existing theme (like "Django") or create a new theme by clicking "Add Theme".
      5. Upload the malicious SVG logo:
        • In the theme edit/create form, locate the "Logo" or "Favicon" field.
        • Click on "Choose File" and select the xss.svg file you created in step 2.
        • Click "Save" to save the theme with the malicious SVG.
      6. Verify the XSS vulnerability:
        • After saving, navigate to any other page within the Django admin panel, such as the dashboard or any model's changelist view.
        • Observe your browser window. If a JavaScript alert box pops up displaying the message "XSS Vulnerability" (or similar), it confirms that the XSS vulnerability is present. The JavaScript code embedded in the SVG logo has been executed.

This combined vulnerability report highlights the Stored Cross-Site Scripting risk due to insufficient SVG sanitization in the django-admin-interface application. Implementing SVG sanitization and Content Security Policy are recommended mitigations to address this high-severity vulnerability.