Summary
A stored cross-site scripting vulnerability in OpenEMR's CCDA document preview allows attacker-controlled JavaScript to execute in a clinician's browser when a malicious CCDA document is viewed.
An attacker who can upload or send a crafted CCDA document can leverage insufficient sanitization of linkHtml elements in the XSL stylesheet to inject script-bearing attributes such as href="javascript:..." and event handlers.
Affected context
The issue occurs in OpenEMR instances that process and render CCDA documents using the vulnerable XSL stylesheet.
It becomes relevant when:
- Clinicians or staff preview CCDA documents through the OpenEMR interface
- CCDA content can originate from external parties, external systems, or untrusted sources
- The rendering pipeline transforms CCDA narrative content, including
linkHtmlelements, into HTML for display without comprehensive sanitization
Under these conditions, malicious markup embedded in CCDA linkHtml elements can be reflected into the clinician's browser as active script.
Exploit preconditions
- Attack surface: Web application interface used to preview CCDA documents within OpenEMR.
- Required access: Ability to upload, import, or otherwise provide a CCDA document that will be stored and later previewed by a clinician or staff member.
- User interaction: A clinician or staff member must open or preview the malicious CCDA document in the application UI.
- Trigger point: Rendering of CCDA narrative content where
linkHtmlelements are transformed into HTML without proper attribute sanitization. - Why exploitation is possible: The XSL stylesheet sanitizes attributes for most narrative elements but omits equivalent checks for
linkHtml, allowingjavascript:URLs and event handler attributes to pass through to the final HTML.
Why this happens
The vulnerability stems from incomplete output encoding and sanitization in the transformation pipeline that converts CCDA content into HTML.
Specifically, the XSL stylesheet responsible for rendering CCDA narrative elements applies attribute sanitization broadly but fails to enforce it for the linkHtml element.
As a result, attacker-controlled attributes such as href="javascript:..." or inline event handlers are inserted directly into the generated HTML.
This behavior maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where untrusted data is included in the page without appropriate escaping or filtering at the point of output.
Potential impact
- Execution of arbitrary JavaScript in a clinician's authenticated browser session.
- Theft of session-related data accessible to scripts (e.g., sensitive page content, form data).
- Unauthorized actions performed on behalf of the clinician within OpenEMR using their privileges.
- Manipulation or exfiltration of protected health information (PHI) visible in the interface.
- Phishing-style UI manipulation within the application to trick users into dangerous actions.
General mitigation guidance
Mitigation focuses on robust output encoding and consistent sanitization across all transformation paths from CCDA to HTML:
- Ensure that all CCDA narrative elements, including
linkHtml, undergo the same strict attribute validation and filtering in the XSL transformation. - Disallow dangerous URL schemes such as
javascript:and restrict hyperlinks to a vetted allowlist of protocols (e.g.,https,http,mailtowhere appropriate). - Strip or neutralize event handler attributes (e.g.,
onclick,onload) and other scriptable attributes before they reach the browser. - Apply context-aware HTML escaping at the final output layer, treating CCDA content as untrusted by default.
- Use well-maintained sanitization libraries designed for converting rich text or XML content to safe HTML rendering contexts.
- Apply a default-deny policy in the transformation logic, permitting only explicitly safe tags and attributes needed for clinical display.
How teams detect issues like this
Effective detection typically combines code-level review with behavioral testing:
- Static analysis and code scanning:
- Search for XSLT templates or rendering code that injects CCDA fields directly into HTML attributes or element bodies without explicit encoding or sanitization.
- Flag transformations involving
linkHtmlor similar narrative elements where attribute filtering is missing or inconsistent with other elements. - Code review signals:
- Look for string concatenation in templates or rendering functions that assemble
href,src, or event attributes from untrusted input. - Review any allowlist or blacklist logic for URL schemes and event attributes to ensure
javascript:and event handlers cannot pass through. - Dynamic and regression testing:
- Include CCDA test fixtures containing controlled payloads in
linkHtmlelements to verify that dangerous attributes are neutralized. - Integrate automated browser-based tests that check rendered CCDA previews for blocked script execution.
- Security policy enforcement:
- Enforce template and view-layer guidelines that mandate context-aware encoding for all user- or externally supplied content.
- Optionally employ Content Security Policy (CSP) in the application to limit the impact of any residual XSS in CCDA or other views.

