tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 30953e6fa75d5030062cfb0a40776dd64aa71158
parent 0af65aacbfd9805032c2d84fea1871bbb394f07b
Author: Frédéric Wang <fwang@igalia.com>
Date:   Tue, 11 Nov 2025 01:08:12 +0000

Bug 1997521 - Update TrustedTypes attribute handling after latest changes to DOM PR. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D270813

Diffstat:
Mdom/base/nsDOMAttributeMap.cpp | 35+++++++++++++----------------------
Dtesting/web-platform/meta/trusted-types/set-attributes-require-trusted-types-no-default-policy-error-cases.html.ini | 24------------------------
2 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/dom/base/nsDOMAttributeMap.cpp b/dom/base/nsDOMAttributeMap.cpp @@ -180,23 +180,6 @@ already_AddRefed<Attr> nsDOMAttributeMap::SetNamedItemNS( Attr& aAttr, nsIPrincipal* aSubjectPrincipal, ErrorResult& aError) { NS_ENSURE_TRUE(mContent, nullptr); - // XXX should check same-origin between mContent and aAttr however - // nsContentUtils::CheckSameOrigin can't deal with attributenodes yet - - // Check that attribute is not owned by somebody else - nsDOMAttributeMap* owner = aAttr.GetMap(); - if (owner) { - if (owner != this) { - aError.Throw(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR); - return nullptr; - } - - // setting a preexisting attribute is a no-op, just return the same - // node. - RefPtr<Attr> attribute = &aAttr; - return attribute.forget(); - } - nsAutoString value; aAttr.GetValue(value); @@ -212,11 +195,19 @@ already_AddRefed<Attr> nsDOMAttributeMap::SetNamedItemNS( if (aError.Failed()) { return nullptr; } - // After the GetTrustedTypesCompliantAttributeValue() call, the attribute may - // have been attached to another element. - if (aAttr.GetMap() && aAttr.GetMap() != this) { - aError.Throw(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR); - return nullptr; + + // Check that attribute is not owned by somebody else + nsDOMAttributeMap* owner = aAttr.GetMap(); + if (owner) { + if (owner != this) { + aError.Throw(NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR); + return nullptr; + } + + // setting a preexisting attribute is a no-op, just return the same + // node. + RefPtr<Attr> attribute = &aAttr; + return attribute.forget(); } nsresult rv; diff --git a/testing/web-platform/meta/trusted-types/set-attributes-require-trusted-types-no-default-policy-error-cases.html.ini b/testing/web-platform/meta/trusted-types/set-attributes-require-trusted-types-no-default-policy-error-cases.html.ini @@ -1,24 +0,0 @@ -[set-attributes-require-trusted-types-no-default-policy-error-cases.html] - [setAttributeNode runs Trusted Types check before inuse checks] - expected: FAIL - - [setAttributeNodeNS runs Trusted Types check before inuse checks] - expected: FAIL - - [setNamedItem runs Trusted Types check before inuse checks] - expected: FAIL - - [setNamedItemNS runs Trusted Types check before inuse checks] - expected: FAIL - - [setAttributeNode runs Trusted Types check before same attribute early return] - expected: FAIL - - [setAttributeNodeNS runs Trusted Types check before same attribute early return] - expected: FAIL - - [setNamedItem runs Trusted Types check before same attribute early return] - expected: FAIL - - [setNamedItemNS runs Trusted Types check before same attribute early return] - expected: FAIL