Summary
OpenEMR prior to 8.0.0.1 contains a cross-site scripting (XSS) vulnerability where unsanitized patient names are rendered into HTML both on the server side and in client-side JavaScript.
An attacker who can control patient demographic data may inject malicious script that executes in a user's browser when viewing prescription print views or portal signing interfaces, potentially leading to session theft or unauthorized actions in the application.
Affected context
The vulnerability occurs wherever patient names from the patient_data table are rendered directly into HTML without proper encoding.
Two main contexts are affected:
- The prescription CSS/HTML print view, which uses raw PHP
echoto output patient names on the server side. - The patient portal signing component (
portal/sign/assets/signer_api.js), which uses jQuery's.html()API to inject patient names into the DOM on the client side.
The issue is exposed when patient demographic data is treated as trusted display content, particularly in workflows involving prescription printing and portal signing.
Exploit preconditions
- Attack surface: Web browser clients accessing OpenEMR features such as prescription print views or the patient portal signing interface.
- Required access: Ability to create or modify patient demographic records (e.g., patient name fields) through any workflow or API that persists data to
patient_data. - Trigger point (server-side sink): A user opens the prescription CSS/HTML print view that renders the compromised patient name via raw PHP output.
- Trigger point (DOM-based sink): A user accesses the portal signing feature where
signer_api.jsinjects the compromised patient name into the DOM using$(...).html(...). - Why exploitation is possible: User-controlled patient name fields are stored persistently and later rendered into HTML without context-appropriate encoding or sanitization, allowing embedded script-like content to be interpreted and executed by the browser.
Why this happens
The root cause is improper output handling of untrusted data from patient_data, specifically patient names, which are used directly in HTML contexts without encoding.
On the server side, PHP outputs patient names using raw echo, placing attacker-controlled strings directly into the prescription print view markup.
On the client side, the portal signing code in signer_api.js uses jQuery's .html() method to inject patient names into the DOM, which interprets embedded HTML and script-capable constructs.
These patterns map to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), where application logic fails to neutralize or encode user-supplied data before rendering it in a browser-executable context.
Potential impact
- Execution of arbitrary JavaScript in the browser of clinicians, administrative staff, or patients viewing affected pages.
- Theft of session cookies or other sensitive browser-stored credentials associated with OpenEMR.
- Unauthorized actions performed in the victim's context (e.g., changing records, initiating workflows, or exfiltrating data), potentially leading to broader compromise of patient data.
- Alteration of on-screen content or user interface elements, which can be abused for phishing or misleading clinical decisions.
- Lateral movement within the application via XSS-driven request forgery or token theft.
General mitigation guidance
Effective mitigation centers on strict output encoding and avoiding unsafe rendering APIs:
- Apply context-appropriate output encoding to all patient-supplied fields, especially names and other demographics, before inserting them into HTML, attributes, or JavaScript.
- On the server side, replace raw
echoof patient data with templating helpers or framework functions that HTML-encode output by default. - On the client side, avoid using
.html()with any untrusted data; prefer.text()or other APIs that treat values as plain text, not markup. - Centralize sanitization/encoding of data originating from
patient_dataso that all paths consuming these fields benefit from consistent protections. - Adopt a "safe-by-default" rendering strategy where templates, components, and APIs require explicit opt-in to render raw HTML, and reserve that for strictly controlled content.
- Limit the privileges and capabilities of browser sessions where possible (e.g., enforcing strict Content Security Policy) to reduce the impact of any residual XSS.
How teams detect issues like this
Detection can leverage both code-level and behavioral techniques:
- Use static analysis to identify uses of raw
echo,print, or equivalent output functions that directly embed database fields, focusing on templates and views that render patient demographics. - Add rules to flag instances of jQuery
.html()or similar DOM APIs (innerHTML,dangerouslySetInnerHTML) when the source is user-controlled data or database fields. - During code review, treat any rendering of
patient_data(especially names, addresses, notes) as suspicious unless it passes through a known encoding/sanitization layer. - Implement automated tests that inject benign but XSS-revealing payload patterns into patient records, then navigate workflows such as prescription printing and portal signing to surface unencoded output.
- Use Content Security Policy report-only mode to gather telemetry on attempted script execution from inline or unexpected sources as a signal of potential XSS.

