diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..efdac30 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,17 @@ module ApplicationHelper + def style_tag(content_or_options_with_block = nil, html_options = {}, &block) + content = + if block + html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) + capture(&block) + else + content_or_options_with_block + end + + if html_options[:nonce] == true + html_options[:nonce] = content_security_policy_nonce + end + + content_tag("style", content.html_safe, html_options) + end end diff --git a/app/views/admin/developers_review.html.erb b/app/views/admin/developers_review.html.erb index 4e428e5..23215c2 100644 --- a/app/views/admin/developers_review.html.erb +++ b/app/views/admin/developers_review.html.erb @@ -34,7 +34,7 @@ <%= javascript_include_tag "tinder", "data-turbo-track": "reload" %> <% end %> - +<% end %> diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb index 707c480..d5f56c3 100644 --- a/app/views/admin/index.html.erb +++ b/app/views/admin/index.html.erb @@ -11,7 +11,7 @@ - +<% end %> diff --git a/app/views/admin/review.html.erb b/app/views/admin/review.html.erb index acfb79a..b3bb928 100644 --- a/app/views/admin/review.html.erb +++ b/app/views/admin/review.html.erb @@ -32,7 +32,7 @@ <%= javascript_include_tag "tinder", "data-turbo-track": "reload" %> <% end %> - +<% end %> diff --git a/app/views/auth/create_key.html.erb b/app/views/auth/create_key.html.erb index af16fc2..c6bcef5 100644 --- a/app/views/auth/create_key.html.erb +++ b/app/views/auth/create_key.html.erb @@ -18,7 +18,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/auth/email.html.erb b/app/views/auth/email.html.erb index 1427c02..dce63d0 100644 --- a/app/views/auth/email.html.erb +++ b/app/views/auth/email.html.erb @@ -18,7 +18,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/auth/login.html.erb b/app/views/auth/login.html.erb index ea040fa..1b65118 100644 --- a/app/views/auth/login.html.erb +++ b/app/views/auth/login.html.erb @@ -7,7 +7,7 @@

Don't have an account? Register

@@ -24,7 +24,7 @@
- \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/developers/applications/index.html.erb b/app/views/developers/applications/index.html.erb index fe4b9ea..02c06c4 100644 --- a/app/views/developers/applications/index.html.erb +++ b/app/views/developers/applications/index.html.erb @@ -40,10 +40,10 @@
- \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/developers/applications/request.html.erb b/app/views/developers/applications/request.html.erb index 35a69c9..3c2c0da 100644 --- a/app/views/developers/applications/request.html.erb +++ b/app/views/developers/applications/request.html.erb @@ -25,7 +25,7 @@ <% end %> - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/developers/applications/show.html.erb b/app/views/developers/applications/show.html.erb index 637eb14..0865c0f 100644 --- a/app/views/developers/applications/show.html.erb +++ b/app/views/developers/applications/show.html.erb @@ -163,7 +163,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/device_authorizations/approve.html.erb b/app/views/device_authorizations/approve.html.erb index c94c465..0731766 100644 --- a/app/views/device_authorizations/approve.html.erb +++ b/app/views/device_authorizations/approve.html.erb @@ -29,7 +29,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/device_authorizations/index.html.erb b/app/views/device_authorizations/index.html.erb index aed3274..a28f9b2 100644 --- a/app/views/device_authorizations/index.html.erb +++ b/app/views/device_authorizations/index.html.erb @@ -15,7 +15,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/device_authorizations/success.html.erb b/app/views/device_authorizations/success.html.erb index 3a7b1cf..c76dcb2 100644 --- a/app/views/device_authorizations/success.html.erb +++ b/app/views/device_authorizations/success.html.erb @@ -7,7 +7,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/domains/index.html.erb b/app/views/domains/index.html.erb index ef6aead..2ce8e85 100644 --- a/app/views/domains/index.html.erb +++ b/app/views/domains/index.html.erb @@ -37,7 +37,7 @@ - +<% end %> diff --git a/app/views/domains/request_domain.html.erb b/app/views/domains/request_domain.html.erb index 187ad17..38af0bb 100644 --- a/app/views/domains/request_domain.html.erb +++ b/app/views/domains/request_domain.html.erb @@ -21,7 +21,7 @@ <% end %> - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/doorkeeper/authorizations/new.html.erb b/app/views/doorkeeper/authorizations/new.html.erb index d584d0b..bea38c5 100644 --- a/app/views/doorkeeper/authorizations/new.html.erb +++ b/app/views/doorkeeper/authorizations/new.html.erb @@ -47,7 +47,7 @@ - +<% end %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index e629939..88b8084 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -36,7 +36,7 @@ <%= yield_nested %> - - +<% end %> +<%= javascript_tag nonce: true do %>(function(r,e,b,o,u,n,d){if(r.Rebound)return;d=function(){o="script";u=e.createElement(o);u.type="text/javascript";u.src=b;u.async=true;n=e.getElementsByTagName(o)[0];n.parentNode.insertBefore(u,n)};if(r.attachEvent){r.attachEvent("onload",d)}else{r.addEventListener("load",d,false)}})(window,document,"https://rebound.postmarkapp.com/widget/1.0");<% end %> <% if @developers %> - + <% end %> <% end %> diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index cbd34d2..1b9bc9e 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -2,9 +2,9 @@ - + <% end %> diff --git a/app/views/users/email_verification.html.erb b/app/views/users/email_verification.html.erb index ec97c22..96a5cd4 100644 --- a/app/views/users/email_verification.html.erb +++ b/app/views/users/email_verification.html.erb @@ -18,7 +18,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/users/register.html.erb b/app/views/users/register.html.erb index 4fb23e7..8b9d159 100644 --- a/app/views/users/register.html.erb +++ b/app/views/users/register.html.erb @@ -24,7 +24,7 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/users/settings.html.erb b/app/views/users/settings.html.erb index 71d0aed..4e17125 100644 --- a/app/views/users/settings.html.erb +++ b/app/views/users/settings.html.erb @@ -53,11 +53,11 @@ - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index b3076b3..bb74da5 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -4,22 +4,23 @@ # See the Securing Rails Applications Guide for more information: # https://guides.rubyonrails.org/security.html#content-security-policy-header -# Rails.application.configure do -# config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" -# end -# -# # Generate session nonces for permitted importmap, inline scripts, and inline styles. -# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } -# config.content_security_policy_nonce_directives = %w(script-src style-src) -# -# # Report violations without enforcing the policy. -# # config.content_security_policy_report_only = true -# end +Rails.application.configure do + config.content_security_policy do |policy| + policy.default_src :self, "https://rebound.postmarkapp.com", "https://esm.sh/v135/selectlist-polyfill@0.3.0/es2022/selectlist-polyfill.mjs", "https://ga.jspm.io/npm:local-time@3.0.2/app/assets/javascripts/local-time.es2017-esm.js", "https://esm.sh/selectlist-polyfill@0.3.0" + policy.font_src :self, :data + policy.img_src :self, :data + policy.object_src :none + policy.script_src :self, "https://rebound.postmarkapp.com" + policy.style_src :self, "https://unpkg.com/cursor-chat/dist/style.css" + policy.style_src_attr :self, "'unsafe-inline'" + # Specify URI for violation reports + # policy.report_uri "/csp-violation-report-endpoint" + end + + # Generate session nonces for permitted importmap, inline scripts, and inline styles. + config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } + config.content_security_policy_nonce_directives = %w[script-src style-src] + + # Report violations without enforcing the policy. + config.content_security_policy_report_only = true unless Rails.env.production? +end