Skip to main content

Go Rails' Stripe lesson and strong params

Rails • Asked by Mark M.
Eab939478a0b68ab4197ed2d849ef428

Hello,

I recently watched the Go Rails Stripe tutorial. In it, Chris creates subscriptions like this:

def create_subscription
  customer = # set customer...
  subscription = # create subscription...

  # Set initial subscription information
  user.update(
    stripe_id:      customer.id,
    card_last4:     params[:last4],
    card_exp_month: params[:exp_month],
    card_exp_year:  params[:exp_year],
    card_brand:     params[:card_brand],
    # ...
  )
end

Is this a secure approach for Rails 5 since we're not using strong params? I'm initially thinking yes (since we're explicitly setting which params can be updated by user.update) but I wanted to double-check with all of you since I'm new to Rails.

Thanks!


Ce795239ba5dd2384fc2f88ffaff5451

Hey Mark,

It's a great question! Here we were skipping strong params. In either case, it'll accept any input the browser sends over. We're explicitly setting columns in this case which is safe.

The problem that strong_params prevents is attackers who add in extra fields into the HTML and submit something like user[admin]=true that you weren't expecting. Strong params makes a whitelist of attributes it will accept, so if you passed in admin, it will ignore it or throw an error.

Since we're explicitly setting a param to a column, it has the same effect. Rails added strong params so you didn't have to manually write all that out every time.


Eab939478a0b68ab4197ed2d849ef428

Thanks for such a detailed response, Chris!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 18,000+ developers who get early access to new screencasts, articles, guides, updates, and more.

By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

More of a social being? We're also on Twitter and YouTube.