From 0e02e94278011f5d88b42b78be20ba5a7bd5d943 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 1 May 2025 16:20:08 +0200 Subject: [PATCH 01/20] No issue - Include all non-ubiquitous image and media types in nav Accept: See: https://github.com/whatwg/fetch/issues/274#issuecomment-2841053461 Considering the ubiquitous nature of gif, jpg, png, mp4, avi, etc. those are left out, leaving just jxl, webp, x-matroska (mkv) and webm as explicitly mentioned supported formats for conneg. Note: it's not clear where network.http.accept.image is used in practice because our normal place to use the image override (imgloader) uses a different pref (image.http.accept). --- modules/libpref/init/all.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 1a7428427f..d82879a3f6 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1500,8 +1500,18 @@ pref("network.http.request.max-attempts", 10); // Headers pref("network.http.accept.default", "*/*"); -pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); -pref("network.http.accept.image", "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); +// Top-level navigation should include all non-ubiquitous mime types in front of */* +// including image and video/audio types that are handled top-level. +#ifdef MOZ_JXL +pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/webp,video/x-matroska,video/webm,*/*;q=0.8"); +#else +pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,video/x-matroska,video/webm,*/*;q=0.8"); +#endif +#ifdef MOZ_JXL +pref("network.http.accept.image", "image/jxl,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); +#else +pref("network.http.accept.image", "image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); +#endif pref("network.http.accept.style", "text/css,*/*;q=0.1"); // Prefs allowing granular control of referers From 055765d1017d6180556a05ca8a9566718d569d8d Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 3 May 2025 13:49:28 +0200 Subject: [PATCH 02/20] No issue - Explicitly indicate image/apng in `Accept:` header --- modules/libpref/init/all.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index d82879a3f6..0902ef55f2 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1503,14 +1503,14 @@ pref("network.http.accept.default", "*/*"); // Top-level navigation should include all non-ubiquitous mime types in front of */* // including image and video/audio types that are handled top-level. #ifdef MOZ_JXL -pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/webp,video/x-matroska,video/webm,*/*;q=0.8"); +pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/webp,image/apng,video/x-matroska,video/webm,*/*;q=0.8"); #else pref("network.http.accept.navigation", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,video/x-matroska,video/webm,*/*;q=0.8"); #endif #ifdef MOZ_JXL -pref("network.http.accept.image", "image/jxl,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); +pref("network.http.accept.image", "image/jxl,image/webp,image/apng,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); #else -pref("network.http.accept.image", "image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); +pref("network.http.accept.image", "image/webp,image/apng,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); #endif pref("network.http.accept.style", "text/css,*/*;q=0.1"); From 40e01c31e434301f422056a6e73e0703757a9b7f Mon Sep 17 00:00:00 2001 From: Shadow Date: Fri, 2 May 2025 15:07:00 +0000 Subject: [PATCH 03/20] No Issue - Fix incorrectly written pref name Bug 1481096 "spdy.default-hpack-buffer" was incorrectly written as "spdy.hpack-default-buffer". --- netwerk/protocol/http/nsHttpHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index d6c5ca2107..46acea5baf 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -1690,7 +1690,7 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) } } - if (PREF_CHANGED(HTTP_PREF("spdy.hpack-default-buffer"))) { + if (PREF_CHANGED(HTTP_PREF("spdy.default-hpack-buffer"))) { rv = prefs->GetIntPref(HTTP_PREF("spdy.default-hpack-buffer"), &val); if (NS_SUCCEEDED(rv)) { mDefaultHpackBuffer = val; From e8b3077d4f95a30d9346d75bd590067051fc765a Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 5 May 2025 13:12:42 -0500 Subject: [PATCH 04/20] No Issue - Fixes for building with LLVM 19 included with FreeBSD 13.5. Fix a conflict with libc++ 19 and the old Mozilla (re)alloc macros. LLVM 18+ does not allow std::char_traits so avoid it. https://bugzilla.mozilla.org/show_bug.cgi?id=1849070 Partial NSS upgrade to replace ByteString with a class. https://bugzilla.mozilla.org/show_bug.cgi?id=1851092 --- gfx/graphite2/src/MozGrMalloc.h | 20 +++++++++++--- js/src/builtin/intl/Locale.cpp | 9 ++++--- .../mozpkix/include/pkix-test/pkixtestutil.h | 26 ++++++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/gfx/graphite2/src/MozGrMalloc.h b/gfx/graphite2/src/MozGrMalloc.h index acaae1236c..eb54661121 100644 --- a/gfx/graphite2/src/MozGrMalloc.h +++ b/gfx/graphite2/src/MozGrMalloc.h @@ -12,8 +12,22 @@ #include "mozilla/mozalloc.h" -#define malloc moz_xmalloc -#define calloc moz_xcalloc -#define realloc moz_xrealloc +// extern "C" is needed for the Solaris build, while the inline +// functions are needed for the MinGW build. + +extern "C" inline void* malloc(size_t size) +{ + return moz_xmalloc(size); +} + +extern "C" inline void* calloc(size_t nmemb, size_t size) +{ + return moz_xcalloc(nmemb, size); +} + +extern "C" inline void* realloc(void *ptr, size_t size) +{ + return moz_xrealloc(ptr, size); +} #endif // MOZ_GR_MALLOC_H diff --git a/js/src/builtin/intl/Locale.cpp b/js/src/builtin/intl/Locale.cpp index 980ab37f66..b34ee953ca 100644 --- a/js/src/builtin/intl/Locale.cpp +++ b/js/src/builtin/intl/Locale.cpp @@ -746,8 +746,9 @@ static inline auto FindUnicodeExtensionType(JSLinearString* unicodeExtension, UnicodeKey key) { JS::AutoCheckCannotGC nogc; return unicodeExtension->hasLatin1Chars() - ? FindUnicodeExtensionType(unicodeExtension->latin1Chars(nogc), - unicodeExtension->length(), key) + ? FindUnicodeExtensionType( + reinterpret_cast(unicodeExtension->latin1Chars(nogc)), + unicodeExtension->length(), key) : FindUnicodeExtensionType(unicodeExtension->twoByteChars(nogc), unicodeExtension->length(), key); } @@ -858,7 +859,9 @@ static BaseNamePartsResult BaseNameParts(const CharT* baseName, size_t length) { static inline auto BaseNameParts(JSLinearString* baseName) { JS::AutoCheckCannotGC nogc; return baseName->hasLatin1Chars() - ? BaseNameParts(baseName->latin1Chars(nogc), baseName->length()) + ? BaseNameParts( + reinterpret_cast(baseName->latin1Chars(nogc)), + baseName->length()) : BaseNameParts(baseName->twoByteChars(nogc), baseName->length()); } diff --git a/security/nss/lib/mozpkix/include/pkix-test/pkixtestutil.h b/security/nss/lib/mozpkix/include/pkix-test/pkixtestutil.h index 721fcc23b1..1f3efe1752 100644 --- a/security/nss/lib/mozpkix/include/pkix-test/pkixtestutil.h +++ b/security/nss/lib/mozpkix/include/pkix-test/pkixtestutil.h @@ -35,7 +35,31 @@ namespace mozilla { namespace pkix { namespace test { -typedef std::basic_string ByteString; +class ByteString : public std::string { + public: + ByteString() {} + ByteString(size_t count, uint8_t value) : std::string(count, char(value)) {} + explicit ByteString(const uint8_t* data) + : std::string(reinterpret_cast(data)) {} + ByteString(const uint8_t* data, size_t length) + : std::string(reinterpret_cast(data), length) {} + ByteString operator+(const ByteString& rhs) const { + ByteString result = *this; + result.std::string::append(rhs); + return result; + } + const uint8_t* data() const { + return reinterpret_cast(std::string::data()); + } + void assign(const uint8_t* data, size_t length) { + std::string::assign(reinterpret_cast(data), length); + } + void append(const ByteString& other) { std::string::append(other); } + void append(const uint8_t* data, size_t length) { + std::string::append(reinterpret_cast(data), length); + } + void push_back(uint8_t c) { std::string::push_back(char(c)); } +}; inline bool ENCODING_FAILED(const ByteString& bs) { return bs.empty(); } From facab7f0abcaa82cb1680948a6cb2844be24cc62 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 7 May 2025 16:54:26 +0200 Subject: [PATCH 05/20] No issue - Bump general.useragent.compatMode.version to 128.0 --- modules/libpref/init/all.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 0902ef55f2..4e516401f7 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -25,7 +25,7 @@ pref("general.useragent.locale", "chrome://global/locale/intl.properties"); // Platform User-agent compatibility mode default settings pref("general.useragent.compatMode.gecko", false); pref("general.useragent.compatMode.firefox", false); -pref("general.useragent.compatMode.version", "115.0"); +pref("general.useragent.compatMode.version", "128.0"); pref("general.useragent.appVersionIsBuildID", false); // In order to disable all overrides by default, don't initialize From 422ca16a8e37d8dee86b9c4e37508a52c00e84c9 Mon Sep 17 00:00:00 2001 From: Shadow Date: Thu, 8 May 2025 10:03:06 +0000 Subject: [PATCH 06/20] No Issue - Remove obsolete pref. Bug 1193695 Removes obsolete preference "gfx.prefer-mesa-llvmpipe" The code which made use of it was removed. --- modules/libpref/init/all.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 4e516401f7..fc33216025 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -808,7 +808,6 @@ pref("gfx.canvas.skiagl.dynamic-cache", true); pref("gfx.text.disable-aa", false); pref("gfx.work-around-driver-bugs", true); -pref("gfx.prefer-mesa-llvmpipe", false); pref("gfx.draw-color-bars", false); From 9ad680cfc48c4ea041697176fddaa016268e630d Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 26 Apr 2025 20:07:16 +0200 Subject: [PATCH 07/20] Issue #2736 - Part 1: Provide more consistent principals to CSP. We're currently fairly vague and inconsistent about the values we provide to content policy implementations for requestOrigin and requestPrincipal. In some cases they're the triggering principal, sometimes the loading principal, sometimes the channel principal. Our existing content policy implementations which require or expect a loading principal currently retrieve it from the context node. Since no current callers require the principal to be the loading principal, and some already expect it to be the triggering principal (which there's currently no other way to retrieve), a choice was made to pass the triggering principal whenever possible, but use the loading principal to determine the origin URL. --- docshell/base/nsDocShell.cpp | 3 ++ dom/base/WebSocket.cpp | 3 +- dom/base/nsContentPolicyUtils.h | 48 +++++++++++-------- dom/base/nsContentUtils.cpp | 1 + dom/base/nsIContentPolicy.idl | 15 ++++-- dom/base/nsObjectLoadingContent.cpp | 6 ++- dom/html/ImageDocument.cpp | 3 ++ .../base/nsPluginStreamListenerPeer.cpp | 3 +- dom/script/ScriptLoader.cpp | 3 +- dom/security/nsContentSecurityManager.cpp | 11 +---- dom/workers/ServiceWorkerEvents.cpp | 10 ++-- dom/workers/ServiceWorkerManager.cpp | 3 +- dom/xml/nsXMLContentSink.cpp | 3 +- image/imgLoader.cpp | 3 +- layout/style/FontFaceSet.cpp | 3 +- layout/style/Loader.cpp | 44 +++++++++++------ layout/style/Loader.h | 3 +- toolkit/modules/addons/WebRequestContent.js | 5 +- 18 files changed, 109 insertions(+), 61 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 770eb43119..459ed7523a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9951,6 +9951,9 @@ nsDocShell::InternalLoad(nsIURI* aURI, int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(contentType, aURI, + // This is a top-level load, so the loading + // principal is null. + nullptr, aTriggeringPrincipal, requestingContext, EmptyCString(), // mime guess diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index 075697dd71..f91de98773 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -1556,7 +1556,8 @@ WebSocketImpl::Init(JSContext* aCx, int16_t shouldLoad = nsIContentPolicy::ACCEPT; aRv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_WEBSOCKET, uri, - aPrincipal, + aPrincipal, // loading principal + aPrincipal, // triggering principal originDoc, EmptyCString(), nullptr, diff --git a/dom/base/nsContentPolicyUtils.h b/dom/base/nsContentPolicyUtils.h index 3984ede544..9b4de24276 100644 --- a/dom/base/nsContentPolicyUtils.h +++ b/dom/base/nsContentPolicyUtils.h @@ -152,7 +152,7 @@ NS_CP_ContentTypeName(uint32_t contentType) return NS_ERROR_FAILURE; \ \ return policy-> action (contentType, contentLocation, requestOrigin, \ - context, mimeType, extra, originPrincipal, \ + context, mimeType, extra, triggeringPrincipal, \ decision); \ PR_END_MACRO @@ -160,7 +160,7 @@ NS_CP_ContentTypeName(uint32_t contentType) #define CHECK_CONTENT_POLICY_WITH_SERVICE(action, _policy) \ PR_BEGIN_MACRO \ return _policy-> action (contentType, contentLocation, requestOrigin, \ - context, mimeType, extra, originPrincipal, \ + context, mimeType, extra, triggeringPrincipal, \ decision); \ PR_END_MACRO @@ -173,14 +173,18 @@ NS_CP_ContentTypeName(uint32_t contentType) #define CHECK_PRINCIPAL_AND_DATA(action) \ nsCOMPtr requestOrigin; \ PR_BEGIN_MACRO \ - if (originPrincipal) { \ + if (loadingPrincipal) { \ nsCOMPtr secMan = aSecMan; \ if (!secMan) { \ secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); \ } \ if (secMan) { \ bool isSystem; \ - nsresult rv = secMan->IsSystemPrincipal(originPrincipal, \ + /* We exempt most loads into any document with the system principal \ + * from content policy checks, mostly as an optimization. Which means \ + * that we need to apply this check to the loading principal, not the \ + * principal that triggered the load. */ \ + nsresult rv = secMan->IsSystemPrincipal(loadingPrincipal, \ &isSystem); \ NS_ENSURE_SUCCESS(rv, rv); \ if (isSystem && contentType != nsIContentPolicy::TYPE_DOCUMENT) { \ @@ -203,31 +207,33 @@ NS_CP_ContentTypeName(uint32_t contentType) dataPolicy-> action (externalType, contentLocation, \ requestOrigin, context, \ mimeType, extra, \ - originPrincipal, decision); \ + triggeringPrincipal, decision);\ } \ } \ } \ return NS_OK; \ } \ } \ - nsresult rv = originPrincipal->GetURI(getter_AddRefs(requestOrigin)); \ + nsresult rv = loadingPrincipal->GetURI(getter_AddRefs(requestOrigin)); \ NS_ENSURE_SUCCESS(rv, rv); \ } \ PR_END_MACRO /** * Alias for calling ShouldLoad on the content policy service. Parameters are - * the same as nsIContentPolicy::shouldLoad, except for the originPrincipal - * parameter, which should be non-null if possible, and the last two - * parameters, which can be used to pass in pointer to some useful services if - * the caller already has them. The origin URI to pass to shouldLoad will be - * the URI of originPrincipal, unless originPrincipal is null (in which case a - * null origin URI will be passed). + * the same as nsIContentPolicy::shouldLoad, except for the loadingPrincipal + * and triggeringPrincipal parameters (which should be non-null if possible, + * and have the same semantics as in LoadInfo), and the last two parameters, + * which can be used to pass in pointer to some useful services if the caller + * already has them. The origin URI to pass to shouldLoad will be the URI of + * loadingPrincipal, unless loadingPrincipal is null (in which case a null + * origin URI will be passed). */ inline nsresult NS_CheckContentLoadPolicy(uint32_t contentType, nsIURI *contentLocation, - nsIPrincipal *originPrincipal, + nsIPrincipal *loadingPrincipal, + nsIPrincipal *triggeringPrincipal, nsISupports *context, const nsACString &mimeType, nsISupports *extra, @@ -244,17 +250,19 @@ NS_CheckContentLoadPolicy(uint32_t contentType, /** * Alias for calling ShouldProcess on the content policy service. Parameters - * are the same as nsIContentPolicy::shouldLoad, except for the originPrincipal - * parameter, which should be non-null if possible, and the last two - * parameters, which can be used to pass in pointer to some useful services if - * the caller already has them. The origin URI to pass to shouldLoad will be - * the URI of originPrincipal, unless originPrincipal is null (in which case a - * null origin URI will be passed). + * are the same as nsIContentPolicy::shouldLoad, except for the and + * triggeringPrincipal parameters (which should be non-null if possible, and + * have the same semantics as in nsLoadInfo), and the last parameter, which + * can be used to pass in a pointer to a useful service if the caller already + * has it. The origin URI to pass to shouldLoad will be the URI of + * loadingPrincipal, unless loadingPrincipal is null (in which case a null + * origin URI will be passed). */ inline nsresult NS_CheckContentProcessPolicy(uint32_t contentType, nsIURI *contentLocation, - nsIPrincipal *originPrincipal, + nsIPrincipal *loadingPrincipal, + nsIPrincipal *triggeringPrincipal, nsISupports *context, const nsACString &mimeType, nsISupports *extra, diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 155d55ac29..1d3086c512 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3289,6 +3289,7 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext, rv = NS_CheckContentLoadPolicy(aContentType, aURI, aLoadingPrincipal, + aLoadingPrincipal, // triggering principal aContext, EmptyCString(), //mime guess nullptr, //extra diff --git a/dom/base/nsIContentPolicy.idl b/dom/base/nsIContentPolicy.idl index 870ed6f739..31044e46f0 100644 --- a/dom/base/nsIContentPolicy.idl +++ b/dom/base/nsIContentPolicy.idl @@ -34,8 +34,11 @@ interface nsIContentPolicy : nsIContentPolicyBase * not be null * * @param aRequestOrigin OPTIONAL. the location of the resource that - * initiated this load request; can be null if - * inapplicable + * that is loading the request. This will generally + * be the URI of the loading principal for the + * resulting request (as determined by its + * LoadInfo), but may vary depending on the + * caller. Can be null if inapplicable. * * @param aContext OPTIONAL. the nsIDOMNode or nsIDOMWindow that * initiated the request, or something that can QI @@ -55,8 +58,12 @@ interface nsIContentPolicy : nsIContentPolicyBase * @param aRequestPrincipal an OPTIONAL argument, defines the principal that * caused the load. This is optional only for * non-gecko code: all gecko code should set this - * argument. For navigation events, this is - * the principal of the page that caused this load. + * argument. This should generally be the same as + * the triggering principal for the resulting + * request (as determined by its LoadInfo), but may + * vary depending on the caller. Sometimes it will + * be the loading principal or final channel + * principal instead. * * @return ACCEPT or REJECT_* * diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 0f0c9106eb..e6ff926906 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -1633,7 +1633,8 @@ nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy) *aContentPolicy = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType, mURI, - doc->NodePrincipal(), + doc->NodePrincipal(), // loading principal + doc->NodePrincipal(), // triggering principal thisContent, mContentType, nullptr, //extra @@ -1684,7 +1685,8 @@ nsObjectLoadingContent::CheckProcessPolicy(int16_t *aContentPolicy) nsresult rv = NS_CheckContentProcessPolicy(objectType, mURI ? mURI : mBaseURI, - doc->NodePrincipal(), + doc->NodePrincipal(), // loading principal + doc->NodePrincipal(), // triggering principal static_cast(this), mContentType, nullptr, //extra diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 87bf3ee99f..efa95f36c5 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -97,11 +97,14 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) if (secMan) { secMan->GetChannelResultPrincipal(channel, getter_AddRefs(channelPrincipal)); } + + nsCOMPtr loadInfo = channel->GetLoadInfo(); int16_t decision = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_INTERNAL_IMAGE, channelURI, channelPrincipal, + loadInfo ? loadInfo->TriggeringPrincipal() : nullptr, domWindow->GetFrameElementInternal(), mimeType, nullptr, diff --git a/dom/plugins/base/nsPluginStreamListenerPeer.cpp b/dom/plugins/base/nsPluginStreamListenerPeer.cpp index 603f2408c8..3cde93725c 100644 --- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp +++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp @@ -505,7 +505,8 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_OBJECT_SUBREQUEST, mURL, - principal, + principal, // loading principal + principal, // triggering principal element, contentType, nullptr, diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index b6462a0cee..dc07d47781 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -448,7 +448,8 @@ ScriptLoader::CheckContentPolicy(nsIDocument* aDocument, int16_t shouldLoad = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType, aURI, - aDocument->NodePrincipal(), + aDocument->NodePrincipal(), // loading principal + aDocument->NodePrincipal(), // triggering principal aContext, NS_LossyConvertUTF16toASCII(aType), nullptr, //extra diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index d33f962ecd..1539e263d5 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -573,18 +573,11 @@ DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo) MOZ_ASSERT(false, "can not perform security check without a valid contentType"); } - // For document loads we use the triggeringPrincipal as the originPrincipal. - // Note the the loadingPrincipal for loads of TYPE_DOCUMENT is a nullptr. - nsCOMPtr principal = - (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT || - contentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT) - ? aLoadInfo->TriggeringPrincipal() - : aLoadInfo->LoadingPrincipal(); - int16_t shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(internalContentPolicyType, uri, - principal, + aLoadInfo->LoadingPrincipal(), + aLoadInfo->TriggeringPrincipal(), requestingContext, mimeTypeGuess, nullptr, //extra, diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 34b307caf4..ec22a68d63 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -261,10 +261,14 @@ public: rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, nullptr); NS_ENSURE_SUCCESS(rv, false); int16_t decision = nsIContentPolicy::ACCEPT; - rv = NS_CheckContentLoadPolicy(aLoadInfo->InternalContentPolicyType(), uri, + rv = NS_CheckContentLoadPolicy(aLoadInfo->InternalContentPolicyType(), + uri, aLoadInfo->LoadingPrincipal(), - aLoadInfo->LoadingNode(), EmptyCString(), - nullptr, &decision); + aLoadInfo->TriggeringPrincipal(), + aLoadInfo->LoadingNode(), + EmptyCString(), + nullptr, + &decision); NS_ENSURE_SUCCESS(rv, false); return decision == nsIContentPolicy::ACCEPT; } diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 7f70c9ee10..6c0e8250b8 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -592,7 +592,8 @@ ServiceWorkerManager::Register(mozIDOMWindow* aWindow, int16_t decision = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER, aScriptURI, - documentPrincipal, + documentPrincipal, // loading principal + documentPrincipal, // triggering principal doc, EmptyCString(), nullptr, diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index 2c55265193..44eff4cc32 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -696,7 +696,8 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement, int16_t decision = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XSLT, url, - mDocument->NodePrincipal(), + mDocument->NodePrincipal(), // loading principal + mDocument->NodePrincipal(), // triggering principal aElement, type, nullptr, diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 1bf6ece905..503bc5ed11 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -567,7 +567,8 @@ ShouldLoadCachedImage(imgRequest* aImgRequest, int16_t decision = nsIContentPolicy::REJECT_REQUEST; rv = NS_CheckContentLoadPolicy(aPolicyType, contentLocation, - aLoadingPrincipal, + aLoadingPrincipal, // loading principal + aLoadingPrincipal, // triggering principal aLoadingContext, EmptyCString(), //mime guess nullptr, //aExtra diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 402e7c05a3..5b390d769e 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -1366,7 +1366,8 @@ FontFaceSet::IsFontLoadAllowed(nsIURI* aFontLocation, nsIPrincipal* aPrincipal) int16_t shouldLoad = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_FONT, aFontLocation, - aPrincipal, + aPrincipal, // loading principal + aPrincipal, // triggering principal mDocument, EmptyCString(), // mime type nullptr, // aExtra diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 3b445eb567..41ed9a1af5 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1028,14 +1028,15 @@ Loader::ObsoleteSheet(nsIURI* aURI) } nsresult -Loader::CheckContentPolicy(nsIPrincipal* aSourcePrincipal, - nsIURI* aTargetURI, - nsISupports* aContext, - bool aIsPreload) +Loader::CheckContentPolicy(nsIPrincipal* aLoadingPrincipal, + nsIPrincipal* aTriggeringPrincipal, + nsIURI* aTargetURI, + nsISupports* aContext, + bool aIsPreload) { // When performing a system load (e.g. aUseSystemPrincipal = true) - // then aSourcePrincipal == null; don't consult content policies. - if (!aSourcePrincipal) { + // then aLoadingPrincipal == null; don't consult content policies. + if (!aLoadingPrincipal) { return NS_OK; } @@ -1046,7 +1047,8 @@ Loader::CheckContentPolicy(nsIPrincipal* aSourcePrincipal, int16_t shouldLoad = nsIContentPolicy::ACCEPT; nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType, aTargetURI, - aSourcePrincipal, + aLoadingPrincipal, + aTriggeringPrincipal, aContext, NS_LITERAL_CSTRING("text/css"), nullptr, //extra param @@ -2039,15 +2041,20 @@ Loader::LoadStyleLink(nsIContent* aElement, NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED); - nsIPrincipal* principal = - aElement ? aElement->NodePrincipal() : mDocument->NodePrincipal(); + nsIPrincipal* loadingPrincipal = aElement ? aElement->NodePrincipal() + : mDocument->NodePrincipal(); + //SHOULD BE: + //nsIPrincipal* principal = aTriggeringPrincipal ? aTriggeringPrincipal + // : loadingPrincipal; + nsIPrincipal* principal = loadingPrincipal; + nsISupports* context = aElement; if (!context) { context = mDocument; } - nsresult rv = CheckContentPolicy(principal, aURL, context, false); + nsresult rv = CheckContentPolicy(loadingPrincipal, principal, aURL, context, false); if (NS_WARN_IF(NS_FAILED(rv))) { // Don't fire the error event if our document is loaded as data. We're // supposed to not even try to do loads in that case... Unfortunately, we @@ -2188,13 +2195,18 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, owningNode = topSheet->GetOwnerNode(); } - nsISupports* context = owningNode; - if (!context) { + nsISupports* context = nullptr; + nsIPrincipal* loadingPrincipal = nullptr; + if (owningNode) { + context = owningNode; + loadingPrincipal = owningNode->NodePrincipal(); + } else if (mDocument) { context = mDocument; + loadingPrincipal = mDocument->NodePrincipal(); } nsIPrincipal* principal = aParentSheet->Principal(); - nsresult rv = CheckContentPolicy(principal, aURL, context, false); + nsresult rv = CheckContentPolicy(loadingPrincipal, principal, aURL, context, false); NS_ENSURE_SUCCESS(rv, rv); SheetLoadData* parentData = nullptr; @@ -2351,7 +2363,11 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, return NS_ERROR_NOT_AVAILABLE; } - nsresult rv = CheckContentPolicy(aOriginPrincipal, aURL, mDocument, aIsPreload); + nsCOMPtr loadingPrincipal = (aOriginPrincipal && mDocument + ? mDocument->NodePrincipal() + : nullptr); + nsresult rv = CheckContentPolicy(loadingPrincipal, aOriginPrincipal, + aURL, mDocument, aIsPreload); NS_ENSURE_SUCCESS(rv, rv); StyleSheetState state; diff --git a/layout/style/Loader.h b/layout/style/Loader.h index 2319164a2f..830099b3ce 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -452,7 +452,8 @@ public: private: friend class SheetLoadData; - nsresult CheckContentPolicy(nsIPrincipal* aSourcePrincipal, + nsresult CheckContentPolicy(nsIPrincipal* aLoadingPrincipal, + nsIPrincipal* aTriggeringPrincipal, nsIURI* aTargetURI, nsISupports* aContext, bool aIsPreload); diff --git a/toolkit/modules/addons/WebRequestContent.js b/toolkit/modules/addons/WebRequestContent.js index f044a1cd4e..d3f52bc6a5 100644 --- a/toolkit/modules/addons/WebRequestContent.js +++ b/toolkit/modules/addons/WebRequestContent.js @@ -173,7 +173,10 @@ var ContentPolicy = { windowId, parentWindowId}; if (requestOrigin) { - data.originUrl = requestOrigin.spec; + data.documentUrl = requestOrigin.spec; + } + if (requestPrincipal && requestPrincipal.URI) { + data.originUrl = requestPrincipal.URI.spec; } if (block) { let rval = mm.sendSyncMessage("WebRequest:ShouldLoad", data); From 824d0cad581cf1a6c0b5bdfe25e067634f6486c7 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 27 Apr 2025 20:42:29 +0200 Subject: [PATCH 08/20] Issue #2736 - Part 2: Pass subject principal to SetAttribute and friends. In order to tailor certain security checks to the caller that is attempting to load a particular piece of content, we need to be able to attach an appropriate triggering principal to the corresponding requests. Since most HTML content is loaded based on attribute values, this means capturing the subject principal of the caller who sets those attributes, which in turn means we need to make it available to `AfterSetAttr` hooks on all relevant element types. --- dom/base/AnonymousContent.cpp | 3 +- dom/base/AnonymousContent.h | 1 + dom/base/Attr.cpp | 5 ++- dom/base/Attr.h | 8 +++- dom/base/DocumentFragment.h | 7 +-- dom/base/Element.cpp | 20 ++++++--- dom/base/Element.h | 61 ++++++++++++++++++-------- dom/base/nsGenericDOMDataNode.cpp | 1 + dom/base/nsGenericDOMDataNode.h | 7 +-- dom/base/nsIContent.h | 17 +++++++ dom/base/nsStyledElement.cpp | 3 +- dom/html/HTMLAnchorElement.cpp | 7 ++- dom/html/HTMLAnchorElement.h | 1 + dom/html/HTMLAreaElement.cpp | 6 ++- dom/html/HTMLAreaElement.h | 1 + dom/html/HTMLButtonElement.cpp | 6 ++- dom/html/HTMLButtonElement.h | 1 + dom/html/HTMLCanvasElement.cpp | 6 ++- dom/html/HTMLCanvasElement.h | 1 + dom/html/HTMLFieldSetElement.cpp | 7 ++- dom/html/HTMLFieldSetElement.h | 1 + dom/html/HTMLFormElement.cpp | 6 ++- dom/html/HTMLFormElement.h | 1 + dom/html/HTMLIFrameElement.cpp | 10 +++-- dom/html/HTMLIFrameElement.h | 1 + dom/html/HTMLImageElement.cpp | 13 ++++-- dom/html/HTMLImageElement.h | 2 + dom/html/HTMLInputElement.cpp | 5 ++- dom/html/HTMLInputElement.h | 1 + dom/html/HTMLLinkElement.cpp | 7 ++- dom/html/HTMLLinkElement.h | 1 + dom/html/HTMLMediaElement.cpp | 8 +++- dom/html/HTMLMediaElement.h | 1 + dom/html/HTMLMenuItemElement.cpp | 10 +++-- dom/html/HTMLMenuItemElement.h | 1 + dom/html/HTMLMetaElement.cpp | 10 +++-- dom/html/HTMLMetaElement.h | 1 + dom/html/HTMLObjectElement.cpp | 7 ++- dom/html/HTMLObjectElement.h | 1 + dom/html/HTMLOptGroupElement.cpp | 7 ++- dom/html/HTMLOptGroupElement.h | 1 + dom/html/HTMLOptionElement.cpp | 8 +++- dom/html/HTMLOptionElement.h | 1 + dom/html/HTMLScriptElement.cpp | 10 +++-- dom/html/HTMLScriptElement.h | 1 + dom/html/HTMLSelectElement.cpp | 5 ++- dom/html/HTMLSelectElement.h | 1 + dom/html/HTMLSharedElement.cpp | 7 ++- dom/html/HTMLSharedElement.h | 1 + dom/html/HTMLSharedObjectElement.cpp | 3 +- dom/html/HTMLSharedObjectElement.h | 1 + dom/html/HTMLSlotElement.cpp | 4 +- dom/html/HTMLSlotElement.h | 1 + dom/html/HTMLSourceElement.cpp | 8 +++- dom/html/HTMLSourceElement.h | 1 + dom/html/HTMLStyleElement.cpp | 7 ++- dom/html/HTMLStyleElement.h | 1 + dom/html/HTMLTableElement.cpp | 7 ++- dom/html/HTMLTableElement.h | 1 + dom/html/HTMLTextAreaElement.cpp | 7 ++- dom/html/HTMLTextAreaElement.h | 1 + dom/html/nsGenericHTMLElement.cpp | 16 +++++-- dom/html/nsGenericHTMLElement.h | 6 +++ dom/html/nsGenericHTMLFrameElement.cpp | 7 ++- dom/html/nsGenericHTMLFrameElement.h | 1 + dom/mathml/nsMathMLElement.cpp | 7 ++- dom/mathml/nsMathMLElement.h | 1 + dom/svg/SVGAElement.cpp | 4 +- dom/svg/SVGAElement.h | 8 ++-- dom/svg/SVGAnimationElement.cpp | 7 ++- dom/svg/SVGAnimationElement.h | 1 + dom/svg/SVGFEImageElement.cpp | 8 +++- dom/svg/SVGFEImageElement.h | 1 + dom/svg/SVGGeometryElement.cpp | 8 +++- dom/svg/SVGGeometryElement.h | 1 + dom/svg/SVGImageElement.cpp | 8 +++- dom/svg/SVGImageElement.h | 1 + dom/svg/SVGScriptElement.cpp | 8 +++- dom/svg/SVGScriptElement.h | 1 + dom/svg/SVGStyleElement.cpp | 3 +- dom/svg/SVGStyleElement.h | 8 ++-- dom/svg/nsSVGElement.cpp | 8 ++-- dom/svg/nsSVGElement.h | 1 + dom/webidl/AnonymousContent.webidl | 2 +- dom/webidl/Attr.webidl | 2 +- dom/webidl/Element.webidl | 4 +- dom/xul/nsXULElement.cpp | 6 ++- dom/xul/nsXULElement.h | 1 + 88 files changed, 337 insertions(+), 132 deletions(-) diff --git a/dom/base/AnonymousContent.cpp b/dom/base/AnonymousContent.cpp index ffb7597979..6b9f47be18 100644 --- a/dom/base/AnonymousContent.cpp +++ b/dom/base/AnonymousContent.cpp @@ -74,6 +74,7 @@ void AnonymousContent::SetAttributeForElement(const nsAString& aElementId, const nsAString& aName, const nsAString& aValue, + nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { Element* element = GetElementById(aElementId); @@ -82,7 +83,7 @@ AnonymousContent::SetAttributeForElement(const nsAString& aElementId, return; } - element->SetAttribute(aName, aValue, aRv); + element->SetAttribute(aName, aValue, aSubjectPrincipal, aRv); } void diff --git a/dom/base/AnonymousContent.h b/dom/base/AnonymousContent.h index c1c2b189b6..161c117579 100644 --- a/dom/base/AnonymousContent.h +++ b/dom/base/AnonymousContent.h @@ -42,6 +42,7 @@ public: void SetAttributeForElement(const nsAString& aElementId, const nsAString& aName, const nsAString& aValue, + nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv); void GetAttributeForElement(const nsAString& aElementId, diff --git a/dom/base/Attr.cpp b/dom/base/Attr.cpp index 91e9c1db23..2abe675a52 100644 --- a/dom/base/Attr.cpp +++ b/dom/base/Attr.cpp @@ -174,7 +174,7 @@ Attr::GetValue(nsAString& aValue) } void -Attr::SetValue(const nsAString& aValue, ErrorResult& aRv) +Attr::SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, ErrorResult& aRv) { Element* element = GetElement(); if (!element) { @@ -187,6 +187,7 @@ Attr::SetValue(const nsAString& aValue, ErrorResult& aRv) nameAtom, mNodeInfo->GetPrefixAtom(), aValue, + aTriggeringPrincipal, true); } @@ -194,7 +195,7 @@ NS_IMETHODIMP Attr::SetValue(const nsAString& aValue) { ErrorResult rv; - SetValue(aValue, rv); + SetValue(aValue, nullptr, rv); return rv.StealNSResult(); } diff --git a/dom/base/Attr.h b/dom/base/Attr.h index 154a83102e..5c6fe895a5 100644 --- a/dom/base/Attr.h +++ b/dom/base/Attr.h @@ -84,9 +84,13 @@ public: virtual JSObject* WrapNode(JSContext* aCx, JS::Handle aGivenProto) override; // XPCOM GetName() is OK - // XPCOM GetValue() is OK - void SetValue(const nsAString& aValue, ErrorResult& aRv); + void GetValue(nsString& val, nsIPrincipal&) + { + GetValue(val); + } + + void SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, ErrorResult& aRv); bool Specified() const; diff --git a/dom/base/DocumentFragment.h b/dom/base/DocumentFragment.h index 3ffc8ac0b8..817d37c9dd 100644 --- a/dom/base/DocumentFragment.h +++ b/dom/base/DocumentFragment.h @@ -69,13 +69,10 @@ public: virtual JSObject* WrapNode(JSContext *aCx, JS::Handle aGivenProto) override; // nsIContent - nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, - const nsAString& aValue, bool aNotify) - { - return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); - } + using nsIContent::SetAttr; virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, const nsAString& aValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override { return NS_OK; diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 7522128d46..b03fdd5fbf 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1254,6 +1254,7 @@ Element::ToggleAttribute(const nsAString& aName, void Element::SetAttribute(const nsAString& aName, const nsAString& aValue, + nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError) { aError = nsContentUtils::CheckQName(aName, false); @@ -1269,12 +1270,12 @@ Element::SetAttribute(const nsAString& aName, aError.Throw(NS_ERROR_OUT_OF_MEMORY); return; } - aError = SetAttr(kNameSpaceID_None, nameAtom, aValue, true); + aError = SetAttr(kNameSpaceID_None, nameAtom, aValue, aTriggeringPrincipal, true); return; } aError = SetAttr(name->NamespaceID(), name->LocalName(), name->GetPrefix(), - aValue, true); + aValue, aTriggeringPrincipal, true); return; } @@ -1357,6 +1358,7 @@ void Element::SetAttributeNS(const nsAString& aNamespaceURI, const nsAString& aQualifiedName, const nsAString& aValue, + nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError) { RefPtr ni; @@ -1370,7 +1372,7 @@ Element::SetAttributeNS(const nsAString& aNamespaceURI, } aError = SetAttr(ni->NamespaceID(), ni->NameAtom(), ni->GetPrefixAtom(), - aValue, true); + aValue, aTriggeringPrincipal, true); } void @@ -2419,6 +2421,7 @@ Element::SetSingleClassFromParser(nsIAtom* aSingleClassName) nullptr, // prefix nullptr, // old value value, + nullptr, // subject principal static_cast(nsIDOMMutationEvent::ADDITION), false, // hasListeners false, // notify @@ -2430,6 +2433,7 @@ Element::SetSingleClassFromParser(nsIAtom* aSingleClassName) nsresult Element::SetAttr(int32_t aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix, const nsAString& aValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) { // Keep this in sync with SetParsedAttr below and SetSingleClassFromParser @@ -2489,7 +2493,8 @@ Element::SetAttr(int32_t aNamespaceID, nsIAtom* aName, return SetAttrAndNotify(aNamespaceID, aName, aPrefix, oldValueSet ? &oldValue : nullptr, - attrValue, modType, hasListeners, aNotify, + attrValue, aSubjectPrincipal, modType, + hasListeners, aNotify, kCallAfterSetAttr, document, updateBatch); } @@ -2534,7 +2539,7 @@ Element::SetParsedAttr(int32_t aNamespaceID, nsIAtom* aName, mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify); return SetAttrAndNotify(aNamespaceID, aName, aPrefix, oldValueSet ? &oldValue : nullptr, - aParsedValue, modType, hasListeners, aNotify, + aParsedValue, nullptr, modType, hasListeners, aNotify, kCallAfterSetAttr, document, updateBatch); } @@ -2544,6 +2549,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, nsIAtom* aPrefix, const nsAttrValue* aOldValue, nsAttrValue& aParsedValue, + nsIPrincipal* aSubjectPrincipal, uint8_t aModType, bool aFireMutation, bool aNotify, @@ -2650,7 +2656,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, if (aCallAfterSetAttr) { rv = AfterSetAttr(aNamespaceID, aName, &valueForAfterSetAttr, oldValue, - aNotify); + aSubjectPrincipal, aNotify); NS_ENSURE_SUCCESS(rv, rv); if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::dir) { @@ -2946,7 +2952,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } - rv = AfterSetAttr(aNameSpaceID, aName, nullptr, &oldValue, aNotify); + rv = AfterSetAttr(aNameSpaceID, aName, nullptr, &oldValue, nullptr, aNotify); NS_ENSURE_SUCCESS(rv, rv); UpdateState(aNotify); diff --git a/dom/base/Element.h b/dom/base/Element.h index 4d4c9284d3..22ec00418b 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -542,12 +542,7 @@ public: already_AddRefed GetExistingAttrNameFromQName(const nsAString& aStr) const; - MOZ_ALWAYS_INLINE // Avoid a crashy hook from Avast 10 Beta (Bug 1058131) - nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, - const nsAString& aValue, bool aNotify) - { - return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); - } + using nsIContent::SetAttr; /** * Helper for SetAttr/SetParsedAttr. This method will return true if aNotify @@ -610,7 +605,8 @@ public: nsresult SetSingleClassFromParser(nsIAtom* aSingleClassName); virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, - const nsAString& aValue, bool aNotify) override; + const nsAString& aValue, nsIPrincipal* aSubjectPrincipal, + bool aNotify) override; // aParsedValue receives the old value of the attribute. That's useful if // either the input or output value of aParsedValue is StoresOwnData. nsresult SetParsedAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, @@ -783,11 +779,18 @@ public: bool ToggleAttribute(const nsAString& aName, const Optional& aForce, ErrorResult& aError); void SetAttribute(const nsAString& aName, const nsAString& aValue, - ErrorResult& aError); + nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError); void SetAttributeNS(const nsAString& aNamespaceURI, const nsAString& aLocalName, const nsAString& aValue, + nsIPrincipal* aTriggeringPrincipal, ErrorResult& aError); + void SetAttribute(const nsAString& aName, const nsAString& aValue, + ErrorResult& aError) + { + SetAttribute(aName, aValue, nullptr, aError); + } + void RemoveAttribute(const nsAString& aName, ErrorResult& aError); void RemoveAttributeNS(const nsAString& aNamespaceURI, @@ -1232,6 +1235,11 @@ public: aError = SetAttr(kNameSpaceID_None, aAttr, aValue, true); } + void SetAttr(nsIAtom* aAttr, const nsAString& aValue, nsIPrincipal& aTriggeringPrincipal, ErrorResult& aError) + { + aError = nsIContent::SetAttr(kNameSpaceID_None, aAttr, aValue, &aTriggeringPrincipal, true); + } + /** * Set a content attribute via a reflecting nullable string IDL * attribute (e.g. a CORS attribute). If DOMStringIsNull(aValue), @@ -1309,6 +1317,14 @@ protected: * @param aParsedValue parsed new value of attribute. Replaced by the * old value of the attribute. This old value is only * useful if either it or the new value is StoresOwnData. + * @param aMaybeScriptedPrincipal + * the principal of the scripted caller responsible for + * setting the attribute, or null if no scripted caller + * can be determined. A null value here does not + * guarantee that there is no scripted caller, but a + * non-null value does guarantee that a scripted caller + * with the given principal is directly responsible for + * the attribute change. * @param aModType nsIDOMMutationEvent::MODIFICATION or ADDITION. Only * needed if aFireMutation or aNotify is true. * @param aFireMutation should mutation-events be fired? @@ -1321,6 +1337,7 @@ protected: nsIAtom* aPrefix, const nsAttrValue* aOldValue, nsAttrValue& aParsedValue, + nsIPrincipal* aMaybeScriptedPrincipal, uint8_t aModType, bool aFireMutation, bool aNotify, @@ -1412,13 +1429,21 @@ protected: * the attr was not previously set. This argument may not have the * correct value for SVG elements, or other cases in which the * attribute value doesn't store its own data + * @param aMaybeScriptedPrincipal the principal of the scripted caller + * responsible for setting the attribute, or null if no scripted caller + * can be determined, or the attribute is being unset. A null value + * here does not guarantee that there is no scripted caller, but a + * non-null value does guarantee that a scripted caller with the given + * principal is directly responsible for the attribute change. * @param aNotify Whether we plan to notify document observers. */ // Note that this is inlined so that when subclasses call it it gets // inlined. Those calls don't go through a vtable. virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, + bool aNotify) { return NS_OK; } @@ -1801,7 +1826,7 @@ NS_IMETHOD SetAttribute(const nsAString& name, \ const nsAString& value) override \ { \ mozilla::ErrorResult rv; \ - Element::SetAttribute(name, value, rv); \ + Element::SetAttribute(name, value, nullptr, rv); \ return rv.StealNSResult(); \ } \ NS_IMETHOD SetAttributeNS(const nsAString& namespaceURI, \ @@ -1809,22 +1834,22 @@ NS_IMETHOD SetAttributeNS(const nsAString& namespaceURI, \ const nsAString& value) final override \ { \ mozilla::ErrorResult rv; \ - Element::SetAttributeNS(namespaceURI, qualifiedName, value, rv); \ - return rv.StealNSResult(); \ + Element::SetAttributeNS(namespaceURI, qualifiedName, value, nullptr, rv); \ + return rv.StealNSResult(); \ } \ using Element::RemoveAttribute; \ NS_IMETHOD RemoveAttribute(const nsAString& name) final override \ { \ mozilla::ErrorResult rv; \ RemoveAttribute(name, rv); \ - return rv.StealNSResult(); \ + return rv.StealNSResult(); \ } \ NS_IMETHOD RemoveAttributeNS(const nsAString& namespaceURI, \ const nsAString& localName) final override \ { \ mozilla::ErrorResult rv; \ Element::RemoveAttributeNS(namespaceURI, localName, rv); \ - return rv.StealNSResult(); \ + return rv.StealNSResult(); \ } \ using Element::HasAttribute; \ NS_IMETHOD HasAttribute(const nsAString& name, \ @@ -1860,7 +1885,7 @@ NS_IMETHOD SetAttributeNode(nsIDOMAttr* newAttr, \ mozilla::ErrorResult rv; \ mozilla::dom::Attr* attr = static_cast(newAttr); \ *_retval = Element::SetAttributeNode(*attr, rv).take(); \ - return rv.StealNSResult(); \ + return rv.StealNSResult(); \ } \ NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr, \ nsIDOMAttr** _retval) final override \ @@ -1871,7 +1896,7 @@ NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* oldAttr, \ mozilla::ErrorResult rv; \ mozilla::dom::Attr* attr = static_cast(oldAttr); \ *_retval = Element::RemoveAttributeNode(*attr, rv).take(); \ - return rv.StealNSResult(); \ + return rv.StealNSResult(); \ } \ NS_IMETHOD GetAttributeNodeNS(const nsAString& namespaceURI, \ const nsAString& localName, \ @@ -1887,7 +1912,7 @@ NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* newAttr, \ mozilla::ErrorResult rv; \ mozilla::dom::Attr* attr = static_cast(newAttr); \ *_retval = Element::SetAttributeNodeNS(*attr, rv).take(); \ - return rv.StealNSResult(); \ + return rv.StealNSResult(); \ } \ NS_IMETHOD GetElementsByTagName(const nsAString& name, \ nsIDOMHTMLCollection** _retval) final \ @@ -2055,7 +2080,7 @@ NS_IMETHOD ReleaseCapture(void) final override \ NS_IMETHOD MozRequestFullScreen(void) final override \ { \ mozilla::ErrorResult rv; \ - Element::RequestFullscreen(rv); \ + Element::RequestFullscreen(rv); \ return rv.StealNSResult(); \ } \ NS_IMETHOD MozRequestPointerLock(void) final override \ diff --git a/dom/base/nsGenericDOMDataNode.cpp b/dom/base/nsGenericDOMDataNode.cpp index ebb135d88b..85f8833d00 100644 --- a/dom/base/nsGenericDOMDataNode.cpp +++ b/dom/base/nsGenericDOMDataNode.cpp @@ -625,6 +625,7 @@ nsGenericDOMDataNode::GetChildren(uint32_t aFilter) nsresult nsGenericDOMDataNode::SetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, nsIAtom* aPrefix, const nsAString& aValue, + nsIPrincipal* aContentPrincipal, bool aNotify) { return NS_OK; diff --git a/dom/base/nsGenericDOMDataNode.h b/dom/base/nsGenericDOMDataNode.h index c3e8ae4740..683528efea 100644 --- a/dom/base/nsGenericDOMDataNode.h +++ b/dom/base/nsGenericDOMDataNode.h @@ -117,13 +117,10 @@ public: virtual already_AddRefed GetChildren(uint32_t aFilter) override; - nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, - const nsAString& aValue, bool aNotify) - { - return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); - } + using nsIContent::SetAttr; virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, nsIAtom* aPrefix, const nsAString& aValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, bool aNotify) override; diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h index 4e2f1e09fb..35451444ac 100644 --- a/dom/base/nsIContent.h +++ b/dom/base/nsIContent.h @@ -363,6 +363,16 @@ public: { return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); } + nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, + const nsAString& aValue, bool aNotify) + { + return SetAttr(aNameSpaceID, aName, aPrefix, aValue, nullptr, aNotify); + } + nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAString& aValue, + nsIPrincipal* aTriggeringPrincipal, bool aNotify) + { + return SetAttr(aNameSpaceID, aName, nullptr, aValue, aTriggeringPrincipal, aNotify); + } /** * Set attribute values. All attribute values are assumed to have a @@ -375,11 +385,18 @@ public: * @param aName the name of the attribute * @param aPrefix the prefix of the attribute * @param aValue the value to set + * @param aMaybeScriptedPrincipal the principal of the scripted caller responsible + * for setting the attribute, or null if no scripted caller can be + * determined. A null value here does not guarantee that there is no + * scripted caller, but a non-null value does guarantee that a scripted + * caller with the given principal is directly responsible for the + * attribute change. * @param aNotify specifies how whether or not the document should be * notified of the attribute change. */ virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix, const nsAString& aValue, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) = 0; /** diff --git a/dom/base/nsStyledElement.cpp b/dom/base/nsStyledElement.cpp index 4fd423acc7..01c8856444 100644 --- a/dom/base/nsStyledElement.cpp +++ b/dom/base/nsStyledElement.cpp @@ -110,7 +110,8 @@ nsStyledElement::SetInlineStyleDeclaration(css::Declaration* aDeclaration, nsIDocument* document = GetComposedDoc(); mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify); return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr, - oldValueSet ? &oldValue : nullptr, attrValue, modType, + oldValueSet ? &oldValue : nullptr, attrValue, + nullptr, modType, hasListeners, aNotify, kDontCallAfterSetAttr, document, updateBatch); } diff --git a/dom/html/HTMLAnchorElement.cpp b/dom/html/HTMLAnchorElement.cpp index 2fb5ea4677..01e1ab1759 100644 --- a/dom/html/HTMLAnchorElement.cpp +++ b/dom/html/HTMLAnchorElement.cpp @@ -386,7 +386,9 @@ HTMLAnchorElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName, nsresult HTMLAnchorElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNamespaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::href) { @@ -398,7 +400,8 @@ HTMLAnchorElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, - aValue, aOldValue, aNotify); + aValue, aOldValue, + aSubjectPrincipal, aNotify); } EventStates diff --git a/dom/html/HTMLAnchorElement.h b/dom/html/HTMLAnchorElement.h index c80c823c72..99c37b9676 100644 --- a/dom/html/HTMLAnchorElement.h +++ b/dom/html/HTMLAnchorElement.h @@ -71,6 +71,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; diff --git a/dom/html/HTMLAreaElement.cpp b/dom/html/HTMLAreaElement.cpp index 89c25f2902..834c13b9ab 100644 --- a/dom/html/HTMLAreaElement.cpp +++ b/dom/html/HTMLAreaElement.cpp @@ -142,7 +142,9 @@ HTMLAreaElement::UnbindFromTree(bool aDeep, bool aNullParent) nsresult HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNamespaceID == kNameSpaceID_None) { // This must happen after the attribute is set. We will need the updated @@ -155,7 +157,7 @@ HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue, - aOldValue, aNotify); + aOldValue, aSubjectPrincipal, aNotify); } #define IMPL_URI_PART(_part) \ diff --git a/dom/html/HTMLAreaElement.h b/dom/html/HTMLAreaElement.h index 919ba9d60c..083675824a 100644 --- a/dom/html/HTMLAreaElement.h +++ b/dom/html/HTMLAreaElement.h @@ -178,6 +178,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; RefPtr mRelList; diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp index 3e48c09d16..853a9db0f4 100644 --- a/dom/html/HTMLButtonElement.cpp +++ b/dom/html/HTMLButtonElement.cpp @@ -438,7 +438,9 @@ HTMLButtonElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsresult HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::type) { @@ -454,7 +456,7 @@ HTMLButtonElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName, aValue, aOldValue, - aNotify); + aSubjectPrincipal, aNotify); } NS_IMETHODIMP diff --git a/dom/html/HTMLButtonElement.h b/dom/html/HTMLButtonElement.h index 139596ae30..3765ce8d12 100644 --- a/dom/html/HTMLButtonElement.h +++ b/dom/html/HTMLButtonElement.h @@ -88,6 +88,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp index 1d6c008240..b7071079ac 100644 --- a/dom/html/HTMLCanvasElement.cpp +++ b/dom/html/HTMLCanvasElement.cpp @@ -443,12 +443,14 @@ NS_IMPL_BOOL_ATTR(HTMLCanvasElement, MozOpaque, moz_opaque) nsresult HTMLCanvasElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { AfterMaybeChangeAttr(aNamespaceID, aName, aNotify); return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue, - aOldValue, aNotify); + aOldValue, aSubjectPrincipal, aNotify); } nsresult diff --git a/dom/html/HTMLCanvasElement.h b/dom/html/HTMLCanvasElement.h index b84f2eac92..e647cd43a2 100644 --- a/dom/html/HTMLCanvasElement.h +++ b/dom/html/HTMLCanvasElement.h @@ -361,6 +361,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValueOrString& aValue, diff --git a/dom/html/HTMLFieldSetElement.cpp b/dom/html/HTMLFieldSetElement.cpp index 9052d399eb..8cf87f31bc 100644 --- a/dom/html/HTMLFieldSetElement.cpp +++ b/dom/html/HTMLFieldSetElement.cpp @@ -83,7 +83,9 @@ HTMLFieldSetElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) nsresult HTMLFieldSetElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled && nsINode::GetFirstChild()) { @@ -100,7 +102,8 @@ HTMLFieldSetElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } return nsGenericHTMLFormElement::AfterSetAttr(aNameSpaceID, aName, - aValue, aOldValue, aNotify); + aValue, aOldValue, + aSubjectPrincipal, aNotify); } // nsIDOMHTMLFieldSetElement diff --git a/dom/html/HTMLFieldSetElement.h b/dom/html/HTMLFieldSetElement.h index e56a279c34..80990dc63b 100644 --- a/dom/html/HTMLFieldSetElement.h +++ b/dom/html/HTMLFieldSetElement.h @@ -44,6 +44,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual nsresult InsertChildAt(nsIContent* aChild, uint32_t aIndex, diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index d2b39461f1..c84c1e752e 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -218,7 +218,9 @@ HTMLFormElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName, nsresult HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aName == nsGkAtoms::novalidate && aNameSpaceID == kNameSpaceID_None) { // Update all form elements states because they might be [no longer] @@ -235,7 +237,7 @@ HTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, - aOldValue, aNotify); + aOldValue, aSubjectPrincipal, aNotify); } NS_IMPL_STRING_ATTR(HTMLFormElement, AcceptCharset, acceptcharset) diff --git a/dom/html/HTMLFormElement.h b/dom/html/HTMLFormElement.h index 102e24fdf9..b0d355d5a7 100644 --- a/dom/html/HTMLFormElement.h +++ b/dom/html/HTMLFormElement.h @@ -110,6 +110,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; /** diff --git a/dom/html/HTMLIFrameElement.cpp b/dom/html/HTMLIFrameElement.cpp index 8cf19dc9f4..7468b64023 100644 --- a/dom/html/HTMLIFrameElement.cpp +++ b/dom/html/HTMLIFrameElement.cpp @@ -183,7 +183,9 @@ HTMLIFrameElement::GetAttributeMappingFunction() const nsresult HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, + bool aNotify) { AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify); @@ -197,8 +199,10 @@ HTMLIFrameElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } } - return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName, aValue, - aOldValue, aNotify); + return nsGenericHTMLFrameElement::AfterSetAttr(aNameSpaceID, aName, + aValue, aOldValue, + aMaybeScriptedPrincipal, + aNotify); } nsresult diff --git a/dom/html/HTMLIFrameElement.h b/dom/html/HTMLIFrameElement.h index e1240de814..5a06a46a2e 100644 --- a/dom/html/HTMLIFrameElement.h +++ b/dom/html/HTMLIFrameElement.h @@ -184,6 +184,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) override; virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValueOrString& aValue, diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index b697dcabea..885e653fa4 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -393,10 +393,12 @@ HTMLImageElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsresult HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, + bool aNotify) { if (aValue) { - AfterMaybeChangeAttr(aNameSpaceID, aName, aNotify); + AfterMaybeChangeAttr(aNameSpaceID, aName, aMaybeScriptedPrincipal, aNotify); } if (aNameSpaceID == kNameSpaceID_None && mForm && @@ -439,7 +441,9 @@ HTMLImageElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, - aValue, aOldValue, aNotify); + aValue, aOldValue, + aMaybeScriptedPrincipal, + aNotify); } nsresult @@ -448,7 +452,7 @@ HTMLImageElement::OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, bool aNotify) { BeforeMaybeChangeAttr(aNamespaceID, aName, aValue, aNotify); - AfterMaybeChangeAttr(aNamespaceID, aName, aNotify); + AfterMaybeChangeAttr(aNamespaceID, aName, nullptr, aNotify); return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName, aValue, aNotify); @@ -530,6 +534,7 @@ HTMLImageElement::BeforeMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName, void HTMLImageElement::AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) { // Because we load image synchronously in non-responsive-mode, we need to do diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h index 3d3c7c834e..748b922499 100644 --- a/dom/html/HTMLImageElement.h +++ b/dom/html/HTMLImageElement.h @@ -337,6 +337,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) override; virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, @@ -378,6 +379,7 @@ private: * @param aNotify Whether we plan to notify document observers. */ void AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify); /** * Used by BeforeMaybeChangeAttr and AfterMaybeChangeAttr to keep track of diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 7d9a4db1cd..5761b12e68 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -1285,7 +1285,9 @@ HTMLInputElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsresult HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None) { // @@ -1436,6 +1438,7 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, return nsGenericHTMLFormElementWithState::AfterSetAttr(aNameSpaceID, aName, aValue, aOldValue, + aSubjectPrincipal, aNotify); } diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 44e1f9c1ca..45464f638b 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -966,6 +966,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual void ResultForDialogSubmit(nsAString& aResult) override; diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 8fe317cec0..7b6379ae3f 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -357,7 +357,9 @@ HTMLLinkElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { // It's safe to call ResetLinkState here because our new attr value has // already been set or unset. ResetLinkState needs the updated attribute @@ -451,7 +453,8 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, - aOldValue, aNotify); + aOldValue, aSubjectPrincipal, + aNotify); } nsresult diff --git a/dom/html/HTMLLinkElement.h b/dom/html/HTMLLinkElement.h index c7742478e3..7eb6b78e18 100644 --- a/dom/html/HTMLLinkElement.h +++ b/dom/html/HTMLLinkElement.h @@ -66,6 +66,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual bool IsLink(nsIURI** aURI) const override; virtual already_AddRefed GetHrefURI() const override; diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index ab93ddff8a..ffd643124f 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -3727,7 +3727,9 @@ int32_t HTMLMediaElement::TabIndexDefault() nsresult HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::src) { @@ -3769,7 +3771,9 @@ HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, - aValue, aOldValue, aNotify); + aValue, aOldValue, + aMaybeScriptedPrincipal, + aNotify); } nsresult diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index bda9924a6f..9cdc376e82 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -1301,6 +1301,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aMaybeScriptedPrincipal, bool aNotify) override; virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValueOrString& aValue, diff --git a/dom/html/HTMLMenuItemElement.cpp b/dom/html/HTMLMenuItemElement.cpp index 42cee132e6..fbd9377298 100644 --- a/dom/html/HTMLMenuItemElement.cpp +++ b/dom/html/HTMLMenuItemElement.cpp @@ -389,7 +389,9 @@ HTMLMenuItemElement::GetText(nsAString& aText) nsresult HTMLMenuItemElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None) { if ((aName == nsGkAtoms::radiogroup || aName == nsGkAtoms::type) && @@ -412,8 +414,10 @@ HTMLMenuItemElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } - return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, - aOldValue, aNotify); + return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, + aValue, aOldValue, + aSubjectPrincipal, + aNotify); } void diff --git a/dom/html/HTMLMenuItemElement.h b/dom/html/HTMLMenuItemElement.h index 1c738187ce..e3a877a313 100644 --- a/dom/html/HTMLMenuItemElement.h +++ b/dom/html/HTMLMenuItemElement.h @@ -126,6 +126,7 @@ protected: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; void WalkRadioGroup(Visitor* aVisitor); diff --git a/dom/html/HTMLMetaElement.cpp b/dom/html/HTMLMetaElement.cpp index f0a66b52c1..2a07dad968 100644 --- a/dom/html/HTMLMetaElement.cpp +++ b/dom/html/HTMLMetaElement.cpp @@ -61,7 +61,9 @@ HTMLMetaElement::SetMetaReferrer(nsIDocument* aDocument) nsresult HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None) { nsIDocument *document = GetUncomposedDoc(); @@ -82,8 +84,10 @@ HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, } } - return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue, - aOldValue, aNotify); + return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, + aValue, aOldValue, + aSubjectPrincipal, + aNotify); } nsresult diff --git a/dom/html/HTMLMetaElement.h b/dom/html/HTMLMetaElement.h index 649ea11cf1..9fabe36d40 100644 --- a/dom/html/HTMLMetaElement.h +++ b/dom/html/HTMLMetaElement.h @@ -34,6 +34,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName); diff --git a/dom/html/HTMLObjectElement.cpp b/dom/html/HTMLObjectElement.cpp index a77cd6fe57..7dc60949d2 100644 --- a/dom/html/HTMLObjectElement.cpp +++ b/dom/html/HTMLObjectElement.cpp @@ -299,13 +299,16 @@ HTMLObjectElement::UnbindFromTree(bool aDeep, nsresult HTMLObjectElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify); NS_ENSURE_SUCCESS(rv, rv); return nsGenericHTMLFormElement::AfterSetAttr(aNamespaceID, aName, aValue, - aOldValue, aNotify); + aOldValue, aSubjectPrincipal, + aNotify); } nsresult diff --git a/dom/html/HTMLObjectElement.h b/dom/html/HTMLObjectElement.h index 6f0990918f..6c982b2b19 100644 --- a/dom/html/HTMLObjectElement.h +++ b/dom/html/HTMLObjectElement.h @@ -245,6 +245,7 @@ public: virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValue* aValue, const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, bool aNotify) override; virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValueOrString& aValue, diff --git a/dom/html/HTMLOptGroupElement.cpp b/dom/html/HTMLOptGroupElement.cpp index a65a79ecf5..49645ad933 100644 --- a/dom/html/HTMLOptGroupElement.cpp +++ b/dom/html/HTMLOptGroupElement.cpp @@ -106,7 +106,9 @@ HTMLOptGroupElement::RemoveChildAt(uint32_t aIndex, bool aNotify) nsresult HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAttrValue* aValue, - const nsAttrValue* aOldValue, bool aNotify) + const nsAttrValue* aOldValue, + nsIPrincipal* aSubjectPrincipal, + bool aNotify) { if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled) { // All our children