
Cloud Vulnerability DB
A community-led vulnerabilities database
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) (GitHub Advisory, Github Advisory).
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/JavaScript sanitization — bypassing the tag check that exists only for templates created or edited through the editor UI. When any Forms Administration user subsequently views the template via mode=editor_render_html, the content is fetched and passed directly to renderEditorHtml() without sanitization, allowing event-handler attributes (e.g., onerror, onload) to execute. The fix introduced DocumentTemplateService::purifyTemplateContent() using HTMLPurifier, applied at both write and render time (GitHub Advisory, Fix Commit).
Successful exploitation enables persistent JavaScript execution in the browser sessions of other Forms Administration users who view the malicious template, enabling session hijacking, credential theft, and unauthorized actions performed on behalf of those administrators. Because OpenEMR handles sensitive protected health information (PHI), a compromised administrative session could expose patient records, facilitate further privilege escalation within the application, or be used to tamper with clinical data. Availability is not directly impacted, but confidentiality and integrity of both the application and patient data are at risk (GitHub Advisory, Github Advisory).
A proof-of-concept (PoC) script (PLT-2026-05-01.py) that automates template upload and provides the trigger URL is referenced in the official advisory, and NVD's SSVC assessment classifies exploitation status as "poc" (GitHub Advisory). However, there is no current evidence of in-the-wild exploitation or threat actor attribution. The EPSS score is approximately 0.171% (7th percentile), indicating a low near-term exploitation probability. The vulnerability is not listed in the CISA KEV catalog. Exploitation requires authenticated access with Forms Administration privileges, limiting the attacker pool (Github Advisory).
<img src=x onerror=alert(document.cookie)> or a more sophisticated payload to exfiltrate session cookies to an attacker-controlled server.POST request to /portal/import_template.php with the malicious file in the template_files[] parameter. The file content is stored without sanitization via DocumentTemplateService.uploadTemplate().docid assigned to the uploaded template from the application response or by querying the template list.http://<host>:<port>/portal/import_template.php?mode=editor_render_html&docid=<template_id>. The stored payload executes in their browser context./portal/import_template.php with HTML file uploads containing script-related content./portal/import_template.php with template_files[] parameters followed by GET requests to the same endpoint with mode=editor_render_html; repeated access to the editor_render_html mode for a specific docid by multiple user accounts.<script>, onerror=, onload=, or javascript: strings.document_templates database table with HTML content containing event-handler attributes or JavaScript URIs (GitHub Advisory).The primary remediation is to upgrade OpenEMR to version 8.3.0 or later, which introduces HTMLPurifier-based sanitization (DocumentTemplateService::purifyTemplateContent()) applied at both template write and render time (OpenEMR Release, Fix Commit). As interim mitigations: restrict Forms Administration permissions to the minimum number of trusted users; implement Content Security Policy (CSP) headers to limit inline script execution in the HTML editor; and audit existing uploaded templates for malicious content. No official workaround short of upgrading has been provided by the vendor.
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."