Skip to content

fix(multiple): harden extendStyles and trusted-types against prototype pollution and DOM clobbering#33410

Open
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/multiple_vulners
Open

fix(multiple): harden extendStyles and trusted-types against prototype pollution and DOM clobbering#33410
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/multiple_vulners

Conversation

@arturovt

Copy link
Copy Markdown
Contributor

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.

…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.
@pullapprove pullapprove Bot requested a review from devversion June 17, 2026 10:13
// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We only call this internally with a pre-defined set of values so this isn't necessary.

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.

2 participants