fix(security): harden prop and URL validation against bypasses - #373
Merged
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.
Markdown-authored innerHTML / dangerouslySetInnerHTML / textContent props reached Vue h(), React createElement, Svelte spreads and the Angular DOM renderer verbatim, injecting raw HTML even when comark/plugins/security was enabled (validateProp only rejected on*, srcdoc and formaction). - Add innerhtml, dangerouslysetinnerhtml and textcontent to unsafeAttributes so the security plugin strips them at parse time - resolveAttributes() (the shared prop-resolution point for all four framework renderers) now drops those keys unconditionally — raw HTML already has its own explicit path via the html plugin - Remove the Angular renderer's dedicated el.innerHTML assignment
The as prop makes framework renderers resolve a different component
than the element's own tag, but the plugin only checked element[0]
against blockedTags/allowedTags. [x]{as="AdminPanel"} instantiated
any resolvable app component even under a strict allowedTags list.
Strip as when its value names a blocked or not-allowed tag; the
element then falls back to its own (already validated) tag.
Entities were stripped instead of decoded, so javascript:alert(1) became javascriptalert(1), failed URL parsing, and passed as a 'relative' URL — while browsers entity-decode the attribute back into a live javascript: URL. Decode entities (numeric, hex, and the scheme-relevant named ones) until stable before the protocol checks, and stop throwing on malformed percent-encoding.
…ts by origin Two allowlist bypasses in validateUrl: - //evil.com and \\evil.com forms failed new URL() without a base and were returned as always-allowed 'relative' URLs, skipping the protocol and prefix checks entirely. Resolve against a fixed dummy origin — only inputs that stay on it are genuinely relative. - allowedLinkPrefixes: ['https://myapp.com'] matched https://myapp.com.evil.com via raw startsWith. Absolute-URL prefixes now compare parsed origin plus a path-segment boundary.
Renderers JSON-decode :binding values at render time, but validateProp inspected the raw pre-resolution string. A JSON-quoted value like '"javascript:alert(1)"' failed URL parsing, was classified as a relative URL, and became a live javascript: href after the renderer's JSON.parse — bypassing the plugin's protocol block and prefix allowlists. Decode the binding's JSON string before running URL validation, and keep the original value when safe so the binding still resolves.
…r time The security plugin validates :href/:src bindings at parse time, but a dot-path binding like :href="frontmatter.home" only shows the literal path — frontmatter data it resolves to was never checked, letting javascript: URLs through the documented sanitizer. resolveAttributes() now applies the hard-floor unsafe-scheme check to binding-resolved href/src/xlink:href values at render time, independent of the security plugin. Literal attributes are untouched: their parse-time validation remains the plugin's job.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📄 Docs previewThis pull request touches 1 documentation page. Changed or added |
Contributor
Documentation previews |
comark
@comark/angular
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
Contributor
✅ Bundle snapshot updatedCommitted the new snapshot as 4975780, verified by re-running the bundle check against it. GitHub suppresses the events a workflow commit would normally raise, so the Produced by this run. |
farnabaz
approved these changes
Aug 25, 2026
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
Stacks on #371's base (branch
fix/html-attribute-escaping, PR pending). Rejects markdown-authoredinnerHTML/dangerouslySetInnerHTML/textContentprops, holds theasprop to the same tag filters, and closes four URL-validation bypasses: entity stripping, scheme-relative//hostURLs, lookalike-host prefix matches, and JSON-quoted or dot-path bindings validated only in their unresolved form.Why
A security scan showed the plugin's documented guarantees were defeatable:
::div{innerHTML="<img …>"}executed in all four framework renderers even with the sanitizer enabled,javascript:alert(1)survived because entities were stripped instead of decoded, and:href="frontmatter.home"could resolve tojavascript:after parse-time checks had run. The render-time hard floor inresolveAttributes()is intentionally unconditional (blocksjavascript:/data:text/htmlin binding-resolvedhref/srceven without the plugin) — literal attributes keep their current behavior and remain the plugin's responsibility.🤖 Prepared by an AI agent (OpenCode) from a security-audit findings list; commits are signed by the repository owner's key.