Skip to content

fix(security): harden prop and URL validation against bypasses - #373

Open
atinux wants to merge 10 commits into
fix/html-attribute-escapingfrom
fix/security-prop-url-validation
Open

fix(security): harden prop and URL validation against bypasses#373
atinux wants to merge 10 commits into
fix/html-attribute-escapingfrom
fix/security-prop-url-validation

Conversation

@atinux

@atinux atinux commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What

Stacks on #371's base (branch fix/html-attribute-escaping, PR pending). Rejects markdown-authored innerHTML/dangerouslySetInnerHTML/textContent props, holds the as prop to the same tag filters, and closes four URL-validation bypasses: entity stripping, scheme-relative //host URLs, 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&#58;alert(1) survived because entities were stripped instead of decoded, and :href="frontmatter.home" could resolve to javascript: after parse-time checks had run. The render-time hard floor in resolveAttributes() is intentionally unconditional (blocks javascript:/data:text/html in binding-resolved href/src even 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.

atinux added 7 commits August 20, 2026 20:30
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&#58;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.
@atinux
atinux requested a review from farnabaz as a code owner August 20, 2026 18:53
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview Aug 21, 2026 1:33pm
comark-json-render Ready Ready Preview Aug 21, 2026 1:33pm
comark-nextjs Ready Ready Preview Aug 21, 2026 1:33pm
comark-nuxt Ready Ready Preview Aug 21, 2026 1:33pm
comark-svelte Ready Ready Preview Aug 21, 2026 1:33pm
comark-sveltekit Ready Ready Preview Aug 21, 2026 1:33pm
comark-twoslash Ready Ready Preview Aug 21, 2026 1:33pm
comark-vue Ready Ready Preview Aug 21, 2026 1:33pm

@github-actions

Copy link
Copy Markdown
Contributor

📄 Docs preview

This pull request touches 1 documentation page.

Changed or added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant