-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Disable content security policy for mailer previews #33483
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
@pixeltrix tagging you since I believe you implemented CSP |
I have a question — should this problem be fixed environment-wise (so, say, we disable CSP for development) or is doing controller-based the right thing? |
@sikachu Do you mean disabling CSP for development across the whole application, or just for the mailer previews? Some teams rely on catching CSP errors during development by having their configuration match on dev and prod. Presently even if the configuration's script_src/style_src is compatible with the assets requested by the mailer previews, the settings for those fields will be overridden by the default block in Rails::ApplicationController. |
I think it would be good to do We're running into this locally, too. |
@rylanb Well, mailer previews are not normally used in production. If for some reason you are, I guess it wouldn't hurt. Here's the monkey patch we're using as a stopgap:
|
Yeah, totally. Seems like maybe just disabling it for mailers is fine. I can't see how the |
Disable content security policy for mailer previews
Apparently, I can’t configure Roadie to inline css in ActionMailer Previews; on the other hand, discussion on rails/rails#33483 shows it won’t be an issue soon.
Rails 5.2 introduced a default
content_security_policy
block toRails::ApplicationController
.Rails::ApplicationController
is required by the MailersController, but any app-defined application_controller is not loaded. This means that regardless of CSP configuration in an app-defined application_controller or content_security_policy.rb initializer, the default CSP values will be included in the response headers for mailer previews.These default CSP header values break certain middleware (e.g., guard-livereload, profilers). To my knowledge there is no benefit to supporting CSP in mailer previews, so maybe we can just disable them there?