Move the SCA page's values into Stimulus data attributes - #1274
Merged
Merged
Conversation
The script interpolated the publishable key, the Connect account and two translations directly into JavaScript strings, so a translation with an apostrophe broke the page. Everything the controller needs is now a Stimulus value on the root element, Stripe.js is created in initialize() (value callbacks run before connect), and the script contains no ERB. The back link used URI.parse(params[:back]).path, which raised on a malformed value and dropped a legitimate query string. url_from keeps same-site URLs intact and rejects everything else. The redundant sanitize around link_to and two commented-out asset tags in the layout are gone. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Engine route helpers don't persist across a second request in the same integration test on Rails 7.0, so the external and malformed back-link cases get their own tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
excid3
force-pushed
the
sca-page-stimulus-values
branch
from
September 20, 2026 22:21
bc9ec78 to
3ec3911
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
View.
show.html.erbinterpolated the publishable key, the Connect account, and two translated messages straight into JavaScript string literals. A translation containing an apostrophe would break the script. The values now live on the root element as Stimulus values (publicKey,stripeAccount,nameMissingMessage,confirmedMessage), the controller buildsthis.stripeininitialize()(Stimulus runs value callbacks beforeconnect(), andstatusValueChangedmay callconfirmPaymentimmediately), and the<script>block has no ERB in it at all.window.stripeis gone. Thesanitizearoundlink_todid nothing and is removed.Controller.
URI.parse(params[:back]).pathraisedURI::InvalidURIErroron a malformed value (a 500) and threw away the query string of a legitimate/billing?tab=invoices. Rails 7'surl_fromreturns same-site URLs intact and nil for anything else, so@redirect_to = url_from(params[:back]) || root_pathkeeps the open-redirect protection with less code. With one action and one ivar thebefore_actionis inlined.Layout. Two commented-out asset tags removed.
Apps that copied the payment view with
rails g pay:viewsshould regenerate it; noted in the changelog.Test plan
standardrbclean.🤖 Generated with Claude Code