bot_challenge_page 1.0.0 → 1.1.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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f487a01c979d017a65f2ef03c460ecd54eab49047fefd344d31f0b17f7d43fa
|
|
4
|
+
data.tar.gz: 4e1ff3d6d6fb127a99fdb8d59a2251f5473138f1b9dcd361762f6700b96586f8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05e2489f513ef948b8d0a1ec2446d722a5277ac8e88c78676efbd3ebc5befa564d981e98e288786de9b237035e4213d48250b7ef6288f687ee6127b67538824b
|
|
7
|
+
data.tar.gz: db452f92074ac849d6e568bba787e684951c4977d0176b359179c974fa51b3d464c0b9494212345183638f6e669a3a0ea577eb0446ff954b14ced5bcaca93aff
|
data/README.md
CHANGED
|
@@ -112,6 +112,16 @@ config.after_blocked = (_bot_challenge_class)-> {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
If you'd like to log every time a request is let through because it has a verified session pass,
|
|
116
|
+
which could be a lot of data, use `after_session_pass`.
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
config.after_session_pass = (_bot_challenge_class)-> {
|
|
120
|
+
logger.info("page allowed through by session pass: #{request.uri}")
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
|
|
115
125
|
Or, here's how I managed to get it in [lograge](https://github.com/roidrage/lograge), so a page blocked results in a `bot_chlng=true` param in a lograge line.
|
|
116
126
|
|
|
117
127
|
```ruby
|
|
@@ -13,7 +13,7 @@ module BotChallengePage
|
|
|
13
13
|
# Render challenge page when necessary, otherwise do nothing allowing ordinary rails render.
|
|
14
14
|
def bot_challenge_guard_action(controller)
|
|
15
15
|
if self.bot_challenge_config.enabled &&
|
|
16
|
-
! self._bot_detect_passed_good?(controller
|
|
16
|
+
! self._bot_detect_passed_good?(controller) &&
|
|
17
17
|
! controller.kind_of?(self) # don't ever guard ourself, that'd be a mess!
|
|
18
18
|
|
|
19
19
|
# we can only do GET requests right now
|
|
@@ -51,7 +51,9 @@ module BotChallengePage
|
|
|
51
51
|
|
|
52
52
|
# Does the session already contain a bot detect pass that is good for this request
|
|
53
53
|
# Tie to IP address to prevent session replay shared among IPs
|
|
54
|
-
def _bot_detect_passed_good?(
|
|
54
|
+
def _bot_detect_passed_good?(controller)
|
|
55
|
+
request = controller.request
|
|
56
|
+
|
|
55
57
|
session_data = request.session[self.bot_challenge_config.session_passed_key]
|
|
56
58
|
|
|
57
59
|
return false unless session_data && session_data.kind_of?(Hash)
|
|
@@ -61,7 +63,9 @@ module BotChallengePage
|
|
|
61
63
|
fingerprint = session_data[self::SESSION_FINGERPRINT_KEY]
|
|
62
64
|
|
|
63
65
|
(Time.now - Time.iso8601(datetime) < self.bot_challenge_config.session_passed_good_for ) &&
|
|
64
|
-
fingerprint == self.bot_challenge_config.session_valid_fingerprint.call(request)
|
|
66
|
+
(fingerprint == self.bot_challenge_config.session_valid_fingerprint.call(request)) &&
|
|
67
|
+
# not a real condition, just to call our hook on passed
|
|
68
|
+
(controller.instance_exec(self, &self.bot_challenge_config.after_session_passed) || true)
|
|
65
69
|
end
|
|
66
70
|
end
|
|
67
71
|
end
|
|
@@ -45,6 +45,8 @@ module BotChallengePage
|
|
|
45
45
|
|
|
46
46
|
attribute :after_blocked, default: ->(bot_detect_class) {}
|
|
47
47
|
|
|
48
|
+
attribute :after_session_passed, default: ->(bot_detect_class) {}
|
|
49
|
+
|
|
48
50
|
|
|
49
51
|
# rate limit per subnet, follow lehigh's lead with
|
|
50
52
|
# subnet: /16 for IPv4 (x.y.*.*), and /64 for IPv6 (about the same size subnet for better or worse)
|