fix(security): harden prop and URL validation against bypasses - #373
Open
atinux wants to merge 10 commits into
Open
fix(security): harden prop and URL validation against bypasses#373atinux wants to merge 10 commits into
atinux wants to merge 10 commits into
Conversation
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 |
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.