From 63739feac33fb1c47ba87b9fd21e239cec1462ff Mon Sep 17 00:00:00 2001 From: Chung-Sheng Fu Date: Wed, 29 Nov 2017 16:55:00 +0200 Subject: [PATCH] Bug 1037335 - Add a pref to enable only within Nightly and Early Beta. r=ckerschb,smaug MozReview-Commit-ID: Bi82dHm53qX --HG-- extra : rebase_source : 61a7c517afb2759d672a1c486213a73ef505a324 extra : amend_source : 572a2c8613fe36ae1ebd613a361bb23acc019912 --- dom/security/nsCSPContext.cpp | 7 +++++++ dom/security/nsCSPContext.h | 2 ++ .../test/csp/test_security_policy_violation_event.html | 5 +++++ dom/webidl/SecurityPolicyViolationEvent.webidl | 3 ++- modules/libpref/init/all.js | 5 +++++ .../base-uri/base-uri_iframe_sandbox.sub.html.ini | 1 + .../report-uri-does-not-respect-base-uri.sub.html.ini | 1 + .../child-src/child-src-worker-blocked.sub.html.ini | 1 + .../connect-src-xmlhttprequest-blocked.sub.html.ini | 1 + .../font-src/font-stylesheet-font-blocked.sub.html.ini | 1 + .../generic/generic-0_1-img-src.html.ini | 1 + .../generic/generic-0_1-script-src.html.ini | 1 + .../generic/generic-0_10_1.sub.html.ini | 1 + .../generic/generic-0_2_2.sub.html.ini | 1 + .../content-security-policy/generic/generic-0_2_3.html.ini | 1 + .../generic/generic-0_8_1.sub.html.ini | 1 + .../media-src/media-src-7_1_2.sub.html.ini | 1 + .../media-src/media-src-7_2_2.sub.html.ini | 1 + .../media-src/media-src-7_3_2.sub.html.ini | 1 + .../media-src/media-src-blocked.sub.html.ini | 1 + .../navigation/to-javascript-url-script-src.html.ini | 1 + ...port-only-sends-reports-on-violation.https.sub.html.ini | 1 + ...api-report-to-overrides-report-uri-1.https.sub.html.ini | 1 + ...api-report-to-overrides-report-uri-2.https.sub.html.ini | 1 + ...rting-api-sends-reports-on-violation.https.sub.html.ini | 1 + .../reporting/securitypolicyviolation-idl.html.ini | 1 + .../script-src/javascript-window-open-blocked.html.ini | 1 + .../script-src/script-src-1_1.html.ini | 1 + .../script-src/script-src-1_10.html.ini | 1 + .../script-src/script-src-1_2.html.ini | 1 + .../script-src/script-src-1_2_1.html.ini | 1 + .../script-src/script-src-1_4.html.ini | 1 + .../script-src/script-src-1_4_1.html.ini | 1 + .../script-src/script-src-1_4_2.html.ini | 1 + ...rt-only-policy-works-with-external-hash-policy.html.ini | 1 + ...-src-report-only-policy-works-with-hash-policy.html.ini | 1 + .../script-src-strict_dynamic_discard_whitelist.html.ini | 1 + ...c-strict_dynamic_double_policy_different_nonce.html.ini | 1 + ...t-src-strict_dynamic_double_policy_report_only.html.ini | 1 + .../script-src/script-src-strict_dynamic_hashes.html.ini | 1 + .../script-src-strict_dynamic_javascript_uri.html.ini | 1 + ...ct_dynamic_non_parser_inserted_incorrect_nonce.html.ini | 1 + .../script-src-strict_dynamic_parser_inserted.html.ini | 1 + .../scripthash-unicode-normalization.sub.html.ini | 1 + .../script-src/scriptnonce-and-scripthash.sub.html.ini | 1 + .../scriptnonce-ignore-unsafeinline.sub.html.ini | 1 + .../securitypolicyviolation/blockeduri-inline.html.ini | 1 + .../securitypolicyviolation/idl.html.ini | 1 + .../img-src-redirect-upgrade-reporting.https.html.ini | 1 + ...ation-block-cross-origin-image-from-script.sub.html.ini | 1 + ...typolicyviolation-block-cross-origin-image.sub.html.ini | 1 + ...itypolicyviolation-block-image-from-script.sub.html.ini | 1 + .../securitypolicyviolation-block-image.sub.html.ini | 1 + .../securitypolicyviolation/targeting.html.ini | 2 +- ...inline-style-allowed-while-cloning-objects.sub.html.ini | 1 + .../style-src/style-src-hash-blocked.html.ini | 1 + .../style-src-injected-inline-style-blocked.html.ini | 1 + .../style-src-injected-stylesheet-blocked.sub.html.ini | 1 + .../style-src-inline-style-attribute-blocked.html.ini | 1 + .../style-src/style-src-inline-style-blocked.html.ini | 1 + ...yle-src-inline-style-nonce-blocked-error-event.html.ini | 1 + .../style-src-inline-style-nonce-blocked.html.ini | 1 + .../style-src/style-src-none-blocked.html.ini | 1 + .../style-src/style-src-stylesheet-nonce-blocked.html.ini | 1 + .../style-src/stylehash-basic-blocked.sub.html.ini | 1 + .../style-src/stylenonce-allowed.sub.html.ini | 1 + .../style-src/stylenonce-blocked.sub.html.ini | 1 + .../svg/object-in-svg-foreignobject.sub.html.ini | 1 + .../content-security-policy/svg/svg-inline.sub.html.ini | 1 + .../script_event_handlers_allowed.html.ini | 1 + ...enied_matching_hash_no_unsafe_inline_attribute.html.ini | 1 + ...script_event_handlers_denied_not_matching_hash.html.ini | 1 + 72 files changed, 88 insertions(+), 2 deletions(-) diff --git a/dom/security/nsCSPContext.cpp b/dom/security/nsCSPContext.cpp index 34bce29005f8..50b7d2b8457b 100644 --- a/dom/security/nsCSPContext.cpp +++ b/dom/security/nsCSPContext.cpp @@ -273,6 +273,7 @@ NS_IMPL_ISUPPORTS_CI(nsCSPContext, nsISerializable) int32_t nsCSPContext::sScriptSampleMaxLength; +bool nsCSPContext::sViolationEventsEnabled = false; nsCSPContext::nsCSPContext() : mInnerWindowID(0) @@ -285,6 +286,8 @@ nsCSPContext::nsCSPContext() Preferences::AddIntVarCache(&sScriptSampleMaxLength, "security.csp.reporting.script-sample.max-length", 40); + Preferences::AddBoolVarCache(&sViolationEventsEnabled, + "security.csp.enable_violation_events"); sInitialized = true; } @@ -1137,6 +1140,10 @@ nsresult nsCSPContext::FireViolationEvent( const mozilla::dom::SecurityPolicyViolationEventInit& aViolationEventInit) { + if (!sViolationEventsEnabled) { + return NS_OK; + } + nsCOMPtr doc = do_QueryReferent(mLoadingContext); if (!doc) { return NS_OK; diff --git a/dom/security/nsCSPContext.h b/dom/security/nsCSPContext.h index 1f63b583b1e2..90e16f99e5ea 100644 --- a/dom/security/nsCSPContext.h +++ b/dom/security/nsCSPContext.h @@ -144,6 +144,8 @@ class nsCSPContext : public nsIContentSecurityPolicy return std::max(sScriptSampleMaxLength, 0); } + static bool sViolationEventsEnabled; + nsString mReferrer; uint64_t mInnerWindowID; // used for web console logging nsTArray mPolicies; diff --git a/dom/security/test/csp/test_security_policy_violation_event.html b/dom/security/test/csp/test_security_policy_violation_event.html index 04034ac8f0b3..db1ae9fa7a13 100644 --- a/dom/security/test/csp/test_security_policy_violation_event.html +++ b/dom/security/test/csp/test_security_policy_violation_event.html @@ -4,6 +4,11 @@