forest_admin_rpc_agent 1.4.0 → 1.5.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: dce86f43a17822742d269f5ed0fe0e0b1e872103c2ca757223da9ba206d6cd5e
4
- data.tar.gz: 84f854406e55262bd66e0a46d4fed20a8ac38f666d27ff79525e504f1582a36e
3
+ metadata.gz: 4e52fd0a839e769c9fd90ce4753b6b15f21651a2ed54bf4f7ae4e2de95cd209e
4
+ data.tar.gz: 69ff2cfc82494cfc16186a6c2fe8b0c3cc7a325139ccc50ab1d2ad397b3a9c9b
5
5
  SHA512:
6
- metadata.gz: 80b7b5bdca2c923d5ae8042d3e02cc261c70e9299348bf08269968c8c508c92d214a9c242714e7aa5ecaf5cc30be189e5b05297d8062de2d454bd160f4d1d051
7
- data.tar.gz: 1ca233e4b72ccf48bbc01e27d67dec93df43090410d779b5f447150a2c7b38f4715c93cdb99d7c55e219f255fbc03a258c64e82894bffb7b839d7a4f959e1391
6
+ metadata.gz: 7a5836d6419f13ac7b1ef93be88073e0cd1723bee3ce60f0301d32e239f9b7382df9f806149dc08e6765a59c32efa804682b26f2e783f97be190066de301b093
7
+ data.tar.gz: 58712d1f4db5abef1e0e9ef618bb53f5c8344473032876c079859c6ea7ae7d0574565fe81d9a832e4d5b8cb969f98676af34f46518bd2ca9ab7d76479067c506
@@ -4,6 +4,7 @@ module ForestAdminRpcAgent
4
4
  ALLOWED_TIME_DIFF = 300
5
5
  SIGNATURE_REUSE_WINDOW = 5
6
6
  @@used_signatures = {}
7
+ @@signatures_mutex = Mutex.new
7
8
 
8
9
  def initialize(app)
9
10
  @app = app
@@ -32,33 +33,45 @@ module ForestAdminRpcAgent
32
33
  return false unless Rack::Utils.secure_compare(signature, expected_signature)
33
34
 
34
35
  # check if this signature has already been used (replay attack)
35
- if @@used_signatures.key?(signature)
36
- last_used = @@used_signatures[signature]
37
- return false if Time.now.utc.to_i - last_used > SIGNATURE_REUSE_WINDOW
38
- end
39
- @@used_signatures[signature] = Time.now.utc.to_i
36
+ # Reject if signature was used recently (within SIGNATURE_REUSE_WINDOW seconds)
37
+ # Use mutex to prevent race conditions in multi-threaded environments
38
+ now = current_time_in_seconds
39
+
40
+ @@signatures_mutex.synchronize do
41
+ if @@used_signatures.key?(signature)
42
+ last_used = @@used_signatures[signature]
43
+ time_since_last_use = now - last_used
44
+ return false if time_since_last_use <= SIGNATURE_REUSE_WINDOW
45
+ end
46
+ @@used_signatures[signature] = now
40
47
 
41
- cleanup_old_signatures
48
+ cleanup_old_signatures
49
+ end
42
50
 
43
51
  true
44
52
  end
45
53
 
46
54
  def valid_timestamp?(timestamp)
47
55
  time = begin
48
- Time.iso8601(timestamp)
49
- rescue StandardError
56
+ Time.iso8601(timestamp).utc
57
+ rescue ArgumentError
50
58
  nil
51
59
  end
52
60
  return false if time.nil?
53
61
 
54
- (Time.now.utc.to_i - time.to_i).abs <= ALLOWED_TIME_DIFF
62
+ (current_time_in_seconds - time.to_i).abs <= ALLOWED_TIME_DIFF
55
63
  end
56
64
 
57
65
  def cleanup_old_signatures
58
- now = Time.now.utc.to_i
66
+ # Should be called within mutex synchronize block
67
+ now = current_time_in_seconds
59
68
  @@used_signatures.delete_if { |_signature, last_used| now - last_used > ALLOWED_TIME_DIFF }
60
69
  end
61
70
 
71
+ def current_time_in_seconds
72
+ defined?(Time.current) ? Time.current.to_i : Time.now.utc.to_i
73
+ end
74
+
62
75
  def auth_secret
63
76
  ForestAdminRpcAgent.config.auth_secret
64
77
  end
@@ -1,3 +1,3 @@
1
1
  module ForestAdminRpcAgent
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_rpc_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-10-03 00:00:00.000000000 Z
12
+ date: 2025-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-configurable