2018-10-22 13:22:23 -04:00
|
|
|
# frozen_string_literal: true
|
2019-10-02 00:01:53 -04:00
|
|
|
require 'content_security_policy/builder'
|
|
|
|
require 'content_security_policy/extension'
|
2018-10-22 13:22:23 -04:00
|
|
|
|
|
|
|
class ContentSecurityPolicy
|
2018-11-30 09:51:45 -05:00
|
|
|
class << self
|
2020-03-19 15:54:42 -04:00
|
|
|
def policy(theme_ids = [], base_url: Discourse.base_url, path_info: "/")
|
|
|
|
new.build(theme_ids, base_url: base_url, path_info: path_info)
|
2018-10-22 13:22:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-19 15:54:42 -04:00
|
|
|
def build(theme_ids, base_url:, path_info: "/")
|
|
|
|
builder = Builder.new(base_url: base_url)
|
2018-10-22 13:22:23 -04:00
|
|
|
|
2019-02-11 07:32:04 -05:00
|
|
|
Extension.theme_extensions(theme_ids).each { |extension| builder << extension }
|
2018-11-30 09:51:45 -05:00
|
|
|
Extension.plugin_extensions.each { |extension| builder << extension }
|
|
|
|
builder << Extension.site_setting_extension
|
2019-12-30 07:17:12 -05:00
|
|
|
builder << Extension.path_specific_extension(path_info)
|
2018-10-22 13:22:23 -04:00
|
|
|
|
2018-11-30 09:51:45 -05:00
|
|
|
builder.build
|
2018-11-15 12:14:16 -05:00
|
|
|
end
|
2018-10-22 13:22:23 -04:00
|
|
|
end
|
2018-11-30 09:51:45 -05:00
|
|
|
|
|
|
|
CSP = ContentSecurityPolicy
|