reputable 0.1.14 → 0.1.16
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 +27 -0
- data/lib/reputable/middleware.rb +33 -8
- data/lib/reputable/tracker.rb +5 -2
- data/lib/reputable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d33fb1c68fdaca4082540ed61021d61ec5d687779c6c290635327dfe58a83ec7
|
|
4
|
+
data.tar.gz: 8a217cc36dcc8eef21623025b2dca9b0ccd697b1a312fd46bcfa814c7958e189
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9470847736221d9aa4b0c0012487f18b32ed15bba2f22d5e85bbcd3f376263aa66899b8e14eda2058b0aa0e52e1c659845a516dee09709f379d9ef660cd2ed4
|
|
7
|
+
data.tar.gz: 879cc235f75b50f054db621572dbd2dfb58020102bc784d14fed109b921bfa82a4f91f0fe4fff7c7c3f2811ff0f292d5638ab2864323bcf93ddbcd18ecf18a3c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -301,6 +301,33 @@ Notes:
|
|
|
301
301
|
- Use `blocked_page_path` only for local blocked pages (or to build a custom `failure_url`).
|
|
302
302
|
- Override `challenge_redirect_status` (default `302`) or `verification_force_challenge` if needed.
|
|
303
303
|
|
|
304
|
+
### Server/JS Request Reconciliation
|
|
305
|
+
|
|
306
|
+
When using both server-side tracking (Rack middleware) and client-side JavaScript tracking, requests can be double-counted. The reconciliation system prevents this by correlating requests using a unique `request_id`.
|
|
307
|
+
|
|
308
|
+
**Automatic Request ID**: The middleware automatically generates a UUID for each request and stores it in `env['reputable.request_id']`. This ID is included when pushing to the Redis buffer.
|
|
309
|
+
|
|
310
|
+
**Exposing to JavaScript**: To enable reconciliation, expose the request_id in your views:
|
|
311
|
+
|
|
312
|
+
```erb
|
|
313
|
+
<%# In your layout (app/views/layouts/application.html.erb) %>
|
|
314
|
+
<meta name="reputable-request-id" content="<%= request.env['reputable.request_id'] %>">
|
|
315
|
+
|
|
316
|
+
<%# Or via JavaScript variable %>
|
|
317
|
+
<script>
|
|
318
|
+
window.reputableConfig = {
|
|
319
|
+
requestId: '<%= request.env['reputable.request_id'] %>'
|
|
320
|
+
};
|
|
321
|
+
</script>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
The JavaScript snippet will automatically read the request_id from:
|
|
325
|
+
1. `data-reputable-request-id` attribute on the script tag
|
|
326
|
+
2. `window.reputableConfig.requestId`
|
|
327
|
+
3. `<meta name="reputable-request-id">` tag
|
|
328
|
+
|
|
329
|
+
**Bot Detection Signal**: If the middleware tracks a request but JavaScript never fires (after a 10-second grace period), the request is flagged with `risk:no_js`. This is a strong bot signal—bots and crawlers typically don't render JavaScript.
|
|
330
|
+
|
|
304
331
|
### Default Skipped Paths
|
|
305
332
|
|
|
306
333
|
The middleware automatically skips:
|
data/lib/reputable/middleware.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "blocked_page"
|
|
4
|
+
require "securerandom"
|
|
4
5
|
|
|
5
6
|
module Reputable
|
|
6
7
|
# Rack middleware for automatic request tracking
|
|
@@ -61,6 +62,10 @@ module Reputable
|
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
def call(env)
|
|
65
|
+
# Generate a unique request ID for reconciliation with JS tracking
|
|
66
|
+
# This ID is exposed to views so it can be included in the JS snippet
|
|
67
|
+
env['reputable.request_id'] = SecureRandom.uuid
|
|
68
|
+
|
|
64
69
|
# Check for verification return parameters and verify signature if present
|
|
65
70
|
handle_verification_return(env)
|
|
66
71
|
|
|
@@ -145,16 +150,35 @@ module Reputable
|
|
|
145
150
|
|
|
146
151
|
def handle_verification_return(env)
|
|
147
152
|
request = Rack::Request.new(env)
|
|
148
|
-
# Quick check to avoid overhead
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
# Quick check to avoid overhead - support both new (reputable_r) and legacy (reputable_status) formats
|
|
154
|
+
query = request.query_string
|
|
155
|
+
return unless query.include?("reputable_r") || query.include?("reputable_status")
|
|
156
|
+
|
|
157
|
+
params = request.params
|
|
158
|
+
|
|
159
|
+
# Determine status from new format or legacy format
|
|
160
|
+
status = if params["reputable_r"]
|
|
161
|
+
decoded = Reputable.decode_reputable_response(params)
|
|
162
|
+
decoded&.dig("status")
|
|
163
|
+
else
|
|
164
|
+
params["reputable_status"]
|
|
165
|
+
end
|
|
152
166
|
|
|
153
|
-
|
|
167
|
+
return unless status == "pass"
|
|
168
|
+
|
|
169
|
+
if Reputable.verify_redirect_return(params)
|
|
154
170
|
env["reputable.verified"] = true
|
|
155
|
-
|
|
171
|
+
|
|
172
|
+
# Extract ignore_analytics from new format or legacy format
|
|
173
|
+
ignore_analytics = if params["reputable_r"]
|
|
174
|
+
decoded = Reputable.decode_reputable_response(params)
|
|
175
|
+
decoded&.dig("ignore_analytics")
|
|
176
|
+
else
|
|
177
|
+
params["reputable_ignore_analytics"]
|
|
178
|
+
end
|
|
179
|
+
|
|
156
180
|
unless ignore_analytics.nil?
|
|
157
|
-
env["reputable.ignore_analytics"] = ignore_analytics.to_s == "true"
|
|
181
|
+
env["reputable.ignore_analytics"] = ignore_analytics == true || ignore_analytics.to_s == "true"
|
|
158
182
|
end
|
|
159
183
|
|
|
160
184
|
# Store in session if available
|
|
@@ -371,7 +395,8 @@ module Reputable
|
|
|
371
395
|
method: request.request_method,
|
|
372
396
|
user_agent: env["HTTP_USER_AGENT"],
|
|
373
397
|
referer: env["HTTP_REFERER"],
|
|
374
|
-
tags: build_tags(env)
|
|
398
|
+
tags: build_tags(env),
|
|
399
|
+
request_id: env["reputable.request_id"]
|
|
375
400
|
}.compact
|
|
376
401
|
rescue StandardError => e
|
|
377
402
|
Reputable.logger&.debug("Reputable build_params: #{e.class} - #{e.message}")
|
data/lib/reputable/tracker.rb
CHANGED
|
@@ -24,6 +24,7 @@ module Reputable
|
|
|
24
24
|
# @option options [String] :country Country code (ISO 3166-1 alpha-2)
|
|
25
25
|
# @option options [Array<String>] :tags Custom classification tags
|
|
26
26
|
# @option options [Hash] :metadata Additional metadata
|
|
27
|
+
# @option options [String] :request_id Unique request ID for reconciliation with JS tracking
|
|
27
28
|
# @return [Boolean] true if successfully pushed to buffer, false otherwise
|
|
28
29
|
#
|
|
29
30
|
# @example Basic usage
|
|
@@ -32,7 +33,7 @@ module Reputable
|
|
|
32
33
|
# path: "/products/123"
|
|
33
34
|
# )
|
|
34
35
|
#
|
|
35
|
-
# @example Full usage
|
|
36
|
+
# @example Full usage with request_id for JS reconciliation
|
|
36
37
|
# Reputable::Tracker.track_request(
|
|
37
38
|
# ip: request.ip,
|
|
38
39
|
# path: request.path,
|
|
@@ -40,6 +41,7 @@ module Reputable
|
|
|
40
41
|
# method: request.request_method,
|
|
41
42
|
# user_agent: request.user_agent,
|
|
42
43
|
# referer: request.referer,
|
|
44
|
+
# request_id: env['reputable.request_id'],
|
|
43
45
|
# tags: ["view:page:product", "trust:channel:organic"]
|
|
44
46
|
# )
|
|
45
47
|
def track_request(ip:, path:, **options)
|
|
@@ -80,7 +82,8 @@ module Reputable
|
|
|
80
82
|
referer: options[:referer],
|
|
81
83
|
country: options[:country],
|
|
82
84
|
tags: options[:tags] || [],
|
|
83
|
-
metadata: options[:metadata]
|
|
85
|
+
metadata: options[:metadata],
|
|
86
|
+
request_id: options[:request_id]
|
|
84
87
|
}.compact
|
|
85
88
|
end
|
|
86
89
|
|
data/lib/reputable/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reputable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Reputable
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: redis
|