Summary
OpenEMR versions prior to 8.0.0.3 contain a stored cross-site scripting vulnerability in the Eye Exam encounter form display logic.
Authenticated users with the Notes - my encounters role can inject arbitrary JavaScript into form answers, which is later executed in the browser of any user with the same role when viewing encounter pages or visit history.
Affected context
The vulnerability occurs in the context of Eye Exam forms within patient encounters in OpenEMR deployments prior to 8.0.0.3.
It specifically affects workflows where:
- Users with the
Notes - my encountersrole can create or update Eye Exam forms. - Form answers are later rendered on encounter pages and in the visit history without proper output encoding.
- Multiple staff members share the same form role and routinely view those encounter details.
The issue is limited to authenticated usage but can affect a broad set of users who rely on the Eye Exam module for clinical documentation.
Exploit preconditions
- Attack surface: Web interface of OpenEMR (Eye Exam encounter forms).
- Required access: Authenticated account with at least the
Notes - my encountersrole, allowing creation or modification of Eye Exam form entries. - Trigger point: Viewing patient encounter pages or visit history that render malicious form answers.
- Why exploitation is possible: User-supplied form answers are stored in the database and later inserted into HTML responses without the necessary context-aware output encoding or sanitization, enabling persistent execution of injected JavaScript in victims' browsers.
Why this happens
This vulnerability stems from improper neutralization of user-controlled content when rendering Eye Exam form answers.
The application stores raw form inputs from users and later embeds them directly into HTML pages without applying context-appropriate output encoding (e.g., HTML- or JavaScript-encoding) or robust server-side sanitization.
This behavior aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where dynamically generated pages fail to treat stored user input as untrusted, allowing active script content to be interpreted by the browser.
Potential impact
- Compromise of sessions or login context for users with the affected role, including potential session token theft via malicious scripts.
- Unauthorized access to sensitive medical information visible to compromised sessions, subject to the role's privileges.
- Execution of arbitrary JavaScript in the victim's browser, enabling UI redressing, data exfiltration, or manipulation of clinical records within the user's permissions.
- Creation of self-propagating payloads that automatically inject further malicious content into other encounter records viewed by affected users.
- Undermining integrity and trustworthiness of patient encounter documentation, particularly in Eye Exam records.
General mitigation guidance
Effective mitigation focuses on treating all stored form content as untrusted and enforcing strict output encoding at every render point:
- Apply context-aware output encoding on all form answers before inserting them into HTML pages, ensuring that characters with special meaning in HTML and JavaScript are safely encoded.
- Avoid building HTML fragments by concatenating raw user input; instead, use templating systems and helpers that encode by default.
- Introduce server-side validation and normalization that rejects or neutralizes input containing potentially executable markup, while accommodating legitimate clinical free-text where necessary.
- Limit the privileges associated with roles that can submit or edit encounter forms (including
Notes - my encounters) according to least privilege principles, reducing blast radius if abuse occurs. - Consider enforcing a Content Security Policy (CSP) that disallows inline JavaScript and restricts script sources, to reduce exploitability of any remaining XSS bugs.
- Maintain a secure development standard where new form modules and display functions are required to pass XSS-focused code review and automated checks before deployment.
How teams detect issues like this
Detection can combine code-centric and behavior-centric approaches:
- Static analysis: Configure linters or SAST tools to flag direct insertion of user-controlled variables into HTML responses, templates, or echo statements without passing through a known encoding or sanitization function.
- Code review signals: During review of encounter-related modules and forms, look for patterns where:
- Database fields are rendered into HTML without escaping.
- Custom HTML is assembled via string concatenation or
echostatements that include request parameters or stored user content. - Template and view audits: Perform targeted inspection of all form display functions, verifying that templating helpers or output routines always apply context-aware encoding for text fields.
- Runtime monitoring: Use application logs, WAF rules, or security monitoring to detect anomalous form submissions that contain script tags, event handlers, or suspicious JavaScript-like substrings.
- Testing and QA: Incorporate XSS payload checks into automated functional tests for new or modified encounter forms, ensuring that rendered content appears as inert text and not executable script.

