fix(multiple): harden extendStyles and trusted-types against prototype pollution and DOM clobbering#33410
Open
arturovt wants to merge 1 commit into
Open
fix(multiple): harden extendStyles and trusted-types against prototype pollution and DOM clobbering#33410arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
…e pollution and DOM clobbering Replace `source.hasOwnProperty(key)` with `Object.hasOwn(source, key)` in the two `extendStyles` helpers (drag-drop/styling and flexible-connected-position-strategy). Calling hasOwnProperty as an instance method is unsafe when Object.prototype itself has been polluted — Object.hasOwn has no such exposure. Wrap `trustedTypes.createPolicy()` in a try/catch in trusted-types.ts. The call can throw if window.trustedTypes was DOM-clobbered with an HTML element before Angular bootstrapped, which previously caused an unhandled exception and silently skipped policy creation. The catch falls back to null, preserving the existing DomSanitizer sanitization path in _setInnerHtml. Add "es2022.object" to the root tsconfig lib to make Object.hasOwn available; the target was already es2022 so this aligns the type surface without broadening it further.
crisbeto
reviewed
Jun 17, 2026
| // window.trustedTypes was DOM-clobbered with an HTML element before | ||
| // Angular bootstrapped. Either way, null means trustedHTMLFromString | ||
| // falls back to plain strings — sanitization in _setInnerHtml still runs. | ||
| policy = null; |
Member
There was a problem hiding this comment.
This seems a bit pointless since the policy won't be created if there's an error.
| } | ||
|
|
||
| /** Shallow-extends a stylesheet object with another stylesheet object. */ | ||
| function extendStyles( |
Member
There was a problem hiding this comment.
We only call this internally with a pre-defined set of values so this isn't necessary.
| ) { | ||
| for (let key in source) { | ||
| if (source.hasOwnProperty(key)) { | ||
| if (Object.hasOwn(source, key)) { |
Member
There was a problem hiding this comment.
We only call this internally with a pre-defined set of values so this isn't necessary.
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.
Replace
source.hasOwnProperty(key)withObject.hasOwn(source, key)in the twoextendStyleshelpers (drag-drop/styling and flexible-connected-position-strategy). Calling hasOwnProperty as an instance method is unsafe when Object.prototype itself has been polluted — Object.hasOwn has no such exposure.Wrap
trustedTypes.createPolicy()in a try/catch in trusted-types.ts. The call can throw if window.trustedTypes was DOM-clobbered with an HTML element before Angular bootstrapped, which previously caused an unhandled exception and silently skipped policy creation. The catch falls back to null, preserving the existing DomSanitizer sanitization path in _setInnerHtml.Add "es2022.object" to the root tsconfig lib to make Object.hasOwn available; the target was already es2022 so this aligns the type surface without broadening it further.