Summary
OpenEMR has a stored cross-site scripting flaw in which a portal patient can submit an encounterForm value that is later rendered unsanitized in an iframe source. If staff view the affected document, a crafted javascript: URL may execute in their browser session, potentially exposing protected health information (PHI) and enabling actions through staff or admin endpoints.
Affected context
The issue occurs in the document template rendering path when patient-controlled template_data is stored and later used by DocumentTemplateRender to populate an iframe src. Risk is present when the value is rendered without adequate sanitization or URL scheme validation and a staff member views the affected document. Exploitation may depend on browser behavior and applicable security policies.
Exploit preconditions
- Attack surface: Patient portal submission of encounter form data.
- Required access: Ability to submit the relevant patient-controlled value; staff or admin access is not required to plant it.
- Trigger point: A staff member views a document that renders the stored value in an iframe source.
- Why exploitation is possible: The value may be interpreted as an executable URL when rendered without suitable output encoding and URL scheme restrictions.
Why this happens
The root cause is treating untrusted, stored input as a safe URL when inserting it into an iframe src attribute. Insufficient context-aware output encoding and URL validation can allow a javascript: scheme to execute in the viewer's browser context. This is a stored cross-site scripting weakness mapped to CWE-79: Improper Neutralization of Input During Web Page Generation.
Potential impact
- Malicious script execution in a staff member's browser session could expose PHI available to that session.
- Scripts could access CSRF tokens or other data accessible to the affected page, depending on browser and application controls.
- Unauthorized requests to staff or admin endpoints could be made with the viewer's privileges.
- Compromised sessions could lead to further changes or access within the application.
General mitigation guidance
Defensive patterns focus on preventing untrusted data from becoming executable browser content:
- Use context-aware output encoding for values placed in HTML attributes.
- Validate URLs against an explicit allowlist of permitted schemes and destinations; reject executable schemes.
- Prefer secure-by-default rendering APIs that treat values as data rather than markup or script.
- Minimize trust in patient-submitted content and apply validation at input boundaries as well as output sinks.
- Apply least privilege to staff roles and use appropriate browser and application security policies as additional defense in depth.
How teams detect issues like this
- Use static analysis to identify untrusted values flowing into iframe
srcattributes and other HTML or URL sinks. - Review document template rendering code for missing context-aware encoding, URL scheme validation, or unsafe HTML construction.
- Add tests and policy checks that reject executable URL schemes in user-controlled values.
- Monitor security reviews and automated code analysis for stored XSS patterns across patient-submitted content and staff-facing views.

