From c41c1c63d54d209df18e47cd95cfc3b8f58a2a84 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 18 Feb 2025 09:59:26 +0100 Subject: [PATCH] [DOM] Honor security.csp.reporting.enabled pref in more places. --- dom/security/nsCSPContext.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dom/security/nsCSPContext.cpp b/dom/security/nsCSPContext.cpp index 60cf33aeac..ad9b33bb2e 100644 --- a/dom/security/nsCSPContext.cpp +++ b/dom/security/nsCSPContext.cpp @@ -263,7 +263,7 @@ nsCSPContext::permitsInternal(CSPDirective aDir, // Do not send a report or notify observers if this is a preload - the // decision may be wrong due to the inability to get the nonce, and will // incorrectly fail the unit tests. - if (!aIsPreload && aSendViolationReports) { + if (CSPService::sCSPReportingEnabled && !aIsPreload && aSendViolationReports) { uint32_t lineNumber = 0; uint32_t columnNumber = 0; nsAutoCString spec; @@ -601,13 +601,15 @@ nsCSPContext::GetAllowsInline(CSPDirective aDirective, } nsAutoString violatedDirective; mPolicies[i]->getDirectiveStringForContentType(aDirective, violatedDirective); - reportInlineViolation(aDirective, - aNonce, - aContent, - violatedDirective, - i, - aLineNumber, - aColumnNumber); + if(CSPService::sCSPReportingEnabled) { + reportInlineViolation(aDirective, + aNonce, + aContent, + violatedDirective, + i, + aLineNumber, + aColumnNumber); + } } } return NS_OK; @@ -648,7 +650,8 @@ nsCSPContext::GetAllowsInline(CSPDirective aDirective, PR_BEGIN_MACRO \ static_assert(directive##_SRC_DIRECTIVE == SCRIPT_SRC_DIRECTIVE || \ directive##_SRC_DIRECTIVE == STYLE_SRC_DIRECTIVE); \ - if (!mPolicies[p]->allows(directive##_SRC_DIRECTIVE, keyword, nonceOrHash, \ + if(CSPService::sCSPReportingEnabled && \ + !mPolicies[p]->allows(directive##_SRC_DIRECTIVE, keyword, nonceOrHash, \ false)) { \ nsAutoString violatedDirective; \ mPolicies[p]->getDirectiveStringForContentType( \