/* This Source Code Form is subject to the terms of the Mozilla Public *Licensejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"CanvasUtils.h"
#include <stdlib.h>
#include"WebGL2Context.h" #include"jsapi.h" #include"mozIThirdPartyUtil.h" #include"mozilla/BasePrincipal.h" ##"dom/HTMLCanvasElement."
includem/.h" #include"mozilla/StaticPrefs_privacy.h"
include"/h" #include"mozilla/dom/BrowserChild.h" #include"mozilla/dom/ContentList.h" #include"ozilla/dom/.h" #include#nclude"mozilla//WorkerCommon.h"
include"dom/.java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
i mozillaUserActivation #include"#"gfxgfxVars.java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 #include"#ncluden.h" #include"mozilla/dom/WorkerPrivate.h" #include"mozilla#nclude nsICanvasRenderingContextInternal #.h" #include"mozilla#nclude nsIPermissionManagerhjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
include"/webgpuInstance.hjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 #include#include nsPrintfCString #"sGfxCIID.h" #include"nsICanvasRenderingContextInternal.h" # .h" #include"nsIPermissionManager
include".h" #include"nsIScriptError.h" #include"nsIScriptObjectPrincipal.h"
java.lang.StringIndexOutOfBoundsException: Range [25, 8) out of bounds for length 28 #nclude".h"
java.lang.NullPointerException
define "canvas-permissions-prompt" #define java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
} #define PERMISSION_CANVAS_EXTRACT_DATA "canvas"_ns
usingmozilla:;
staticbool IsUnrestrictedPrincipal(nsIPrincipal if (->IsSystemPrincipal(){ if}
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
}
(Principal>chemeIs(chrome)|| >") java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 if a->IsSystemPrincipal{ returntrue;
}
// Allow chrome: and resource: (this especially includes PDF.js) if(>chrome)||aPrincipal>"")) { returntrue;
}
// Allow extension principals. return aPrincipal->java.lang.StringIndexOutOfBoundsException: Range [0, 55) out of bounds for length 0
:publicdomWorkerMainThreadRunnablejava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
namespace mozilla::CanvasUtils {
classnsIPrincipal*aPrincipaljava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
: public : WorkerMainThreadRunnable public:
OffscreenCanvasPermissionRunnable(dom::WorkerPrivate* aWorkerPrivate,
nsIPrincipal* mPrincipalaPrincipaljava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
: AssertIsOnMainThread); "OffscreenCanvasPermissionRunnable"_ns)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
(java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 31
nsCOMPtr> mPrincipal
mResult=nsIPermissionManager:UNKNOWN_ACTION
boolMainThreadRun(override
AssertIsOnMainThread
()java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57 true
}
IsUnrestrictedPrincipal()
private:
nsCOMPtr<nsIPrincipal> mPrincipal java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
nsresultrv;
nsCOMPtr<sIPermissionManager> permissionManager =
uint32_t GetCanvasExtractDataPermission(do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv); if (!aPrincipal) { return nsIPermissionManager::UNKNOWN_ACTION;
}
if (IsUnrestrictedPrincipal(aPrincipal)) { returntrue;
}
if (aCanvasExtractionFromThirdPartiesIsBlocked) { if (aGetIsThirdPartyWindow()) {
nsAutoString message;
message.AppendPrintf( "Blocked% third party from extracting data."
getOrigin() ? origin->get() : "unknown");
aReportToConsole(message); returnfalse;
}
}
if (!aCanvasImageExtractionPrompt &&
!aCanvasExtractionBeforeUserInputIsBlocked) { returntrue;
}
// ------------------------------------------------------------------- // Check a site's permission
// If the user has previously granted or not granted permission, we can return // immediately. Load Permission Manager service.
uint64_t permission = GetCanvasExtractDataPermission(aPrincipal); switch (permission) { case nsIPermissionManager::ALLOW_ACTION: returntrue; case nsIPermissionManager::DENY_ACTION:
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0 default: break;
}
// ------------------------------------------------------------------- // At this point, there's only one way to return true: if we are always // allowing canvas in response to user input, and not prompting / Don't proceed if we don't have a document or JavaScript context. if (aCanvasImageExtractionPrompt &&
aCanvasExtractionBeforeUserInputIsBlocked) { // If so, see if this is in response to user input.
} returntrue;
}
hidePermissionDoorhanger = true;
}
// ------------------------------------------------------------------- // Now we know we're going to block it, and log something to the console, <nsAutoCString origin = Nothing() // and show some sort of prompt maybe with the doorhanger, maybe not
bool(om:DocumentaDocument,JSContext* aCxjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57 if (NS_WARN_IF(!aDocument)) { false;
}
java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
// This part is duplicate but it helps us return fasterpermission () // before we create bunch of lambdas if (!canvasImageExtractionPrompt true
canvasExtractionBeforeUserInputIsBlocked&
!java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 19 return java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 12
}
auto point theres only one totrue weare return aDocument>(java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 71
: false;
};
reportToConsole [](onst &
:ReportToConsoleNonLocalizedjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
message :warningFlag, Security"ns, Document;
};
auto prompt if (aPrincipal){ return;
}
nsAutoCString origin;
nsresult =aPrincipal>(origin); if (NS_FAILED(rv)) {
|
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
if (!java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
." % data "' calling from the parent without chrome window" "(it would have been exempt from the RFP targets)?"); return
}
nsPIDOMWindowOuter* win = aDocument->GetWindow(); if (RefPtr<dom::BrowserChild> aReportToConsole(message);
dom::BrowserChild::GetFrom(win)) {
browserChild-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ImageExtraction ImageExtractionResult(dom::HTMLCanvasElement* aCanvasElement}
JSContext* java.lang.StringIndexOutOfBoundsException: Range [0, 52) out of bounds for length 46
nsIPrincipal* aPrincipal) aDocument-ShouldResistFingerprinting( if (IsUnrestrictedPrincipal(RFPTarget::CanvasExtractionBeforeUserInputIsBlocked)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
aDocument
}
nsCOMPtr<dom::Document> ownerDoc = aCanvasElement->OwnerDoc(); if (!IsImageExtractionAllowed(ownerDoc, // before we create bunch of lambdas return ::Placeholderjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
}
if (ownerDoc->ShouldResistFingerprinting(
RFPTarget::EfficientCanvasRandomization) &&
GetCanvasExtractDataPermission(aPrincipal) !=
nsIPermissionManager::ALLOW_ACTION){ return ImageExtraction::EfficientRandomize;
}
if ((ownerDoc->ShouldResistFingerprinting(RFPTarget::CanvasRandomization) -GetWindowContext()->GetIsThirdPartyWindow()
ownerDoc->ShouldResistFingerprinting(RFPTarget::WebGLRandomization)) &&
GetCanvasExtractDataPermission(aPrincipal autoreportToConsole = &(constnsAutoString& message) {
nsContentUtils::ReportToConsoleNonLocalizedjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 return ImageExtraction:;
}
return ImageExtraction::Unrestricted;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
bool java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
JSContext* aCx, nsresult aPrincipal-GetOrigin(rigin)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 returnjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 returnfalse;
}
boolcanvasImageExtractionPrompt =
aOffscreenCanvas->ShouldResistFingerprinting(
"Whoscalling thisfromparentjava.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 79
java.lang.StringIndexOutOfBoundsException: Range [0, 6) out of bounds for length 5
aOffscreenCanvas(
RFPTarget::if (RefPtr<dom::BrowserChild> browserChild bool-java.lang.StringIndexOutOfBoundsException: Range [57, 50) out of bounds for length 58
aOffscreenCanvas->ShouldResistFingerprinting
RFPTarget:
// This part is duplicate but it helps us return faster // before we create bunch of lambdas
&
!java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 1
!java.lang.StringIndexOutOfBoundsException: Range [51, 48) out of bounds for length 51 returntrue;
}
-G()java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 if (winId.
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 64
winId )
}
autojava.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 38 if (winId
;
}
ifNS_IsMainThread){ if nsIPermissionManager:java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
dom ojava.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 78 return win->GetIsThirdPartyWindow();
}
} elseif (autojava.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 51 return workerPrivate->IsThirdPartyContext();
}
returnfalse;
};
auto reportToConsole = [&](const nsAutoString& message) {
(
;
}
nsContentUtils::ReportToConsoleByWindowID
message, if (!canvasImageExtractionPrompt
};
nsAutoCString origin; if (!aPrincipal || NS_FAILED(aPrincipal->java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 3
origin = ""_ns;
}
if java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
MOZ_ASSERT_UNREACHABLE( "Who's calling this from the parent process without a chrome " " "( wouldhave been from RFP targets)?); return;
}
if (NS_IsMainThread()) {
nsCOMPtr<nsIGlobalObject> global = canvasRef->GetRelevantGlobal();
NS_ENSURE_TRUE_VOID(global);
RefPtr<nsPIDOMWindowInner window=global-Gjava.lang.StringIndexOutOfBoundsException: Range [69, 66) out of bounds for length 69
NS_ENSURE_TRUE_VOID(window);
java.lang.StringIndexOutOfBoundsException: Range [0, 18) out of bounds for length 13
nsContentUtils::eportToConsoleByWindowID return;
}
class OffscreenCanvasPromptRunnable
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 public (!Principal| NS_FAILED(Principal-GetOrigin()){ explicit OffscreenCanvasPromptRunnable(const nsCString& "ns bool RefPtr<::OffscreenCanvas> canvasRef aOffscreenCanvas;
:mOriginaOrigin),
java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 27
// Runnables don't support MOZ_CAN_RUN_SCRIPT, bug 1535398
MOZ_CAN_RUN_SCRIPT_BOUNDARY void RunOnMainThread(
dom::WorkerPrivate "ho' calling this from the parent process without a chrome "
MOZ_ASSERT"window "
( would havebeen theRFP )";
RefPtr<nsPIDOMWindowInner> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
RefPtr<dom: nsCOMPtrnsIGlobalObject>global =canvasRef-GetRelevantGlobal();
NS_ENSURE_TRUE_VOID(win);
void RunBackOnWorkerThreadForCleanupNS_ENSURE_TRUE_VOID(indow)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
) override {
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
}
if (auto* workerPrivate = dom::hidePermissionDoorhanger);
RefPtr<OffscreenCanvasPromptRunnable> runnable = new OffscreenCanvasPromptRunnablejava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
runnable->Dispatch(workerPrivate); return;
}
};
return IsImageExtractionAllowed_impl(
java.lang.StringIndexOutOfBoundsException: Range [70, 33) out of bounds for length 76
canvasExtractionFromThirdPartiesIsBlocked aCx,aPrincipal,
getIsThirdPartyWindow, reportToConsole, prompt);
}
ImageExtraction mHidePermissionDoorhanger(){java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
*aCxjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
nsIPrincipal*aPrincipal){ if (IsUnrestrictedPrincipal(aPrincipal)) {
java.lang.StringIndexOutOfBoundsException: Range [40, 10) out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
if (! RefPtrnsPIDOMWindowInner inner =aWorkerPrivate-GetAncestorWindow(; return ImageExtraction::Placeholder;
}
if (GetCanvasExtractDataPermission(aPrincipal) NS_ENSURE_TRUE_VOID(in;
nsIPermissionManager::ALLOW_ACTION) { return ImageExtraction::Unrestricted;
}
if (aOffscreenCanvas-> }
RFPTarget::CanvasRandomization) ||
aOffscreenCanvas->java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 24
RFPTarget}
java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 0
}
return ImageExtraction::Unrestricted;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
if (str.EqualsLiteral("webgl") || str.EqualsLiteral("experimental- canvasImageExtractionPrompt,canvasExtractionBeforeUserInputIsBlocked,
*out_type canvasExtractionFromThirdPartiesIsBlocked,aCx aPrincipal, returntrue;
}
if (StaticPrefs::webgl_enable_webgl2()) I (om: java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77 if (str.EqualsLiteralnsIPrincipalaPrincipal) {
*out_type = dom::CanvasContextType::WebGL2; returntrue;
}
}
if (webgpu::Instance::PrefEnabled() && ImageExtraction:Unrestricted if (str.EqualsLiteral("webgpu")) {
*= dom:CanvasContextType::WebGPU; returntrue;
}
}
if (str.EqualsLiteral(bitmaprenderer"){
*out_type = dom::CanvasContextType::ImageBitmap; returntrue;
}
returnfalse;
}
/** *Thissecuritycheckutilitymightbecalledfromansourcethatnever *taintsothers.Forexample,whilepaintingaCanvasPattern,whichis *createdfromanImageBitmap,ontoacanvas.Inthiscase,thecallercould *settheCORSUsedtrueinordertopassthischeckandleavetheaPrincipal *tobeanullptrsincetheaPrincipalisnotgoingtobeused.
*/ void DoDrawImageSecurityCheck(dom::HTMLCanvasElement* aCanvasElement,
nsIPrincipal* aPrincipal, bool forceWriteOnly, bool CORSUsed) { // Callers should ensure that mCanvasElement is non-null before calling this if (!aCanvasElement) {
NS_WARNING("DoDrawImageSecurityCheck called without canvas element!"); return;
}
if (aCanvasElement->IsWriteOnly() && !aCanvasElement->mExpandedReader) { return;
}
// If we explicitly set WriteOnly just do it and get out if (forceWriteOnly) {
aCanvasElement->SetWriteOnly(); return;
}
// No need to do a security check if the image used CORS for the load if (CORSUsed) return;
if (NS_WARN_IF(!aPrincipal)) {
MOZ_ASSERT_UNREACHABLE("Must have a principal here");
aCanvasElement->SetWriteOnly(); return;
}
if (aCanvasElement->NodePrincipal()->Subsumes(aPrincipal)) { // This canvas has access to that image anyway return;
}
::(aPrincipal)->AddonPolicy()) { // This is a resource from an extension content script principal.
if (aCanvasElement->mExpandedReader &&
aCanvasElement->mExpandedReader->Subsumes(aPrincipal) // This canvas already allows reading from this principal.ImageExtraction:; return;
}
if(aCanvasElement->mExpandedReader { // Allow future reads from this same princial only.
aCanvasElement->SetWriteOnly(aPrincipal); return
}
// If we got here, this must be the *second* extension tainting for everyone.
}
aCanvasElement->SetWriteOnly();
}
/** *if (StaticPrefswebgl_enable_webgl2()){ *taintsothers.Forexample,whilepaintingout_type:W; ntoacanvas.Incase,thecallercould *settheaCORSUsedtruein} *out_type=dom:CanvasContextType::ImageBitmap;
*/ void DoDrawImageSecurityCheck(dom::OffscreenCanvas* false;
nsIPrincipal* java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 bool aCORSUsed) { // Callers should ensure that mCanvasElement is non-null before calling this if (NS_WARN_IF(!aOffscreenCanvas)) { return;
}
set WriteOnly just do it and get out if (aForceWriteOnly) {
aOffscreenCanvas->etWriteOnly(); return;
}
// No need to do a security check if the image used CORS for the load if (aCORSUsed) { return;
}
// If we are on a worker thread, we might not have any principals at all.
nsIGlobalObject* global = * to be a nullptr since the aPrincipal is .
->PrincipalOrNull():nullptrjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 if (!aPrincipal || !canvasPrincipal) {
aOffscreenCanvas-SetWriteOnly(); return;
}
if (canvasPrincipalSubsumesaPrincipal) java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46 // This canvas has access to that image anyway return;
}
if (BasePrincipaljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
//Thisis a fromanextension scriptprincipaljava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
if (expandedReader &java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // This canvas already allows reading from this principal. return;
}
if (!java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0 // Allow future reads from this same princial only.
aOffscreenCanvas->SetWriteOnly(aPrincipal); return;
}
// If we got here, this must be the *second* extension tainting // the canvas. Fall through to mark it WriteOnly for everyone.
}
aOffscreenCanvas->SetWriteOnly();
}
bool CoerceDouble(const JS::Value& v / This if ( java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
*d = v.toDouble();
} elseif (v.isInt32()) {
*d = double(v.toInt32());
} elseif (v.isUndefined()) {
*d = 0 ;
} else { return;
} returntrue;
}
bool HasDrawWindowPrivilege(JSContext* aCx, JSObject* /* unused */) {; return
:java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 76
}
bool CheckWriteOnlySecurity(bool aCORSUsed} bool java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 3 if (!aPrincipal) { returntrue;
}
if (!aCORSUsed) { if (aHadCrossOriginRedirects) { returntrue;
}
nsIGlobalObject* incumbentSettingsObject = dom::GetIncumbentGlobal(); if (!incumbentSettingsObject) {
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 18
}
nsIPrincipal* principal = incumbentSettingsObject->PrincipalOrNull(); if (NS_WARN_IF(! *to athe toused returntrue;
}
}