reputable 0.1.11 → 0.1.12
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -1
- data/lib/reputable/middleware.rb +15 -0
- data/lib/reputable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '09fa87a88ec9b2c8b0cf010e6291c7386f32ed2ceaf55b80c34cd831a75b07f4'
|
|
4
|
+
data.tar.gz: ab4eb854a090b4c971722932fffe097ae1f52a8feaf1525b8bf2ed6fc9462411
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45143f6b28ebc3e70810a0a58830b6136c1575a6c4888ad5a680dfc1d3cf09ec9e619ef104873883ecc083324cd083dbe769648494701eedc3f488c5215eb7e6
|
|
7
|
+
data.tar.gz: b1c8722bc5e7c4c9cc4080fb922a0a245c0a42996e5ab4abd6e984e33943f50da0d7d8f55873096630bafd93ec53bc7a703049ab36fc63c8fd68af9cf8f23f43
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -271,6 +271,10 @@ config.middleware.use Reputable::Middleware,
|
|
|
271
271
|
# Async mode (default: true) - tracking runs in background thread
|
|
272
272
|
async: true,
|
|
273
273
|
|
|
274
|
+
# Request tracking (default: false) - push request context to Redis
|
|
275
|
+
# Falls back to ENV REPUTABLE_TRACK_REQUEST if not set
|
|
276
|
+
track_request: true,
|
|
277
|
+
|
|
274
278
|
# Expose reputation flags in request env for views/controllers (default: true)
|
|
275
279
|
# Sets request.env['reputable.ignore_analytics'] when status is untrusted_ignore
|
|
276
280
|
expose_reputation: true
|
|
@@ -565,6 +569,11 @@ The gem is designed with resilience as the top priority:
|
|
|
565
569
|
REPUTABLE_ENABLED=false
|
|
566
570
|
```
|
|
567
571
|
|
|
572
|
+
```bash
|
|
573
|
+
# Enable request tracking (push request context to Redis)
|
|
574
|
+
REPUTABLE_TRACK_REQUEST=true
|
|
575
|
+
```
|
|
576
|
+
|
|
568
577
|
```ruby
|
|
569
578
|
# Check in code
|
|
570
579
|
if Reputable.enabled?
|
|
@@ -653,7 +662,7 @@ expect(Reputable.lookup_ip('1.2.3.4')).to be_nil
|
|
|
653
662
|
|
|
654
663
|
## How It Works
|
|
655
664
|
|
|
656
|
-
1. **Request Tracking**: Your Rails app pushes request data to Redis buffers
|
|
665
|
+
1. **Request Tracking**: Your Rails app pushes request data to Redis buffers (enable with `track_request: true` or `REPUTABLE_TRACK_REQUEST=true`)
|
|
657
666
|
2. **Async Processing**: Reputable API processes buffers asynchronously
|
|
658
667
|
3. **Behavioral Analysis**: Requests go through classification and pattern analysis
|
|
659
668
|
4. **Reputation Storage**: Scores stored in Redis for O(1) lookups
|
data/lib/reputable/middleware.rb
CHANGED
|
@@ -44,6 +44,7 @@ module Reputable
|
|
|
44
44
|
@skip_if = options[:skip_if]
|
|
45
45
|
@tag_builder = options[:tag_builder]
|
|
46
46
|
@async = options.fetch(:async, true)
|
|
47
|
+
@track_request = options.key?(:track_request) ? options[:track_request] : nil
|
|
47
48
|
@reputation_gate = options.fetch(:reputation_gate, false)
|
|
48
49
|
@expose_reputation = options.fetch(:expose_reputation, true)
|
|
49
50
|
@challenge_action = options.fetch(:challenge_action, :verify)
|
|
@@ -118,6 +119,9 @@ module Reputable
|
|
|
118
119
|
def safe_track_request(env)
|
|
119
120
|
# Skip if disabled globally
|
|
120
121
|
return unless Reputable.enabled?
|
|
122
|
+
|
|
123
|
+
# Skip unless explicitly enabled
|
|
124
|
+
return unless track_request_enabled?
|
|
121
125
|
|
|
122
126
|
# Skip if this request should be skipped
|
|
123
127
|
return if skip_request?(env)
|
|
@@ -128,6 +132,17 @@ module Reputable
|
|
|
128
132
|
Reputable.logger&.debug("Reputable middleware: #{e.class} - #{e.message}")
|
|
129
133
|
end
|
|
130
134
|
|
|
135
|
+
def track_request_enabled?
|
|
136
|
+
return @track_request unless @track_request.nil?
|
|
137
|
+
|
|
138
|
+
env_value = ENV["REPUTABLE_TRACK_REQUEST"]
|
|
139
|
+
return false if env_value.nil?
|
|
140
|
+
|
|
141
|
+
!%w[0 false no off disabled].include?(env_value.to_s.downcase)
|
|
142
|
+
rescue StandardError
|
|
143
|
+
false
|
|
144
|
+
end
|
|
145
|
+
|
|
131
146
|
def handle_verification_return(env)
|
|
132
147
|
request = Rack::Request.new(env)
|
|
133
148
|
# Quick check to avoid overhead
|
data/lib/reputable/version.rb
CHANGED