rack-csrf-detector 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa4ba5ae22cdd0b48bce43cb38428101a2aefa77
|
4
|
+
data.tar.gz: 0885fd8ab62bc67a1a838f63a5fe70023602d737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf54867a0be468b15e0b78ee83eb02dd8220169eaa71dae2bfa3b7c8e21d5fdcb98ba44eb3a519de24ef3a98a72ec275744c64be0750aa1d31525f1874b77e3d
|
7
|
+
data.tar.gz: 713f5e6db6d30e829bdc50f038525b28dd45e3f90d0974792e8ea7707d39ac710c962eb170b90e5e56b7f2dc03dbc9841607e1d1fcd15aadd1e3710148dfff99
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract/transaction'
|
2
|
+
|
3
|
+
class Rack::CsrfDetector::ActiveRecordInstrument
|
4
|
+
def use!
|
5
|
+
if ActiveRecord::VERSION::STRING.match(/^4.2/)
|
6
|
+
🙉_activerecord_4_2!
|
7
|
+
else
|
8
|
+
🙉_activerecord_4_0!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def 🙉_activerecord_4_0!
|
15
|
+
ActiveRecord::ConnectionAdapters::OpenTransaction.class_eval do
|
16
|
+
commit_method = instance_method(:commit)
|
17
|
+
|
18
|
+
define_method :commit do
|
19
|
+
Rack::CsrfDetector.more_bad!
|
20
|
+
commit_method.bind(self).call
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def 🙉_activerecord_4_2!
|
26
|
+
ActiveRecord::ConnectionAdapters::Transaction.class_eval do
|
27
|
+
commit_method = instance_method(:commit)
|
28
|
+
|
29
|
+
define_method :commit do
|
30
|
+
Rack::CsrfDetector.more_bad!
|
31
|
+
commit_method.bind(self).call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
class Rack::CsrfDetector::SidekiqInstrument
|
4
|
+
def use!
|
5
|
+
Sidekiq.configure_client do |config|
|
6
|
+
config.client_middleware do |chain|
|
7
|
+
chain.add Middleware
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Middleware
|
13
|
+
def call(worker_class, msg, queue, redis_pool)
|
14
|
+
Rack::CsrfDetector.more_bad!
|
15
|
+
yield
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rack/csrf_detector.rb
CHANGED
@@ -2,9 +2,16 @@ module Rack
|
|
2
2
|
class CsrfDetector
|
3
3
|
@@bad_count = 0
|
4
4
|
|
5
|
-
def initialize(app)
|
5
|
+
def initialize(app, opts={}, &block)
|
6
6
|
@app = app
|
7
|
-
|
7
|
+
|
8
|
+
if block_given?
|
9
|
+
if block.arity == 1
|
10
|
+
block.call(self)
|
11
|
+
else
|
12
|
+
instance_eval(&block)
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
def call(env)
|
@@ -24,38 +31,8 @@ module Rack
|
|
24
31
|
|
25
32
|
private
|
26
33
|
|
27
|
-
def
|
28
|
-
|
29
|
-
🙉_activerecord_4_2!
|
30
|
-
else
|
31
|
-
🙉_activerecord_4_0!
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def 🙉_activerecord_4_0!
|
36
|
-
require 'active_record/connection_adapters/abstract/transaction'
|
37
|
-
|
38
|
-
ActiveRecord::ConnectionAdapters::OpenTransaction.class_eval do
|
39
|
-
commit_method = instance_method(:commit)
|
40
|
-
|
41
|
-
define_method :commit do
|
42
|
-
Rack::CsrfDetector.more_bad!
|
43
|
-
commit_method.bind(self).call
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def 🙉_activerecord_4_2!
|
49
|
-
require 'active_record/connection_adapters/abstract/transaction'
|
50
|
-
|
51
|
-
ActiveRecord::ConnectionAdapters::Transaction.class_eval do
|
52
|
-
commit_method = instance_method(:commit)
|
53
|
-
|
54
|
-
define_method :commit do
|
55
|
-
Rack::CsrfDetector.more_bad!
|
56
|
-
commit_method.bind(self).call
|
57
|
-
end
|
58
|
-
end
|
34
|
+
def use(klass)
|
35
|
+
klass.new.use!
|
59
36
|
end
|
60
37
|
end
|
61
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-csrf-detector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy Murphy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
This middleware helps you identify when a GET request results in an
|
@@ -19,6 +19,8 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/rack/csrf_detector.rb
|
22
|
+
- lib/rack/csrf_detector/active_record_instrument.rb
|
23
|
+
- lib/rack/csrf_detector/sidekiq_instrument.rb
|
22
24
|
homepage: https://github.com/tam7t/rack-csrf-detector
|
23
25
|
licenses:
|
24
26
|
- MIT
|