Summary
OpenEMR's CCDA/CCD preview stylesheets can copy attacker-controlled attributes into preview HTML without consistently sanitizing them. An authenticated user who can upload a crafted document may cause script to run in a clinician's session when the document is previewed.
Affected context
The issue occurs in the CCDA/CCD preview rendering path. The cda.xsl stylesheet copies certain event-handler attributes whose values can evade a character denylist, while ccd.xsl copies table-cell attributes into preview HTML without sanitization. Risk arises when an uploaded document containing such attributes is rendered for a clinician.
Exploit preconditions
- Attack surface: CCDA/CCD document upload and preview functionality
- Required access: An authenticated account permitted to upload a crafted document
- Trigger point: A clinician or other user previews the uploaded document
- Why exploitation is possible: Document attributes can be copied into rendered HTML without effective sanitization, allowing browser event handlers to execute script
Why this happens
This is a cross-site scripting flaw mapped to CWE-79: Improper Neutralization of Input During Web Page Generation. The preview stylesheets copy attacker-controlled attributes into HTML without reliably removing or encoding values for their output context. A character denylist is insufficient when other attribute values or forms can still produce executable event handlers.
Potential impact
- Script could run in a clinician's browser under the application's origin
- An attacker may be able to access or alter information available to the affected user
- The script could perform actions with the clinician's session privileges
- Trust in rendered clinical documents and preview content may be undermined
General mitigation guidance
Mitigation generally focuses on preventing untrusted document data from becoming executable HTML.
Common defensive patterns include:
- Avoid copying arbitrary input attributes into rendered markup; allow only explicitly required attributes
- Apply context-appropriate output encoding and use trusted HTML sanitization where markup is required
- Prefer safe, structured rendering that treats document values as text rather than active markup
- Validate uploaded documents against restrictive schemas, while treating validation as an additional control rather than a substitute for output safety
- Limit application privileges and session capabilities to reduce the consequences of client-side script execution
How teams detect issues like this
Useful detection approaches include:
- Static analysis for stylesheet transformations that copy untrusted attributes into HTML output
- Code review of denylist-based sanitization and event-handler attributes such as
onmouseover,onclick, andonfocus - Tests that render hostile document attributes and verify they are removed or safely encoded
- Policies that restrict dynamic HTML generation and require approved sanitization for untrusted content
Automated code review tools may help identify risky attribute-copying patterns.

