Skip to content

fix(core): allow style attributes in DomSanitizer - #70425

Open
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:style-sanitz
Open

fix(core): allow style attributes in DomSanitizer#70425
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:style-sanitz

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

Modern browsers no longer execute JavaScript from within CSS (e.g., via expression(...) or -moz-binding), eliminating the primary XSS vector associated with inline styles. Because of this, Angular previously removed its internal StyleSanitizer in v14 (PR #43339). This commit aligns DomSanitizer.sanitize(SecurityContext.HTML, ...) with the current security model by adding style to the list of allowed HTML attributes. Safe style attributes will no longer be stripped from HTML output, while still being properly entity-encoded to prevent attribute breakout.

Closes #45270

Modern browsers no longer execute JavaScript from within CSS (e.g., via `expression(...)` or `-moz-binding`), eliminating the primary XSS vector associated with inline styles. Because of this, Angular previously removed its internal `StyleSanitizer` in v14 (PR angular#43339).
This commit aligns `DomSanitizer.sanitize(SecurityContext.HTML, ...)` with the current security model by adding `style` to the list of allowed HTML attributes. Safe `style` attributes will no longer be stripped from HTML output, while still being properly entity-encoded to prevent attribute breakout.

Closes angular#45270
@JeanMeche
JeanMeche requested a review from alan-agius4 August 27, 2026 09:22
@pullapprove
pullapprove Bot requested a review from josephperrott August 27, 2026 09:22
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Aug 27, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 27, 2026

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: fw-security

@JeanMeche

Copy link
Copy Markdown
Member Author

Presubmit failure is legit. A dialog with some custom HTML (with a style attribute) now gets styled.

Marking this as a breaking change.

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

Labels

area: core Issues related to the framework runtime breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DomSanitizer should keep style attributes in HTML but sanitize them if needed

2 participants