Summary
SunEditor before 3.4.0 has a stored cross-site scripting flaw in the bookmark list of its anchor-link modal. An attacker who can save crafted, HTML-encoded text in an editor heading may cause JavaScript to run in a victim's browser when the victim opens the modal and types # in the URL field.
Affected context
The issue occurs in SunEditor's ModalAnchorEditor bookmark-list creation logic. Header text from h1–h6 elements is entity-decoded and then inserted into the list using innerHTML without escaping. The described behavior affects versions before 3.4.0 when an attacker can store crafted heading content and a victim triggers the bookmark-list rendering flow.
Exploit preconditions
- Attack surface: SunEditor content and the anchor-link modal in a victim's browser
- Required access: Ability to add or modify content that will be stored as an editor heading
- Trigger point: A victim opens the link modal and types
#in the URL input - Why exploitation is possible: Entity-decoded heading text is inserted into the DOM through
innerHTMLwithout escaping
Why this happens
The application treats decoded heading text as HTML rather than as plain text when building the bookmark list. This unsafe output handling allows attacker-controlled markup to be interpreted by the browser, mapping to CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Potential impact
- JavaScript may execute in the victim's browser in the context of the editor page.
- An attacker could potentially access information available to that page or perform actions as the victim, subject to the victim's permissions and browser controls.
- The issue could undermine trust in shared or collaborative editor content.
General mitigation guidance
Defensive patterns focus on keeping untrusted content as text throughout rendering:
- Prefer text-oriented DOM APIs such as
textContentfor heading labels. - If HTML rendering is necessary, apply context-appropriate output encoding or a well-maintained HTML sanitizer before insertion.
- Avoid decoding entities and then passing the result to HTML-parsing sinks such as
innerHTML. - Limit who can create or modify stored editor content, and apply appropriate authorization to those workflows.
- Use browser security policies, such as a restrictive Content Security Policy, as defense in depth rather than as a replacement for safe rendering.
How teams detect issues like this
- Use static analysis to identify flows from editor content or decoded entities into
innerHTMLand similar HTML-parsing APIs. - Review DOM-building code for unsafe sinks, especially where stored content is used to create modal or navigation UI.
- Add tests that verify heading text is rendered as text, not interpreted as markup, across relevant modal interactions.
- Enforce code-review or CI policies that restrict unsafe HTML insertion or require approved sanitization.

