A platform for community discussion. Free, open, simple.
FEATURE: Warn admins when Content Security Policy is disabled (#40791)
David Taylor295806c72503
diff --git a/app/models/problem_check.rb b/app/models/problem_check.rbindex a4c3300ade6..4492c095395 100644--- a/app/models/problem_check.rb+++ b/app/models/problem_check.rb@@ -67,6 +67,7 @@ class ProblemCheck#CORE_PROBLEM_CHECKS = [ProblemCheck::BadFaviconUrl,+ ProblemCheck::ContentSecurityPolicyDisabled,ProblemCheck::EmailSendingFailures,ProblemCheck::EmailPollingErroredRecently,ProblemCheck::FacebookConfig,diff --git a/app/services/problem_check/content_security_policy_disabled.rb b/app/services/problem_check/content_security_policy_disabled.rbnew file mode 100644index 00000000000..685d302c456--- /dev/null+++ b/app/services/problem_check/content_security_policy_disabled.rb@@ -0,0 +1,11 @@+# frozen_string_literal: true++class ProblemCheck::ContentSecurityPolicyDisabled < ProblemCheck+ self.priority = "low"++ def call+ return no_problem if SiteSetting.content_security_policy++ problem+ end+enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 5bd5d3f5407..d7fdaa28eb0 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1804,6 +1804,7 @@ en:twitter_login: 'Twitter login appears to not be working at the moment. Check the credentials in <a href="%{base_path}/admin/site_settings/category/login?filter=twitter">the Site Settings</a>.'group_email_credentials: 'There was an issue with the email credentials for the group <a href="%{base_path}/g/%{group_name}/manage/email">%{group_full_name}</a>. No emails will be sent from the group inbox until this problem is addressed. %{error}'upcoming_change_stable_opted_out: 'Your site has opted-out of the "%{upcoming_change}" upcoming change. This change has now reached the "Stable" status and may soon be removed or made permanent. Visit <a href="%{base_path}/admin/config/upcoming-changes">the upcoming changes page</a> to review details about this change.'+ content_security_policy_disabled: "The content-security-policy feature has been disabled. This is an important security feature, and should never be disabled in production environments. <a href='%{base_path}/admin/site_settings/category/all_results?filter=content_security_policy'>Re-enable it here</a>."rails_env: "Your server is running in %{env} mode."host_names: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname."sidekiq_check: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by Sidekiq. Please ensure at least one Sidekiq process is running. <a href="https://github.com/mperham/sidekiq" target="_blank">Learn about Sidekiq here</a>.'diff --git a/spec/services/problem_check/content_security_policy_disabled_spec.rb b/spec/services/problem_check/content_security_policy_disabled_spec.rbnew file mode 100644index 00000000000..c6c9f8ca65b--- /dev/null+++ b/spec/services/problem_check/content_security_policy_disabled_spec.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++RSpec.describe ProblemCheck::ContentSecurityPolicyDisabled do+ subject(:check) { described_class.new }++ describe ".call" do+ before { SiteSetting.stubs(content_security_policy: configured) }++ context "when the content security policy is enabled" do+ let(:configured) { true }++ it { expect(check).to be_chill_about_it }+ end++ context "when the content security policy is disabled" do+ let(:configured) { false }++ it do+ expect(check).to have_a_problem.with_priority("low").with_message(+ I18n.t("dashboard.problem.content_security_policy_disabled", base_path: ""),+ )+ end+ end+ end+end