shugoi 0.4.3 → 0.4.5

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: ae02598e982619825522554b0190f1a1272acad33f637a978d0e821eb0861c34
4
- data.tar.gz: ec6dbe09ad713c8bbee63755b6b9bf3f048d201aed2ec1d104c15660b3f80da5
3
+ metadata.gz: 3f5c8d8f2dbb96ef585e0da0079fffc4ccb21cb8d3c9c488ba2e3ba2f6dcccef
4
+ data.tar.gz: 8dee0a01a95b9a27e34d0d131cfc24e268834f4992993d843302666c4b531b53
5
5
  SHA512:
6
- metadata.gz: 50fdb144de09568d85efeacf3fabc166459ecc9c2b95004432493325310188a41ef8c2544dae2773317de34ce66b438f0d69a76cbca3be862038c969a6766c63
7
- data.tar.gz: e8332144c9d514bf52f37df0d829db7a3bcfd5f7232a7899a82a80ac498ae705b33edda25d55f5959e285713b1037c10214aeeadc5c47174e2b6f4ee87dc3ae6
6
+ metadata.gz: db5513f04ab846d0a248b9dd2cb6b497c74f1f72e30cf9f78c7daaaf2194f4a7b23484f03155f4144e74a2ec51df8e1bd8a3b32e415b196cff3e755d12438de5
7
+ data.tar.gz: b7a01c4200dda93eabe8b43adf26f6b493ff68f2fece74bb88353f78b8fc039e4c7dac3a6cf6bc40590d07c2eea0bc65d9f3ef891905ef7a45f2cde702d4c7d1
@@ -14,9 +14,14 @@ module Shugoi
14
14
  @debug = debug
15
15
  end
16
16
 
17
- # GET /whitelist?key=... → { whitelistedMachines, detectionFlags, skipPaths }
18
- def fetch_whitelist(site_key)
19
- json = get("/whitelist", key: site_key)
17
+ # GET /whitelist?key=...&cb=...&sig=... → { detectionFlags, skipPaths }
18
+ # La siteKey est publique ; la configuration serveur doit prouver la possession
19
+ # du secret de signature (parité Node/PHP, F2/F3).
20
+ def fetch_whitelist(site_key, secret = nil)
21
+ cb = SecureRandom.hex(4)
22
+ params = { key: site_key, cb: cb.to_s }
23
+ params[:sig] = Utils.hmac_hex(secret, cb.to_s) if secret && !secret.empty?
24
+ json = get("/whitelist", params)
20
25
  {
21
26
  whitelist: json["whitelistedMachines"] || [],
22
27
  flags: json["detectionFlags"] || json["flags"] || {},
@@ -7,8 +7,9 @@ module Shugoi
7
7
  TTL_MS = 30_000
8
8
  STALE_MAX_MS = 600_000
9
9
 
10
- def initialize(api_client)
10
+ def initialize(api_client, signing_secret = nil)
11
11
  @api_client = api_client
12
+ @signing_secret = signing_secret
12
13
  @mutex = Mutex.new
13
14
  @whitelist = []
14
15
  @flags = {}
@@ -30,7 +31,7 @@ module Shugoi
30
31
  private
31
32
 
32
33
  def refresh(site_key)
33
- data = @api_client.fetch_whitelist(site_key)
34
+ data = @api_client.fetch_whitelist(site_key, @signing_secret)
34
35
  @whitelist = data[:whitelist]
35
36
  @flags = data[:flags]
36
37
  @skip_paths = data[:skip_paths]
data/lib/shugoi/core.rb CHANGED
@@ -61,7 +61,7 @@ module Shugoi
61
61
  # pre-flight PoW. Posé APRÈS une première résolution réussie (middleware).
62
62
  valid_cookie = !ctx[:sg_ok].to_s.empty? && @pow.sg_ok_valid?(ctx[:sg_ok], ctx[:ip].to_s, ua)
63
63
  # Round 16 (R2) : la preuve est SINGLE-USE (par IP) — un rejeu → 307.
64
- proof_fresh = valid_proof ? consume_proof(proof, ctx[:ip].to_s) : false
64
+ proof_fresh = valid_proof ? consume_proof(proof) : false
65
65
  unless valid_cookie || proof_fresh
66
66
  return pow_challenge_307(ctx) if allow_challenge?(ctx[:ip].to_s)
67
67
 
@@ -218,12 +218,13 @@ module Shugoi
218
218
  end
219
219
  end
220
220
 
221
- # Preuve PoW single-use (par IP) — entrées purgées après POW_TTL_MS.
222
- def consume_proof(proof, ip)
223
- key = "#{ip}:#{proof}"
221
+ # Preuve PoW single-use GLOBAL (round 17) — clé = preuve seule (le nonce aléatoire
222
+ # la rend unique) → rejeu depuis N'IMPORTE QUEL IP → 307 (round 16 : clé ip:proof
223
+ # laissait le rejeu cross-IP → 200). Entrées purgées après POW_TTL_MS.
224
+ def consume_proof(proof)
224
225
  @mutex.synchronize do
225
- return false if @used_proofs.key?(key)
226
- @used_proofs[key] = Utils.now_ms
226
+ return false if @used_proofs.key?(proof)
227
+ @used_proofs[proof] = Utils.now_ms
227
228
  now = Utils.now_ms
228
229
  @used_proofs.delete_if { |_k, t| now - t > POW_TTL_MS }
229
230
  true
@@ -21,7 +21,7 @@ module Shugoi
21
21
  # le deadlock (appels serveur→serveur qui repasseraient par le middleware public).
22
22
  @api_internal = ApiClient.new(@config.internal_url, debug: @config.debug)
23
23
  @guard_cache = GuardCache.new(@api_client)
24
- @config_cache = ConfigCache.new(@api_internal)
24
+ @config_cache = ConfigCache.new(@api_internal, @config.signing_secret)
25
25
  @token_signer = TokenSigner.new(@config.signing_secret)
26
26
  # multi_process → stockage disque du HTML (nécessaire en cluster PM2, parité
27
27
  # enableDiskStore(true) du module Node).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shugoi
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shugoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugoi