Issue #2466 - Part 1: Reduce nsContentPolicy type usage.

Use CSPDirective instead, since it directly deals with CSP anyway.
This cleanup prepares for the following changes.
This commit is contained in:
Moonchild 2024-02-04 00:33:43 +01:00 • committed by roytam1
commit 4ea2206c15
10 changed files with 43 additions and 105 deletions

View file

@ -796,7 +796,7 @@ EventListenerManager::SetEventHandler(nsIAtom* aName,
if (csp) { if (csp) {
bool allowsInlineScript = true; bool allowsInlineScript = true;
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_SCRIPT, rv = csp->GetAllowsInline(nsIContentSecurityPolicy::SCRIPT_SRC_DIRECTIVE,
EmptyString(), // aNonce EmptyString(), // aNonce
true, // aParserCreated (true because attribute event handler) true, // aParserCreated (true because attribute event handler)
aBody, aBody,

View file

@ -146,7 +146,7 @@ interface nsIContentSecurityPolicy : nsISerializable
* Whether or not the effects of the inline style should be allowed * Whether or not the effects of the inline style should be allowed
* (block the rules if false). * (block the rules if false).
*/ */
boolean getAllowsInline(in nsContentPolicyType aContentPolicyType, boolean getAllowsInline(in CSPDirective aContentPolicyType,
in AString aNonce, in AString aNonce,
in boolean aParserCreated, in boolean aParserCreated,
in AString aContent, in AString aContent,

View file

@ -180,7 +180,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (csp) { if (csp) {
bool allowsInlineScript = true; bool allowsInlineScript = true;
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_SCRIPT, rv = csp->GetAllowsInline(nsIContentSecurityPolicy::SCRIPT_SRC_DIRECTIVE,
EmptyString(), // aNonce EmptyString(), // aNonce
true, // aParserCreated true, // aParserCreated
EmptyString(), // aContent EmptyString(), // aContent

View file

@ -1471,7 +1471,7 @@ CSPAllowsInlineScript(nsIScriptElement *aElement, nsIDocument *aDocument)
aElement->GetScriptText(scriptText); aElement->GetScriptText(scriptText);
bool allowInlineScript = false; bool allowInlineScript = false;
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_SCRIPT, rv = csp->GetAllowsInline(nsIContentSecurityPolicy::SCRIPT_SRC_DIRECTIVE,
nonce, parserCreated, scriptText, nonce, parserCreated, scriptText,
aElement->GetScriptLineNumber(), aElement->GetScriptLineNumber(),
aElement->GetScriptColumnNumber(), aElement->GetScriptColumnNumber(),

View file

@ -469,7 +469,7 @@ nsCSPContext::GetAllowsEval(bool* outShouldReportViolation,
*outAllowsEval = true; *outAllowsEval = true;
for (uint32_t i = 0; i < mPolicies.Length(); i++) { for (uint32_t i = 0; i < mPolicies.Length(); i++) {
if (!mPolicies[i]->allows(nsIContentPolicy::TYPE_SCRIPT, if (!mPolicies[i]->allows(SCRIPT_SRC_DIRECTIVE,
CSP_UNSAFE_EVAL, CSP_UNSAFE_EVAL,
EmptyString(), EmptyString(),
false)) { false)) {
@ -486,7 +486,7 @@ nsCSPContext::GetAllowsEval(bool* outShouldReportViolation,
// Helper function to report inline violations // Helper function to report inline violations
void void
nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType, nsCSPContext::reportInlineViolation(CSPDirective aDirective,
const nsAString& aNonce, const nsAString& aNonce,
const nsAString& aContent, const nsAString& aContent,
const nsAString& aViolatedDirective, const nsAString& aViolatedDirective,
@ -499,12 +499,12 @@ nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType,
// let's report the hash error; no need to report the unsafe-inline error // let's report the hash error; no need to report the unsafe-inline error
// anymore. // anymore.
if (!aNonce.IsEmpty()) { if (!aNonce.IsEmpty()) {
observerSubject = (aContentType == nsIContentPolicy::TYPE_SCRIPT) observerSubject = (aDirective == SCRIPT_SRC_DIRECTIVE)
? NS_LITERAL_STRING(SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC) ? NS_LITERAL_STRING(SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC)
: NS_LITERAL_STRING(STYLE_NONCE_VIOLATION_OBSERVER_TOPIC); : NS_LITERAL_STRING(STYLE_NONCE_VIOLATION_OBSERVER_TOPIC);
} }
else { else {
observerSubject = (aContentType == nsIContentPolicy::TYPE_SCRIPT) observerSubject = (aDirective == SCRIPT_SRC_DIRECTIVE)
? NS_LITERAL_STRING(SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC) ? NS_LITERAL_STRING(SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC)
: NS_LITERAL_STRING(STYLE_HASH_VIOLATION_OBSERVER_TOPIC); : NS_LITERAL_STRING(STYLE_HASH_VIOLATION_OBSERVER_TOPIC);
} }
@ -555,7 +555,7 @@ nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType, nsCSPContext::GetAllowsInline(CSPDirective aDirective,
const nsAString& aNonce, const nsAString& aNonce,
bool aParserCreated, bool aParserCreated,
const nsAString& aContent, const nsAString& aContent,
@ -565,11 +565,7 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
{ {
*outAllowsInline = true; *outAllowsInline = true;
MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType), if (aDirective != SCRIPT_SRC_DIRECTIVE && aDirective != STYLE_SRC_DIRECTIVE) {
"We should only see external content policy types here.");
if (aContentType != nsIContentPolicy::TYPE_SCRIPT &&
aContentType != nsIContentPolicy::TYPE_STYLESHEET) {
MOZ_ASSERT(false, "can only allow inline for script or style"); MOZ_ASSERT(false, "can only allow inline for script or style");
return NS_OK; return NS_OK;
} }
@ -577,8 +573,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
// always iterate all policies, otherwise we might not send out all reports // always iterate all policies, otherwise we might not send out all reports
for (uint32_t i = 0; i < mPolicies.Length(); i++) { for (uint32_t i = 0; i < mPolicies.Length(); i++) {
bool allowed = bool allowed =
mPolicies[i]->allows(aContentType, CSP_UNSAFE_INLINE, EmptyString(), aParserCreated) || mPolicies[i]->allows(aDirective, CSP_UNSAFE_INLINE, EmptyString(), aParserCreated) ||
mPolicies[i]->allows(aContentType, CSP_NONCE, aNonce, aParserCreated); mPolicies[i]->allows(aDirective, CSP_NONCE, aNonce, aParserCreated);
// If the inlined script or style is allowed by either unsafe-inline or the // If the inlined script or style is allowed by either unsafe-inline or the
// nonce, go ahead and shortcut this loop. // nonce, go ahead and shortcut this loop.
@ -589,7 +585,7 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
// Check if the csp-hash matches against the hash of the script. // Check if the csp-hash matches against the hash of the script.
// If we don't have any content to check, block the script. // If we don't have any content to check, block the script.
if (!aContent.IsEmpty()) { if (!aContent.IsEmpty()) {
allowed = mPolicies[i]->allows(aContentType, CSP_HASH, aContent, aParserCreated); allowed = mPolicies[i]->allows(aDirective, CSP_HASH, aContent, aParserCreated);
} }
if (!allowed) { if (!allowed) {
@ -599,8 +595,8 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
*outAllowsInline = false; *outAllowsInline = false;
} }
nsAutoString violatedDirective; nsAutoString violatedDirective;
mPolicies[i]->getDirectiveStringForContentType(aContentType, violatedDirective); mPolicies[i]->getDirectiveStringForContentType(aDirective, violatedDirective);
reportInlineViolation(aContentType, reportInlineViolation(aDirective,
aNonce, aNonce,
aContent, aContent,
violatedDirective, violatedDirective,
@ -641,17 +637,17 @@ nsCSPContext::GetAllowsInline(nsContentPolicyType aContentType,
* GetAllowsInline() and do not call this macro, hence we can pass 'false' * GetAllowsInline() and do not call this macro, hence we can pass 'false'
* as the argument _aParserCreated_ to allows(). * as the argument _aParserCreated_ to allows().
*/ */
#define CASE_CHECK_AND_REPORT(violationType, contentPolicyType, nonceOrHash, \ #define CASE_CHECK_AND_REPORT(violationType, directive, nonceOrHash, \
keyword, observerTopic) \ keyword, observerTopic) \
case nsIContentSecurityPolicy::VIOLATION_TYPE_ ## violationType : \ case nsIContentSecurityPolicy::VIOLATION_TYPE_ ## violationType : \
PR_BEGIN_MACRO \ PR_BEGIN_MACRO \
if (!mPolicies[p]->allows(nsIContentPolicy::TYPE_ ## contentPolicyType, \ static_assert(directive##_SRC_DIRECTIVE == SCRIPT_SRC_DIRECTIVE || \
keyword, nonceOrHash, false)) \ directive##_SRC_DIRECTIVE == STYLE_SRC_DIRECTIVE); \
{ \ if (!mPolicies[p]->allows(directive##_SRC_DIRECTIVE, keyword, nonceOrHash, \
false)) { \
nsAutoString violatedDirective; \ nsAutoString violatedDirective; \
mPolicies[p]->getDirectiveStringForContentType( \ mPolicies[p]->getDirectiveStringForContentType( \
nsIContentPolicy::TYPE_ ## contentPolicyType, \ directive##_SRC_DIRECTIVE, violatedDirective); \
violatedDirective); \
this->AsyncReportViolation(selfISupports, nullptr, violatedDirective, p, \ this->AsyncReportViolation(selfISupports, nullptr, violatedDirective, p, \
NS_LITERAL_STRING(observerTopic), aSourceFile,\ NS_LITERAL_STRING(observerTopic), aSourceFile,\
aScriptSample, aLineNum, aColumnNum); \ aScriptSample, aLineNum, aColumnNum); \
@ -711,19 +707,19 @@ nsCSPContext::LogViolationDetails(uint16_t aViolationType,
switch (aViolationType) { switch (aViolationType) {
CASE_CHECK_AND_REPORT(EVAL, SCRIPT, NS_LITERAL_STRING(""), CASE_CHECK_AND_REPORT(EVAL, SCRIPT, NS_LITERAL_STRING(""),
CSP_UNSAFE_EVAL, EVAL_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_EVAL, EVAL_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(INLINE_STYLE, STYLESHEET, NS_LITERAL_STRING(""), CASE_CHECK_AND_REPORT(INLINE_STYLE, STYLE, NS_LITERAL_STRING(""),
CSP_UNSAFE_INLINE, INLINE_STYLE_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, INLINE_STYLE_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(INLINE_SCRIPT, SCRIPT, NS_LITERAL_STRING(""), CASE_CHECK_AND_REPORT(INLINE_SCRIPT, SCRIPT, NS_LITERAL_STRING(""),
CSP_UNSAFE_INLINE, INLINE_SCRIPT_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, INLINE_SCRIPT_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(NONCE_SCRIPT, SCRIPT, aNonce, CASE_CHECK_AND_REPORT(NONCE_SCRIPT, SCRIPT, aNonce,
CSP_UNSAFE_INLINE, SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, SCRIPT_NONCE_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(NONCE_STYLE, STYLESHEET, aNonce, CASE_CHECK_AND_REPORT(NONCE_STYLE, STYLE, aNonce,
CSP_UNSAFE_INLINE, STYLE_NONCE_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, STYLE_NONCE_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(HASH_SCRIPT, SCRIPT, aContent, CASE_CHECK_AND_REPORT(HASH_SCRIPT, SCRIPT, aContent,
CSP_UNSAFE_INLINE, SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, SCRIPT_HASH_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(HASH_STYLE, STYLESHEET, aContent, CASE_CHECK_AND_REPORT(HASH_STYLE, STYLE, aContent,
CSP_UNSAFE_INLINE, STYLE_HASH_VIOLATION_OBSERVER_TOPIC); CSP_UNSAFE_INLINE, STYLE_HASH_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(REQUIRE_SRI_FOR_STYLE, STYLESHEET, NS_LITERAL_STRING(""), CASE_CHECK_AND_REPORT(REQUIRE_SRI_FOR_STYLE, STYLE, NS_LITERAL_STRING(""),
CSP_REQUIRE_SRI_FOR, REQUIRE_SRI_STYLE_VIOLATION_OBSERVER_TOPIC); CSP_REQUIRE_SRI_FOR, REQUIRE_SRI_STYLE_VIOLATION_OBSERVER_TOPIC);
CASE_CHECK_AND_REPORT(REQUIRE_SRI_FOR_SCRIPT, SCRIPT, NS_LITERAL_STRING(""), CASE_CHECK_AND_REPORT(REQUIRE_SRI_FOR_SCRIPT, SCRIPT, NS_LITERAL_STRING(""),
CSP_REQUIRE_SRI_FOR, REQUIRE_SRI_SCRIPT_VIOLATION_OBSERVER_TOPIC); CSP_REQUIRE_SRI_FOR, REQUIRE_SRI_SCRIPT_VIOLATION_OBSERVER_TOPIC);

View file

@ -133,7 +133,7 @@ class nsCSPContext : public nsIContentSecurityPolicy
bool aParserCreated); bool aParserCreated);
// helper to report inline script/style violations // helper to report inline script/style violations
void reportInlineViolation(nsContentPolicyType aContentType, void reportInlineViolation(CSPDirective aDirective,
const nsAString& aNonce, const nsAString& aNonce,
const nsAString& aContent, const nsAString& aContent,
const nsAString& aViolatedDirective, const nsAString& aViolatedDirective,

View file

@ -1225,16 +1225,6 @@ nsCSPDirective::toDomCSPStruct(mozilla::dom::CSP& outCSP) const
} }
bool
nsCSPDirective::restrictsContentType(nsContentPolicyType aContentType) const
{
// make sure we do not check for the default src before any other sources
if (isDefaultDirective()) {
return false;
}
return mDirective == CSP_ContentTypeToDirective(aContentType);
}
void void
nsCSPDirective::getReportURIs(nsTArray<nsString> &outReportURIs) const nsCSPDirective::getReportURIs(nsTArray<nsString> &outReportURIs) const
{ {
@ -1284,19 +1274,6 @@ nsCSPChildSrcDirective::~nsCSPChildSrcDirective()
{ {
} }
bool nsCSPChildSrcDirective::restrictsContentType(nsContentPolicyType aContentType) const
{
if (aContentType == nsIContentPolicy::TYPE_SUBDOCUMENT) {
return mRestrictFrames;
}
if (aContentType == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
aContentType == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER ||
aContentType == nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER) {
return mRestrictWorkers;
}
return false;
}
bool nsCSPChildSrcDirective::equals(CSPDirective aDirective) const bool nsCSPChildSrcDirective::equals(CSPDirective aDirective) const
{ {
if (aDirective == nsIContentSecurityPolicy::FRAME_SRC_DIRECTIVE) { if (aDirective == nsIContentSecurityPolicy::FRAME_SRC_DIRECTIVE) {
@ -1320,16 +1297,6 @@ nsCSPScriptSrcDirective::~nsCSPScriptSrcDirective()
{ {
} }
bool nsCSPScriptSrcDirective::restrictsContentType(nsContentPolicyType aContentType) const
{
if (aContentType == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
aContentType == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER ||
aContentType == nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER) {
return mRestrictWorkers;
}
return mDirective == CSP_ContentTypeToDirective(aContentType);
}
bool nsCSPScriptSrcDirective::equals(CSPDirective aDirective) const bool nsCSPScriptSrcDirective::equals(CSPDirective aDirective) const
{ {
if (aDirective == nsIContentSecurityPolicy::WORKER_SRC_DIRECTIVE) { if (aDirective == nsIContentSecurityPolicy::WORKER_SRC_DIRECTIVE) {
@ -1464,15 +1431,6 @@ nsCSPPolicy::~nsCSPPolicy()
} }
} }
bool
nsCSPPolicy::permits(CSPDirective aDir,
nsIURI* aUri,
bool aSpecific) const
{
nsString outp;
return this->permits(aDir, aUri, EmptyString(), false, aSpecific, false, outp);
}
bool bool
nsCSPPolicy::permits(CSPDirective aDir, nsCSPPolicy::permits(CSPDirective aDir,
nsIURI* aUri, nsIURI* aUri,
@ -1526,7 +1484,7 @@ nsCSPPolicy::permits(CSPDirective aDir,
} }
bool bool
nsCSPPolicy::allows(nsContentPolicyType aContentType, nsCSPPolicy::allows(CSPDirective aDirective,
enum CSPKeyword aKeyword, enum CSPKeyword aKeyword,
const nsAString& aHashOrNonce, const nsAString& aHashOrNonce,
bool aParserCreated) const bool aParserCreated) const
@ -1538,15 +1496,16 @@ nsCSPPolicy::allows(nsContentPolicyType aContentType,
// Try to find a matching directive // Try to find a matching directive
for (uint32_t i = 0; i < mDirectives.Length(); i++) { for (uint32_t i = 0; i < mDirectives.Length(); i++) {
if (mDirectives[i]->restrictsContentType(aContentType)) { if (mDirectives[i]->isDefaultDirective()) {
defaultDir = mDirectives[i];
continue;
}
if (mDirectives[i]->equals(aDirective)) {
if (mDirectives[i]->allows(aKeyword, aHashOrNonce, aParserCreated)) { if (mDirectives[i]->allows(aKeyword, aHashOrNonce, aParserCreated)) {
return true; return true;
} }
return false; return false;
} }
if (mDirectives[i]->isDefaultDirective()) {
defaultDir = mDirectives[i];
}
} }
// {nonce,hash}-source should not consult default-src: // {nonce,hash}-source should not consult default-src:
@ -1573,13 +1532,6 @@ nsCSPPolicy::allows(nsContentPolicyType aContentType,
return true; return true;
} }
bool
nsCSPPolicy::allows(nsContentPolicyType aContentType,
enum CSPKeyword aKeyword) const
{
return allows(aContentType, aKeyword, NS_LITERAL_STRING(""), false);
}
void void
nsCSPPolicy::toString(nsAString& outStr) const nsCSPPolicy::toString(nsAString& outStr) const
{ {
@ -1634,17 +1586,18 @@ nsCSPPolicy::hasDirective(CSPDirective aDir) const
* for the ::permits() function family. * for the ::permits() function family.
*/ */
void void
nsCSPPolicy::getDirectiveStringForContentType(nsContentPolicyType aContentType, nsCSPPolicy::getDirectiveStringForContentType(CSPDirective aDirective,
nsAString& outDirective) const nsAString& outDirective) const
{ {
nsCSPDirective* defaultDir = nullptr; nsCSPDirective* defaultDir = nullptr;
for (uint32_t i = 0; i < mDirectives.Length(); i++) { for (uint32_t i = 0; i < mDirectives.Length(); i++) {
if (mDirectives[i]->restrictsContentType(aContentType)) {
mDirectives[i]->getDirName(outDirective);
return;
}
if (mDirectives[i]->isDefaultDirective()) { if (mDirectives[i]->isDefaultDirective()) {
defaultDir = mDirectives[i]; defaultDir = mDirectives[i];
continue;
}
if (mDirectives[i]->equals(aDirective)) {
mDirectives[i]->getDirName(outDirective);
return;
} }
} }
// if we haven't found a matching directive yet, // if we haven't found a matching directive yet,

View file

@ -483,8 +483,6 @@ class nsCSPDirective {
virtual void addSrcs(const nsTArray<nsCSPBaseSrc*>& aSrcs) virtual void addSrcs(const nsTArray<nsCSPBaseSrc*>& aSrcs)
{ mSrcs = aSrcs; } { mSrcs = aSrcs; }
virtual bool restrictsContentType(nsContentPolicyType aContentType) const;
inline bool isDefaultDirective() const inline bool isDefaultDirective() const
{ return mDirective == nsIContentSecurityPolicy::DEFAULT_SRC_DIRECTIVE; } { return mDirective == nsIContentSecurityPolicy::DEFAULT_SRC_DIRECTIVE; }
@ -520,8 +518,6 @@ class nsCSPChildSrcDirective : public nsCSPDirective {
void setRestrictWorkers() void setRestrictWorkers()
{ mRestrictWorkers = true; } { mRestrictWorkers = true; }
virtual bool restrictsContentType(nsContentPolicyType aContentType) const;
virtual bool equals(CSPDirective aDirective) const; virtual bool equals(CSPDirective aDirective) const;
private: private:
@ -544,8 +540,6 @@ class nsCSPScriptSrcDirective : public nsCSPDirective {
void setRestrictWorkers() void setRestrictWorkers()
{ mRestrictWorkers = true; } { mRestrictWorkers = true; }
virtual bool restrictsContentType(nsContentPolicyType aContentType) const;
virtual bool equals(CSPDirective aDirective) const; virtual bool equals(CSPDirective aDirective) const;
private: private:
@ -668,15 +662,10 @@ class nsCSPPolicy {
bool aSpecific, bool aSpecific,
bool aParserCreated, bool aParserCreated,
nsAString& outViolatedDirective) const; nsAString& outViolatedDirective) const;
bool permits(CSPDirective aDir, bool allows(CSPDirective aDirective,
nsIURI* aUri,
bool aSpecific) const;
bool allows(nsContentPolicyType aContentType,
enum CSPKeyword aKeyword, enum CSPKeyword aKeyword,
const nsAString& aHashOrNonce, const nsAString& aHashOrNonce,
bool aParserCreated) const; bool aParserCreated) const;
bool allows(nsContentPolicyType aContentType,
enum CSPKeyword aKeyword) const;
void toString(nsAString& outStr) const; void toString(nsAString& outStr) const;
void toDomCSPStruct(mozilla::dom::CSP& outCSP) const; void toDomCSPStruct(mozilla::dom::CSP& outCSP) const;
@ -708,7 +697,7 @@ class nsCSPPolicy {
void getReportURIs(nsTArray<nsString> &outReportURIs) const; void getReportURIs(nsTArray<nsString> &outReportURIs) const;
void getDirectiveStringForContentType(nsContentPolicyType aContentType, void getDirectiveStringForContentType(CSPDirective aDirective,
nsAString& outDirective) const; nsAString& outDirective) const;
void getDirectiveAsString(CSPDirective aDir, nsAString& outDirective) const; void getDirectiveAsString(CSPDirective aDir, nsAString& outDirective) const;

View file

@ -215,7 +215,7 @@ function run_test() {
function(csp) { function(csp) {
var uri = NetUtil var uri = NetUtil
// shouldLoad creates and sends out the report here. // shouldLoad creates and sends out the report here.
csp.shouldLoad(Ci.nsIContentPolicy.TYPE_SCRIPT, csp.shouldLoad(Ci.nsIContentSecurityPolicy.SCRIPT_SRC_DIRECTIVE,
NetUtil.newURI(selfSpec + "#bar"), NetUtil.newURI(selfSpec + "#bar"),
null, null, null, null); null, null, null, null);
}); });
@ -224,7 +224,7 @@ function run_test() {
makeTest(8, {"blocked-uri": "ftp://blocked.test"}, false, makeTest(8, {"blocked-uri": "ftp://blocked.test"}, false,
function(csp) { function(csp) {
// shouldLoad creates and sends out the report here. // shouldLoad creates and sends out the report here.
csp.shouldLoad(Ci.nsIContentPolicy.TYPE_SCRIPT, csp.shouldLoad(Ci.nsIContentSecurityPolicy.SCRIPT_SRC_DIRECTIVE,
NetUtil.newURI("ftp://blocked.test/profile.png"), NetUtil.newURI("ftp://blocked.test/profile.png"),
null, null, null, null); null, null, null, null);
}); });

View file

@ -774,7 +774,7 @@ nsStyleUtil::CSPAllowsInlineStyle(nsIContent* aContent,
} }
bool allowInlineStyle = true; bool allowInlineStyle = true;
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_STYLESHEET, rv = csp->GetAllowsInline(nsIContentSecurityPolicy::STYLE_SRC_DIRECTIVE,
nonce, nonce,
false, // aParserCreated only applies to scripts false, // aParserCreated only applies to scripts
aStyleText, aLineNumber, aColumnNumber, aStyleText, aLineNumber, aColumnNumber,