Summary
A cross-site scripting vulnerability in league/commonmark allows specially formatted Markdown attributes to bypass filtering of event-handler attributes and unsafe URLs. When untrusted Markdown is rendered with the AttributesExtension enabled, injected JavaScript may execute in a viewer's browser.
Affected context
The issue occurs in applications using league/commonmark versions within the affected range and enabling the AttributesExtension while processing Markdown from untrusted or insufficiently trusted sources. It becomes risky when rendered output is delivered as HTML without an additional security boundary that prevents browser interpretation of injected event handlers or unsafe URI schemes.
Exploit preconditions
- Attack surface: Markdown-to-HTML rendering through league/commonmark
- Required access: Ability to submit or influence Markdown content that the application renders
- Trigger point: Attribute parsing and filtering performed by the AttributesExtension
- Why exploitation is possible: A form-feed-prefixed attribute name can bypass application-level checks while remaining interpretable by browsers as an event-handler attribute or unsafe URI attribute
Why this happens
The vulnerability results from inconsistent normalization between PHP-side filtering and browser-side HTML parsing. The filtering logic relies on trim() and checks attribute names and values before output, but a leading U+000C form-feed character is not removed by that normalization path. The resulting attribute can therefore bypass checks intended to block event handlers and unsafe URL schemes, while the browser treats it as a genuine attribute. This behavior maps to CWE-79: Improper Neutralization of Input During Web Page Generation, because attacker-controlled Markdown is emitted into HTML without reliably neutralizing executable content.
Potential impact
- An attacker may execute JavaScript in the context of a viewer's browser.
- Session information or page content could be exposed.
- User actions may be performed through the affected application.
- Rendered pages could be modified or used for phishing.
- Unsafe
javascript:links may bypass application-level URL restrictions.
General mitigation guidance
Mitigation generally focuses on consistent input normalization, strict output encoding, and reducing trust in user-supplied Markdown.
Common defensive patterns include:
- Use a parser configuration or component behavior that does not permit raw event-handler attributes or unsafe URI schemes.
- Normalize Unicode and control characters before attribute validation, using the same semantics expected by the HTML consumer.
- Apply context-appropriate HTML sanitization after rendering, with an allowlist for permitted elements, attributes, and URL schemes.
- Treat rendered Markdown as untrusted content and isolate it where appropriate using browser security controls such as a restrictive Content Security Policy.
- Avoid granting rendered-content processes unnecessary access to sensitive application data or privileged browser capabilities.
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis and code review checks for inconsistent trimming, Unicode normalization, or validation of HTML attribute names.
- Tests covering control characters and alternate whitespace forms at attribute boundaries.
- Security-focused rendering tests that verify event-handler attributes and unsafe URI schemes cannot reach output.
- Dependency and configuration policy checks requiring safe Markdown rendering settings and explicit sanitization boundaries.
- Runtime monitoring for unexpected event-handler attributes, unsafe URI schemes, or suspicious script execution in rendered-content responses.

