
Cloud Vulnerability DB
A community-led vulnerabilities database
CVE-2026-40507 is a reflected cross-site scripting (XSS) vulnerability in OpenEMR's patient portal template import handler (/portal/import_template.php). The templateHtml GET parameter is reflected directly into the page response without sanitization, allowing an attacker to craft a malicious URL that executes arbitrary JavaScript in the browser of any authenticated user with Forms Administration permissions who visits the link. All OpenEMR versions before 8.3.0 are affected. The vulnerability was published on August 19, 2026, with a CVSS v3.1 score of 6.1 (Medium) and a CVSS v4.0 score of 5.1 (Medium) (Github Advisory, OpenEMR Advisory).
The root cause is CWE-79 (Improper Neutralization of Input During Web Page Generation), classified as a reflected XSS. In the vulnerable code path within portal/import_template.php, when a GET request includes a non-empty templateHtml parameter, the value is passed directly to renderEditorHtml() without any HTML encoding or sanitization: renderEditorHtml($_REQUEST['docid'], $_GET['templateHtml']);. The fix, introduced in commit ba316dd, removes this unsanitized GET branch entirely and applies HTMLPurifier to template content at render time, stripping script-injectable attributes and javascript: URLs while preserving rich-text markup (OpenEMR Advisory, Fix Commit). No authentication is required from the attacker; only the victim must be authenticated with Forms Administration permissions.
Successful exploitation enables session hijacking of authenticated Forms Administration users, potentially allowing an attacker to take over privileged accounts within the OpenEMR electronic health record system. Because OpenEMR handles sensitive protected health information (PHI), account takeover could expose patient records, demographics, clinical notes, and billing data. The advisory also notes this vulnerability serves as a prerequisite for a chained attack (described as "Vulnerability 5" in the coordinated disclosure), suggesting it could be leveraged to escalate impact beyond session theft (OpenEMR Advisory, Github Advisory).
A proof-of-concept URL is publicly documented in the official security advisory: http://<host>/portal/import_template.php?docid=999&templateHtml=%3Chtml%3E%0A%3Cimg%20src%3Dx%20onerror%3Dalert(JSON.stringify(document))%3E%0A%3C%2Fhtml%3E, which executes immediately when a victim visits the link (OpenEMR Advisory). The NVD SSVC assessment classifies exploitation status as "poc" with no evidence of active in-the-wild exploitation at time of publication. The EPSS score is approximately 0.243% (15th percentile), indicating a low but non-negligible probability of exploitation in the near term (Github Advisory). The vulnerability is not listed in the CISA KEV catalog.
templateHtml GET parameter, for example:http://<target>/portal/import_template.php?docid=999&templateHtml=%3Chtml%3E%3Cimg%20src%3Dx%20onerror%3Dalert(JSON.stringify(document))%3E%3C%2Fhtml%3EtemplateHtml value is rendered directly into the page, causing the injected JavaScript to execute in their browser context.alert() payload with a script that exfiltrates the victim's session cookie or authentication token to an attacker-controlled server, enabling account takeover (OpenEMR Advisory)./portal/import_template.php containing URL-encoded HTML or JavaScript in the templateHtml parameter./portal/import_template.php with a templateHtml parameter containing encoded characters such as %3C, %3E, %22, onerror, alert, document.cookie, or javascript:; repeated requests from the same IP with varying payloads indicating probing activity.Upgrade OpenEMR to version 8.3.0 or later, which removes the vulnerable unsanitized GET branch in portal/import_template.php and applies HTMLPurifier to all template content at render time (OpenEMR Release, Fix Commit). As an interim measure, implement a Content Security Policy (CSP) header to restrict inline JavaScript execution and limit the impact of any reflected XSS. Additionally, educate users with Forms Administration permissions to avoid clicking on unsolicited or unexpected links to the OpenEMR portal.
Source: This report was generated using AI
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."