Search code examples
sinatracsrf-protection

Enabling CSRF on Sinatra


There seems to be no documentation on how to enable CSRF protection using Rack::Protection in Sinatra for forms. Anyone ever done this? I can't seem to figure out how to tell Sinatra to enable this.


Solution

  • The Sinatra readme says that it's enabled by default. So there is no need to enable it.

    And if you need something like Rack::Protection::AuthenticityToken you can just add this middleware with a use in your config.ru or your main application file.

    example:

    require 'rack/protection'
    use Rack::Protection::AuthenticityToken