fix(comark): prevent HTML attribute injection in the stringifier - #372
Open
atinux wants to merge 4 commits into
Open
fix(comark): prevent HTML attribute injection in the stringifier#372atinux wants to merge 4 commits into
atinux wants to merge 4 commits into
Conversation
Attribute values were interpolated into key="value" with no escaping, so a double quote in any attribute value (raw HTML, component props, fence info strings, image alt text) terminated the attribute early and injected attacker-chosen attributes such as onmouseover handlers into the rendered HTML. This bypassed comark/plugins/security, which sanitizes the AST but cannot prevent quote breakout at serialization. - Escape &, ", < and > in all attribute values emitted by htmlAttributes() - Serialize object values as entity-escaped JSON (backslash escaping is not valid inside HTML attribute values) - Drop attribute names outside the safe HTML name charset - Update SPEC expectations that encoded the broken output
Handler maps are plain object literals, so a markdown component named `constructor` resolved Object.prototype.constructor through the prototype chain and was invoked as the node handler, emitting child text without escaping. Names like `__proto__` or `valueOf` instead threw and aborted the whole render. Look up user and default handlers with Object.hasOwn so only real handlers match.
Footnote labels were interpolated raw into href="#fn-<label>" and id="fnref-<label>". A label containing a double quote broke out of the attribute when rendered to HTML, injecting event-handler attributes. Encode any character outside [a-zA-Z0-9_-] as -<hex>- so references and definitions still match and the emitted values stay inert.
The fence info language regex admitted quotes and angle brackets even though the value lands in the language attribute and language-* class of the rendered HTML. Stop the language at those characters; any remainder still parses as meta.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Escapes
&,",<and>in every attribute value emitted byhtmlAttributes(), drops attribute names outside the safe HTML charset, looks up node handlers withObject.hasOwn, sanitizes footnote labels used inhref/id, and stops code-fence languages at quotes/angle brackets.Why
A security scan found that any attribute value containing a double quote (raw HTML, component props, fence info strings, image alt text, footnote labels) broke out of
key="value"at serialization time and injected attacker-chosen attributes such asonmouseoverinto the rendered HTML — even withcomark/plugins/securityenabled, because that plugin sanitizes the AST but cannot fix quote breakout at the string sink. Output encoding belongs in the serializer (per-renderer), since the same AST feeds the DOM-based Vue/React/Svelte/Angular renderers where escaping in the tree would double-encode; a plugin-side-only fix was considered and rejected for that reason. Also fixes a prototype-chain lookup where a::constructorcomponent resolvedObject.prototype.constructoras its handler (XSS, and__proto__/valueOfaborted the render).🤖 Prepared by an AI agent (OpenCode) from a security-audit findings list; commits are signed by the repository owner's key.