2018-10-22 12:22:23 -05:00
|
|
|
# frozen_string_literal: true
|
2018-11-30 08:51:45 -06:00
|
|
|
require_dependency 'content_security_policy/builder'
|
|
|
|
require_dependency 'content_security_policy/extension'
|
2018-10-22 12:22:23 -05:00
|
|
|
|
|
|
|
class ContentSecurityPolicy
|
2018-11-30 08:51:45 -06:00
|
|
|
class << self
|
|
|
|
def policy
|
|
|
|
new.build
|
2018-10-22 12:22:23 -05:00
|
|
|
end
|
|
|
|
|
2018-11-30 08:51:45 -06:00
|
|
|
def base_url
|
|
|
|
@base_url || Discourse.base_url
|
2018-10-22 12:22:23 -05:00
|
|
|
end
|
2018-11-30 08:51:45 -06:00
|
|
|
attr_writer :base_url
|
2018-10-22 12:22:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def build
|
2018-11-30 08:51:45 -06:00
|
|
|
builder = Builder.new
|
2018-10-22 12:22:23 -05:00
|
|
|
|
2018-11-30 08:51:45 -06:00
|
|
|
Extension.theme_extensions.each { |extension| builder << extension }
|
|
|
|
Extension.plugin_extensions.each { |extension| builder << extension }
|
|
|
|
builder << Extension.site_setting_extension
|
2018-10-22 12:22:23 -05:00
|
|
|
|
2018-11-30 08:51:45 -06:00
|
|
|
builder.build
|
2018-11-15 11:14:16 -06:00
|
|
|
end
|
2018-10-22 12:22:23 -05:00
|
|
|
end
|
2018-11-30 08:51:45 -06:00
|
|
|
|
|
|
|
CSP = ContentSecurityPolicy
|