mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 16:02:46 +08:00
DEV: Allow CSP nonce_placeholder to be generated outside Rails (#26052)
Sometimes we add scripts outside of Rails. This commit provides a way to generate a nonce placeholder even if you don't have access to an ApplicationController instance.
This commit is contained in:
parent
30a3e21463
commit
d1a2596889
|
@ -66,9 +66,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def csp_nonce_placeholder
|
def csp_nonce_placeholder
|
||||||
response.headers[
|
ContentSecurityPolicy.nonce_placeholder(response.headers)
|
||||||
::Middleware::CspScriptNonceInjector::PLACEHOLDER_HEADER
|
|
||||||
] ||= "[[csp_nonce_placeholder_#{SecureRandom.hex}]]"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def shared_session_key
|
def shared_session_key
|
||||||
|
|
|
@ -7,6 +7,12 @@ class ContentSecurityPolicy
|
||||||
def policy(theme_id = nil, base_url: Discourse.base_url, path_info: "/")
|
def policy(theme_id = nil, base_url: Discourse.base_url, path_info: "/")
|
||||||
new.build(theme_id, base_url: base_url, path_info: path_info)
|
new.build(theme_id, base_url: base_url, path_info: path_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nonce_placeholder(response_headers)
|
||||||
|
response_headers[
|
||||||
|
::Middleware::CspScriptNonceInjector::PLACEHOLDER_HEADER
|
||||||
|
] ||= "[[csp_nonce_placeholder_#{SecureRandom.hex}]]"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(theme_id, base_url:, path_info: "/")
|
def build(theme_id, base_url:, path_info: "/")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user