-
Notifications
You must be signed in to change notification settings - Fork 26
Demonstrate that ReactOnRails client-side rendering script CSP compatibility #66
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -233,6 +233,7 @@ GEM | |
|
|
||
| PLATFORMS | ||
| x86_64-darwin-22 | ||
| x86_64-darwin-23 | ||
| x86_64-linux | ||
|
|
||
| DEPENDENCIES | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| <h1>Hello, World!</h1> | ||
| <%= 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,25 +4,25 @@ | |||||
| # For further information see the following documentation | ||||||
| # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy | ||||||
|
|
||||||
| # 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 | ||||||
| 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 | ||||||
| # 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 { SecureRandom.base64(16) } | ||||||
| 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: Session ID as CSP nonce is a major security vulnerability. Using
An attacker who obtains the session ID (through XSS, session fixation, network sniffing, etc.) can inject inline scripts/styles that will bypass CSP validation. Apply this fix to use a cryptographically secure random nonce: -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) | ||||||
| Rails.application.config.content_security_policy_nonce_directives = %w(script-src style-src) | ||||||
|
|
||||||
| # 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 | ||||||
| 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 policy weakens security guarantees.
The
:httpsdirective inscript-srcandstyle-srcallows loading scripts and styles from any HTTPS source, which significantly undermines CSP protection. If an attacker can control any HTTPS URL referenced in your application (e.g., through URL parameters, user input, or compromised third-party sources), they can bypass CSP.Consider one of these approaches:
:httpsand rely solely on nonces (once the nonce generator is fixed):📝 Committable suggestion