Class: Rack::CsrfDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/csrf_detector.rb

Constant Summary collapse

@@bad_count =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CsrfDetector

Returns a new instance of CsrfDetector.



5
6
7
8
# File 'lib/rack/csrf_detector.rb', line 5

def initialize(app)
  @app = app
  🙉_activerecord!
end

Class Method Details

.more_bad!Object



21
22
23
# File 'lib/rack/csrf_detector.rb', line 21

def self.more_bad!
  @@bad_count += 1
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/csrf_detector.rb', line 10

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