Visitar URL original
fix(platform-browser): don't write styles to a clobbered style property by rootvector2 路 Pull Request #71255 路 angular/angular 路 GitHub
Skip to content

fix(platform-browser): don't write styles to a clobbered style property - #71255

Closed
rootvector2 wants to merge 1 commit into
angular:mainfrom
rootvector2:clobbered-style-property
Closed

rootvector2 wants to merge 1 commit into
angular:mainfrom
rootvector2:clobbered-style-property

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #70021

HTMLFormElement is [LegacyOverrideBuiltIns], so a form-associated control named style is exposed as an own property of the <form> and shadows the inherited style accessor. setStyle() and removeStyle() read el.style and then write the style name onto it, so on such a form the write lands on the control rather than on a CSSStyleDeclaration.

All styling goes through those two methods, and with [ngStyle], [style] or [style.<prop>] the style name comes from the bound value, which makes innerHTML and outerHTML HTML sinks:

<form [ngStyle]="styles"><button name="style" type="button">Save</button></form>
styles = {innerHTML: '<img src="x" onerror="alert(document.domain)">'};

In Chrome 154 form.style is the <button>, the markup is written into it and the <img> is live in the document. removeStyle() follows the same path and clears the control's innerHTML instead.

What is the new behavior?

Both methods return early when el.style is not a style declaration. The form was never styled on this path to begin with, so nothing that works today changes, and elements that do have a declaration are untouched.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

The two tests fail on main in test_web_chromium and test_web_firefox (Expected '<img src="#">' to be '' and Expected '' to be 'Save') and pass with the change. The node target skips this suite, and domino does not implement the form named getter, so the clobbering is browser-only.

`HTMLFormElement` is `[LegacyOverrideBuiltIns]`, so a form-associated control
named `style` is exposed as an own property of the `<form>` and shadows the
inherited `style` accessor. `setStyle()` and `removeStyle()` read `el.style` and
write the style name onto it, so on such a form the write lands on the control
instead of a `CSSStyleDeclaration`, which turns `innerHTML` and `outerHTML` into
HTML sinks for style names that come from a bound value.

Bail out when `el.style` is not a style declaration. The form was never styled
on this path, so elements with a real declaration keep behaving the same.

Fixes angular#70021
@pullapprove
pullapprove Bot requested a review from JeanMeche October 8, 2026 11:55
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Oct 8, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 8, 2026
@SkyZeroZx

Copy link
Copy Markdown
Contributor

This is a duplicate of #70022

@JeanMeche JeanMeche closed this Oct 8, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants