-
Notifications
You must be signed in to change notification settings - Fork 0
Test CSP with v16 client-side scripts #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22.12.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| v16 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ruby-3.2.2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <%= react_component("HeavyMarkdownEditor", props: @heavy_markdown_editor_props, prerender: true) %> | ||
| <%= react_component("HeavyMarkdownEditor", props: @heavy_markdown_editor_props, prerender: false) %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %> | ||
| <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,25 +1,28 @@ | ||||||
| # Be sure to restart your server when you modify this file. | ||||||
|
|
||||||
| # Define an application-wide content security policy. | ||||||
| # See the Securing Rails Applications Guide for more information: | ||||||
| # https://guides.rubyonrails.org/security.html#content-security-policy-header | ||||||
| # Define an application-wide content security policy | ||||||
| # For further information see the following documentation | ||||||
| # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy | ||||||
|
|
||||||
| # 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.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 | ||||||
|
|
||||||
| # If you are using UJS then enable automatic nonce generation | ||||||
| Rails.application.config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Insecure nonce generation using session ID. Using Apply this diff to use Rails' built-in secure nonce generator: -Rails.application.config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
+Rails.application.config.content_security_policy_nonce_generator = ->(request) { SecureRandom.base64(16) }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # Set the nonce only to specific directives | ||||||
| Rails.application.config.content_security_policy_nonce_directives = %w(script-src style-src) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix style: Use square brackets for The linter suggests using As per coding guidelines. Apply this diff: -Rails.application.config.content_security_policy_nonce_directives = %w(script-src style-src)
+Rails.application.config.content_security_policy_nonce_directives = %w[script-src style-src]📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: lint[failure] 23-23: 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # Report CSP violations to a specified URI | ||||||
| # For further information see the following documentation: | ||||||
| # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only | ||||||
| Rails.application.config.content_security_policy_report_only = true | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overly permissive CSP directives allow any HTTPS resource.
The
:httpssource inscript_srcandstyle_srcallows loading scripts and styles from any HTTPS origin, which significantly weakens CSP protection. An attacker who can inject a reference to a malicious HTTPS resource could bypass the policy.Consider restricting to specific trusted domains or using
'strict-dynamic'with nonces for a more secure approach.Example of a more restrictive policy:
Or if you need to allow specific CDNs:
🤖 Prompt for AI Agents