PHP2Shell: Read our blog on the critical RCE vulnerabilities affecting 70% of the Internet

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

Technical details

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.

Impact

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

Exploitability

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.

Exploitation steps

  1. Reconnaissance: Identify internet-facing OpenEMR instances running versions prior to 8.3.0 using search engines (Shodan, Censys) or by checking the OpenEMR version disclosure endpoint.
  2. Identify target user: Determine or social-engineer a user with Forms Administration permissions (e.g., a clinical administrator or forms manager) within the target OpenEMR deployment.
  3. Craft malicious URL: Construct a URL targeting the vulnerable endpoint with a URL-encoded XSS payload in the 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%3E
  4. Deliver the URL: Send the crafted URL to the target user via phishing email, internal messaging, or any other social engineering vector.
  5. Payload execution: When the authenticated Forms Administration user clicks the link, the unsanitized templateHtml value is rendered directly into the page, causing the injected JavaScript to execute in their browser context.
  6. Session hijacking: Replace the 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).

Indicators of compromise

  • Network: Outbound HTTP requests from the OpenEMR server or victim browser to unexpected external domains shortly after a user visits the portal template import page; unusual GET requests to /portal/import_template.php containing URL-encoded HTML or JavaScript in the templateHtml parameter.
  • Logs: Web server access logs showing GET requests to /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.
  • Browser/Session: Unexpected session invalidation or concurrent sessions for Forms Administration accounts; authentication tokens appearing in external server logs or DNS queries.

Mitigation and workarounds

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.

Additional resources


Source: This 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