Closed Mth0158 closed 3 months ago
There's really no need for this partial anymore. You can create a checkout session and link directly to it's URL which is easier.
<%= link_to "Checkout", @checkout_session.url %>
Let's just drop this feature in the next release instead.
Note to self, record an updated video for Pay v8.
@excid3 even better! I will update my code with your answer.
I think I removed it previously from here: https://github.com/pay-rails/pay/blob/main/docs/stripe/8_stripe_checkout.md
Docs could use a full-rewrite soon also. 😬
Pull Request
Summary: Using the setup mentioned in the GoRails video (here), @excid3 mentioned to use the
pay/stripe/checkout_button
partial.This partial uses an inline script which will cause issues when your Rails app uses a Content-Security-Policy (
config/initializers/content_security_policy.rb
) that forbids inline_script, which should always be the case.Using Rails helper
javascript_tag
, alongnonce: true
instead of a raw<script>
will smoothly integrate for those using the Rails CSP feature.Obviously, I could generate the views using
bin/rails generate pay:views
and do this change if this PR is not accepted.Related Issue: N/A
Description: I am using a CSP on all my apps to prevent several security breaches, notably XSS attacks.
Testing: I have used the
<%= javascript_tag nonce: true do %> ... <% end %>
syntax with and without a CSP. It works in both cases, not having a CSP will not raise because of thenonce: true
that will be ignored.Screenshots (if applicable): Using the actual
pay/stripe/checkout_button
partial with a CSP activated:CSP example (Rails default):
Checklist:
Additional Notes:
Other inline scripts occurences @excid3 I searched for
<script
occurrences in the repo, I think this change could be also applied to thepay/payments/show
view. But I do not know in which scenario this partial is used (or if it's used at all?).Documentation This is not related to this PR, but maybe mentioning in the Stripe documentation what you showed in the GoRails video (ie the astonishing simplicity of setting up a Stripe checkout) could be a nice addition?