dom/security: respect security.csp.reporting.enabled in other places

This commit is contained in:
roytam1 2025-02-13 21:00:20 +08:00
commit f59ffe2826

View file

@ -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;
@ -646,8 +648,9 @@ nsCSPContext::GetAllowsInline(CSPDirective aDirective,
keyword, observerTopic) \
case nsIContentSecurityPolicy::VIOLATION_TYPE_ ## violationType : \
PR_BEGIN_MACRO \
if (!mPolicies[p]->allows(directive##_SRC_DIRECTIVE, keyword, nonceOrHash, \
false)) { \
if (CSPService::sCSPReportingEnabled && \
(!mPolicies[p]->allows(directive##_SRC_DIRECTIVE, keyword, nonceOrHash,\
false))) { \
nsAutoString violatedDirective; \
mPolicies[p]->getDirectiveStringForContentType( \
directive##_SRC_DIRECTIVE, violatedDirective); \