Skip to content

fix: enforce single-property validation in CSSStyleDeclaration.setProperty - #60

Draft
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/css-property-injection
Draft

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/css-property-injection

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

Summary

Fixes CSS property injection in CSSStyleDeclaration.prototype.setProperty where values containing both ; and the substring data: bypassed the semicolon guard (if (value.includes(";") && !value.includes("data:")) return;), causing parseStyles(property + ":" + value) to parse and serialize multiple CSS declarations into the style attribute.

Changes

  • Replaced the substring data: check and multi-property parseStyles loop in CSSStyleDeclaration.prototype.setProperty with CSS Syntax Level 3–aligned single-declaration validation (isValidPropertyName and isValidStyleValue):
    • Rejects top-level ; (while still allowing semicolons inside valid strings, comments, balanced parentheses/brackets, and url(...) tokens such as url(data:image/png;base64,...)).
    • Rejects unbalanced or mismatched (), [], {} delimiters, unclosed quotes or comments, unescaped newlines in strings (<bad-string-token>), malformed unquoted url(...) tokens (where /* is not a comment), escaped function names (e.g. \75 rl(...)), trailing/invalid backslashes, and !important inside the value.
    • Validates the property name and writes only styles.property[property].
  • Added comprehensive unit tests in test/domino.js (styleSetPropertyValidation) covering both rejected injection/parser-differential payloads and legitimate CSS values.

@JeanMeche
JeanMeche force-pushed the fix/css-property-injection branch from 046c175 to 0f37c66 Compare November 24, 2026 22:27
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