Class: Rack::CsrfDetector
- Inherits:
-
Object
- Object
- Rack::CsrfDetector
- Defined in:
- lib/rack/csrf_detector.rb
Defined Under Namespace
Classes: ActiveRecordInstrument, SidekiqInstrument
Constant Summary collapse
- @@bad_count =
0
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}, &block) ⇒ CsrfDetector
constructor
A new instance of CsrfDetector.
Constructor Details
#initialize(app, opts = {}, &block) ⇒ CsrfDetector
Returns a new instance of CsrfDetector.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rack/csrf_detector.rb', line 5 def initialize(app, opts={}, &block) @app = app require 'rack/csrf_detector/active_record_instrument' require 'rack/csrf_detector/sidekiq_instrument' if block_given? if block.arity == 1 block.call(self) else instance_eval(&block) end end end |
Class Method Details
.more_bad! ⇒ Object
31 32 33 |
# File 'lib/rack/csrf_detector.rb', line 31 def self.more_bad! @@bad_count += 1 end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/csrf_detector.rb', line 20 def call(env) @@bad_count = 0 status, headers, response = @app.call(env) if env['REQUEST_METHOD'] == 'GET' && @@bad_count > 0 headers["CSRF_WARNING"] = 'yes' end [status, headers, response] end |