mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 23:52:27 +08:00
FEATURE: allow extending CSP base-uri and object-src
Plus, ensure :none is stripped, it cannot be combined with other sources
This commit is contained in:
@ -4,13 +4,14 @@ require_dependency 'content_security_policy/default'
|
|||||||
class ContentSecurityPolicy
|
class ContentSecurityPolicy
|
||||||
class Builder
|
class Builder
|
||||||
EXTENDABLE_DIRECTIVES = %i[
|
EXTENDABLE_DIRECTIVES = %i[
|
||||||
|
base_uri
|
||||||
|
object_src
|
||||||
script_src
|
script_src
|
||||||
worker_src
|
worker_src
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
# Make extending these directives no-op, until core includes them in default CSP
|
# Make extending these directives no-op, until core includes them in default CSP
|
||||||
TO_BE_EXTENDABLE = %i[
|
TO_BE_EXTENDABLE = %i[
|
||||||
base_uri
|
|
||||||
connect_src
|
connect_src
|
||||||
default_src
|
default_src
|
||||||
font_src
|
font_src
|
||||||
@ -20,7 +21,6 @@ class ContentSecurityPolicy
|
|||||||
img_src
|
img_src
|
||||||
manifest_src
|
manifest_src
|
||||||
media_src
|
media_src
|
||||||
object_src
|
|
||||||
prefetch_src
|
prefetch_src
|
||||||
style_src
|
style_src
|
||||||
].freeze
|
].freeze
|
||||||
@ -65,6 +65,8 @@ class ContentSecurityPolicy
|
|||||||
else
|
else
|
||||||
@directives[directive] << sources
|
@directives[directive] << sources
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@directives[directive].delete(:none) if @directives[directive].count > 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def extendable?(directive)
|
def extendable?(directive)
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
# authors: xrav3nz
|
# authors: xrav3nz
|
||||||
|
|
||||||
extend_content_security_policy(
|
extend_content_security_policy(
|
||||||
script_src: ['https://from-plugin.com']
|
script_src: ['https://from-plugin.com'],
|
||||||
|
object_src: ['https://test-stripping.com']
|
||||||
)
|
)
|
||||||
|
@ -111,6 +111,8 @@ describe ContentSecurityPolicy do
|
|||||||
|
|
||||||
plugin.enabled = true
|
plugin.enabled = true
|
||||||
expect(parse(policy)['script-src']).to include('https://from-plugin.com')
|
expect(parse(policy)['script-src']).to include('https://from-plugin.com')
|
||||||
|
expect(parse(policy)['object-src']).to include('https://test-stripping.com')
|
||||||
|
expect(parse(policy)['object-src']).to_not include("'none'")
|
||||||
|
|
||||||
plugin.enabled = false
|
plugin.enabled = false
|
||||||
expect(parse(policy)['script-src']).to_not include('https://from-plugin.com')
|
expect(parse(policy)['script-src']).to_not include('https://from-plugin.com')
|
||||||
|
Reference in New Issue
Block a user