Bug 1802346 - Use the owner principal in ParseFromSafeString, r=smaug

This is done rather than using the system principal to avoid potential
cross-docgroup adoption issues.

Differential Revision: https://phabricator.services.mozilla.com/D163017
This commit is contained in:
Nika Layzell
2022-11-25 20:56:25 +00:00
parent b3edc91398
commit 2b4199cd37

View File

@@ -103,12 +103,13 @@ already_AddRefed<Document> DOMParser::ParseFromString(const nsAString& aStr,
already_AddRefed<Document> DOMParser::ParseFromSafeString(const nsAString& aStr, already_AddRefed<Document> DOMParser::ParseFromSafeString(const nsAString& aStr,
SupportedType aType, SupportedType aType,
ErrorResult& aRv) { ErrorResult& aRv) {
// Since we disable cross docGroup node adoption, it is safe to create // Create the new document with the same principal as `mOwner`, even if it is
// new document with the system principal, then the new document will be // the system principal. This will ensure that nodes from the returned
// placed in the same docGroup as the chrome document. // document are in the same DocGroup as the owner global's document, allowing
// nodes to be adopted.
nsCOMPtr<nsIPrincipal> docPrincipal = mPrincipal; nsCOMPtr<nsIPrincipal> docPrincipal = mPrincipal;
if (!mPrincipal->IsSystemPrincipal()) { if (mOwner && mOwner->PrincipalOrNull()) {
mPrincipal = SystemPrincipal::Create(); mPrincipal = mOwner->PrincipalOrNull();
} }
RefPtr<Document> ret = ParseFromString(aStr, aType, aRv); RefPtr<Document> ret = ParseFromString(aStr, aType, aRv);