fix(view/ssr): guard bq-bind attribute values against XSS sinks - #184
Merged
Conversation
handleBind wrote any runtime value straight to setAttribute with no protocol or attribute-name validation, so tainted context data could inject javascript: URLs (href/src), inline handlers (bq-bind:onclick), or a full HTML document via iframe srcdoc. The SSR renderers blocked on* and a fixed URL list but also let srcdoc through, where attribute encoding is no defense because the browser entity-decodes and parses it. A shared guard (src/security/bind-guard.ts) now decides per attribute: - on* names are never written (client warns) - srcdoc is sanitized as an HTML sink (sanitizeHtml / sanitizeHtmlForSSR) - URL attributes (href, src, xlink:href, formaction, action, poster, background, cite, data) and srcset drop values with dangerous protocols Used by the client directive, the pure SSR renderer and the legacy DOM-backed SSR renderer. Fixes #164 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Jonas Pfalzgraf <[email protected]>
- ssr-stable.test.ts: the dev merge concatenated the #164/#176 EOF test appends and dropped the #164 block's closing braces (type-check syntax error). - render.ts: the merge with #167 (which routed evaluateSSR through evaluateExpression) left the isComputed/isSignal/Signal import unused. Co-Authored-By: Claude Fable 5 <[email protected]>
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.
Summary
Fixes #164 (High).
bq-bindwrote runtime data to any attribute with no validation:<a bq-bind:href="link">withlink = "javascript:alert(document.cookie)"→ clickable script execution<div bq-bind:onclick="h">→ registered a live inline handler<iframe bq-bind:srcdoc="msg">(client and both SSR backends) → attribute-encoding is decoded by the browser and parsed as a full HTML document → script executionFix
New shared guard
src/security/bind-guard.ts(checkBoundAttribute), reused by all three sinks (client directive, pure SSR renderer, legacy DOM SSR renderer):on*names: never written; client logs a warningsrcdoc: treated as an HTML sink — sanitized viasanitizeHtml(client) /sanitizeHtmlForSSR(SSR)href",src,xlink:href,formaction,action,poster,background,cite,data) +srcset`: values with dangerous protocols (after control-char/zero-width normalization) are droppedBoolean/null semantics of
bq-bindare unchanged; safe values pass through as before.Verification
tsc --noEmit+ eslint clean.🤖 Generated with Claude Code