Custom CSRF Behavior
Brut allows you to change what POST requested require CSRF. By default, Brut uses Brut::FrontEnd::CsrfProtector which requires CSRF for all POSTs. You can change this as follows:
Create a subclass of
Brut::FrontEnd::CsrfProtector. For simple use-cases, you can put this as an inner class ofApp(inapp/src/app.rb). Here is an example that removers the requirement for/webhooks/to supply a CSRF token:rubyclass App < Brut::Framework::App # ... class CsrfProtector < Brut::FrontEnd::CsrfProtector def allowed?(env) # Brut will call this and # require CSRF if it returns true# env is a Rack env !!env["PATH_INFO"].to_s.match?(/^\/webhooks\//) end end # ... end Tell Brut to use your class instead of the default. Inside the
initializemethod ofApp(inapp/src/app.rb):rubydef initialize # ... Brut.container.override("csrf_protector", CSRFProtector.new) # ... end