How to secure code against sql injection on Ruby-sinatra

Hi,

I would like to put a security through Ruby-sinatra code.
Do exist the specific gem to install in order to secure the code ?
Thanks by advance.

Supelec

Why don’t you just use ActiveRecord?

Here are the steps to setup ActiveRecord:

I’m suggesting active record because it’s used by a lot of people and it’s tested against SQL injection.

To keep things safe, I also suggest you updating this gem on gemfile once it’s updated!

  1. Use param_hash instead of using params hash
    Using param_hash will prevent SQL Injection attack. I had seen this in some popular websites like facebook.com etc.
  2. Sinatra uses Rack::MockRequest to handle your request. You can use this mock request to check if parameters are passed correctly or not.
    mock_request rack::mock_request()
    response mock_request.get(‘/’, {‘a’: ‘b’})
    If its false then something went wrong from client side.

Hello,

Thank you for your help !

I will implement the test.

Best regards,

Supelec

Hello,

Thank you very much for your suggestion.

Best regards,

Supelec

1 Like