Guest User

Untitled

a guest
Dec 23rd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. Parameter filtering in Rails 5
  2.  
  3. As a Rails developer you might be aware of all the password parameter used to be filtered by default by Rails application. What suppose if we need to filter other sensitive information like credit card if we are handling in the application.
  4.  
  5. Rails 4:
  6. config.filter_parameters += [:password]
  7.  
  8. The above scenario password key will be filtered if the params hash has password key whenever you submit a request and even it was filtered recursively. Password used to be filtered for all the below cases.
  9.  
  10. {username: 'abc', password: 'password' }
  11. {user: {name: 'abc', password: 'password' }}
  12. {user: {admin: {name: 'abc', password: 'password' }}}
  13.  
  14. Let me show you about credit card params hash which has credit card number and cvv code.
  15.  
  16. {credit_card: {number: '1234-5678-9123', code: '123'}}
  17.  
  18. config.filter_parameters += [:code]
  19.  
  20. Code filed used to be filterd whenever form submita request. Now we have a situation if any of the other form is having a key called 'code' in their form. Of course that is also to be filterd as usual. Because it was filtered recursively.
  21.  
  22. Rails 5:
  23. {dealer: {name: 'dealer-1', code: 'ZXASAS'}}
  24.  
  25. We do not need to be filtered as it is not a sensitive information like password. We can display as usual like normal params. We can achieve this in Rails 5 by adding following config to your
  26. config/initializers/filter_parameter_logging.rb
  27.  
  28. config.filter_parameters += ["credit_card .code"]
  29.  
  30. Here it was ignored as long as it was part of its parent.
Add Comment
Please, Sign In to add comment