spamtrap 0.4.3 → 0.4.4

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: 1cc68536b7186bc9fac9249043e7bd3d0713b77070fab4611c08a8ba5fb1bfc1
4
- data.tar.gz: 91c9ae78401af26537bc45c7c1ea17fac4245c264e1a6ee421fb6a9fd86af2d0
3
+ metadata.gz: c77cdc3c296d9d7add4208780853b77a22cc7e3df72c2fe86dc38371394f8d42
4
+ data.tar.gz: e1edf13f46c1e64c38bca0a1b1d31f5a7dd41419f8f45cba7b29a580e1761f5d
5
5
  SHA512:
6
- metadata.gz: 5985f1e8600a0f2d361b94ede13e567ea8b09d8e9ff3d7b4b0c2be99987d50d85bf5271dcea1bf3a0b5cc128a0fc066d6395b8ebf0be53dbc25970333e8ddab0
7
- data.tar.gz: 5adec9413ed191d8de06866db16da6b68b65ead9509749a535fe416964540da1751037f44e52a688461cd828cbe82826d4714c40d08c06fdafa8f68e0b2f07da
6
+ metadata.gz: 34d2069dd9f92c0c36e56a0b20940c1cae6382cc94cd0c6b54c6609136f58a5ca3e3a26d469111a0527dfed0d5ccfa82d776ae1c2b6464fa91c88898f0d87d49
7
+ data.tar.gz: 249c2fa24da70d78a0a697194cad3a0c0e493b3285199e608ce3fb3667e6cb665078bf27e684cf0d9a18482b76c6501a8f913c688c15465266af37ac0164b9a2
@@ -9,6 +9,8 @@ module Spamtrap
9
9
  NONCE_LEN = 12
10
10
  TAG_LEN = 16
11
11
 
12
+ TOKEN_DRAWS = 8 # see spamtrap_encrypt_field
13
+
12
14
  class << self
13
15
  # HKDF-derives {mutation:, nonce:} keys, memoised per secret at module level so each
14
16
  # request doesn't re-derive them; previous_secret_key_base is what keeps a rotation from
@@ -52,8 +54,20 @@ module Spamtrap
52
54
  context.nil? ? timestamp.to_s : "#{timestamp}:#{context}"
53
55
  end
54
56
 
55
- # aad binds the token to the render timestamp so it can't be replayed under a different one.
57
+ # A token the app's filter_parameters match as it stands (one containing otp or cvv, say) is
58
+ # masked in the log before the real name is checked: 0.38% of draws per field under Rails'
59
+ # generated list. So draw again. Capped because a filter matching every token would never stop.
56
60
  def spamtrap_encrypt_field(field_name, aad)
61
+ token = nil
62
+ TOKEN_DRAWS.times do
63
+ token = spamtrap_encrypt_field_once(field_name, aad)
64
+ break unless defined?(Spamtrap::ParameterFilter) && Spamtrap::ParameterFilter.masks_token?(token)
65
+ end
66
+ token
67
+ end
68
+
69
+ # aad binds the token to the render timestamp so it can't be replayed under a different one.
70
+ def spamtrap_encrypt_field_once(field_name, aad)
57
71
  cipher = OpenSSL::Cipher.new(CIPHER)
58
72
  cipher.encrypt
59
73
  cipher.key = Spamtrap::Crypto.keys_for(Spamtrap.secret_key_base)[:mutation]
@@ -21,7 +21,19 @@ module Spamtrap
21
21
  value.replace(masked) if masked
22
22
  end
23
23
 
24
+ # Stands in for a field's value when asking whether the app's filters would mask a token.
25
+ PROBE = 'spamtrap'.freeze
26
+
24
27
  class << self
28
+ # Whether the app's filters mask a value by the token itself. Rails checks key filters before
29
+ # calling any block, so such a token hides its field whatever the real name. Leaf only, so a
30
+ # dotted filter such as "comment.otp" goes unchecked; it can match only a token's first letters.
31
+ def masks_token?(token)
32
+ return false unless Spamtrap.filter_parameters && defined?(Rails.application) && Rails.application
33
+
34
+ app_filter.filter(token => PROBE)[token] != PROBE
35
+ end
36
+
25
37
  # What the app's filters turn value into at the field's real path, or nil if they leave it.
26
38
  # Only leaf names are mutated, so the containers above the token give the real path. A token
27
39
  # shared by fields_for children has several parents; masking if any path would is the safe side.
@@ -1,5 +1,5 @@
1
1
  module Spamtrap
2
2
 
3
- VERSION = '0.4.3'
3
+ VERSION = '0.4.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spamtrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cedric Howe
@@ -139,14 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 3.1.0
142
+ version: 3.4.0
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: 1.3.6
148
148
  requirements: []
149
- rubygems_version: 4.0.21
149
+ rubygems_version: 4.0.22
150
150
  specification_version: 4
151
151
  summary: Simple spamtrap for spambots.
152
152
  test_files: []