mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 19:29:34 +08:00
FEATURE: allow plugins and themes to extend the default CSP (#6704)
* FEATURE: allow plugins and themes to extend the default CSP For plugins: ``` extend_content_security_policy( script_src: ['https://domain.com/script.js', 'https://your-cdn.com/'], style_src: ['https://domain.com/style.css'] ) ``` For themes and components: ``` extend_content_security_policy: type: list default: "script_src:https://domain.com/|style_src:https://domain.com" ``` * clear CSP base url before each test we have a test that stubs `Rails.env.development?` to true * Only allow extending directives that core includes, for now
This commit is contained in:
@ -32,7 +32,9 @@ class Plugin::Instance
|
||||
:locales,
|
||||
:service_workers,
|
||||
:styles,
|
||||
:themes].each do |att|
|
||||
:themes,
|
||||
:csp_extensions,
|
||||
].each do |att|
|
||||
class_eval %Q{
|
||||
def #{att}
|
||||
@#{att} ||= []
|
||||
@ -361,6 +363,10 @@ class Plugin::Instance
|
||||
DiscoursePluginRegistry.register_svg_icon(icon)
|
||||
end
|
||||
|
||||
def extend_content_security_policy(extension)
|
||||
csp_extensions << extension
|
||||
end
|
||||
|
||||
# @option opts [String] :name
|
||||
# @option opts [String] :nativeName
|
||||
# @option opts [String] :fallbackLocale
|
||||
|
Reference in New Issue
Block a user