Summary
A stored cross-site scripting vulnerability in OpenEMR's GAD-7 anxiety assessment form allows authenticated clinician users to inject malicious JavaScript into assessment data.
When other users view the compromised form, the attacker-controlled script executes in their browser, enabling session hijacking, account takeover, and potential privilege escalation to administrator.
Affected context
The vulnerability occurs within OpenEMR's GAD-7 anxiety assessment workflow, where clinician-entered data is later rendered to other users in the web interface.
It is exposed when:
- Clinician users can enter or update assessment fields that are later displayed to other users (e.g., clinicians, staff, or administrators).
- The stored content is rendered in HTML responses without adequate output encoding or contextual escaping.
- Browsers execute embedded scripts in the context of the OpenEMR domain, inheriting the victim user's authenticated session.
Exploit preconditions
- Attack surface: Web-based user interface for GAD-7 anxiety assessments in OpenEMR.
- Required access: Authenticated account with clinician-level privileges capable of creating or editing GAD-7 assessment entries.
- Trigger point: Any user (including administrators) viewing the compromised GAD-7 assessment via the standard OpenEMR UI.
- Why exploitation is possible: User-supplied assessment data is stored server-side and later rendered into HTML without proper context-aware output encoding, allowing attacker-injected JavaScript to execute in the victim's browser.
Why this happens
The underlying issue aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
The application stores clinician-supplied data from the GAD-7 form and later embeds this data into HTML responses without sufficient output encoding or HTML/JavaScript context escaping.
Because the data is treated as display-ready content rather than untrusted input, an attacker can inject HTML/JavaScript payloads that the browser interprets as active script.
This pattern reflects a classic stored XSS bug: persistent untrusted input is rendered as part of the page's DOM in a script-capable context.
Potential impact
- Attacker-controlled JavaScript may run in the context of other users' authenticated sessions.
- Session hijacking could allow takeover of clinician, staff, or administrator accounts.
- Privilege escalation from clinician to administrator may occur if an admin views a malicious GAD-7 entry.
- Unauthorized access to sensitive electronic health records and patient data could result from compromised accounts.
- Modification or deletion of medical records and configuration settings is possible via impersonated high-privilege users.
- Further client-side attacks, such as credential harvesting or CSRF abuse, can be orchestrated from the victim's browser.
General mitigation guidance
Effective mitigation centers on context-aware output encoding and strict handling of untrusted data:
- Apply HTML, attribute, or JavaScript context-specific output encoding to all user-supplied fields rendered in the GAD-7 form views and similar templates.
- Treat all stored form data as untrusted, regardless of the user's role, and sanitize or validate it before storage and/or before rendering.
- Use templating engines or view helpers that automatically encode values by default and explicitly mark safe-only, vetted content.
- Avoid directly concatenating user input into HTML, JavaScript, or inline event handlers; separate code from data.
- Consider adopting a Content Security Policy (CSP) to reduce the impact of any remaining script injection vectors.
- Enforce least-privilege principles for roles (e.g., clinicians should not inherently have configuration-level capabilities) to limit the damage if a session is compromised.
How teams detect issues like this
Detecting this class of vulnerability generally involves a combination of static and dynamic approaches:
- Static analysis: Configure SAST tools to flag unencoded variables rendered into HTML templates or views, especially in form/result display logic.
- Code review: During manual review, look for direct insertion of database fields or request parameters into HTML pages, script blocks, or event handlers without encoding helpers.
- Dynamic testing: Use automated or manual web application scanning to submit benign script markers in GAD-7 and similar forms, then verify whether they are executed when viewed.
- Security testing policies: Integrate XSS-focused test cases into CI/CD pipelines, and require security review for new forms or UI features that render stored user input.
- Runtime monitoring: Employ web application firewalls or RASP-like controls configured with rules to detect and possibly block common XSS payload patterns, while being aware of false positives.

