blind_index 2.1.1 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +6 -5
- data/lib/blind_index/backfill.rb +2 -2
- data/lib/blind_index/extensions.rb +21 -31
- data/lib/blind_index/model.rb +8 -2
- data/lib/blind_index/version.rb +1 -1
- data/lib/blind_index.rb +5 -5
- metadata +11 -137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12b2d12aee6d6e6dd8952118b308cb9d21de0628c1f3bd6e2f60170f04397d5
|
4
|
+
data.tar.gz: 0e40d8e7ec91d6c8caed22b1c378bd17ef4ad3d56a8359f3e85565d98b1c25b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d312ab5862bbcf0b7aaa5be36f1cc4eac962a1da65d6bb45cc3842f545a441c252654b5809a8de9fc3f66c2c4a8400d4c6cb2134ef576b0d3133d833acfffdf9
|
7
|
+
data.tar.gz: 669f352fb9d01441c4cffffe67eb8ab086db2443a9c7ef50b3d9cf00a353ad65f34d88d87e1ff4e7e4e05a510058b41315cfb1f066b5111655bdfd77ebe64553
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 2.3.1 (2022-09-06)
|
2
|
+
|
3
|
+
- Fixed error with `backfill` when `bidx_attribute` is a symbol
|
4
|
+
|
5
|
+
## 2.3.0 (2022-01-16)
|
6
|
+
|
7
|
+
- Added blind indexes to `filter_attributes`
|
8
|
+
- Dropped support for Ruby < 2.6 and Rails < 5.2
|
9
|
+
|
10
|
+
## 2.2.0 (2020-09-07)
|
11
|
+
|
12
|
+
- Added support for `where` with table in Active Record 5.2+
|
13
|
+
|
1
14
|
## 2.1.1 (2020-08-14)
|
2
15
|
|
3
16
|
- Fixed `version` option
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Works with [Lockbox](https://github.com/ankane/lockbox) ([full example](https://
|
|
6
6
|
|
7
7
|
Learn more about [securing sensitive data in Rails](https://ankane.org/sensitive-data-rails)
|
8
8
|
|
9
|
-
[![Build Status](https://
|
9
|
+
[![Build Status](https://github.com/ankane/blind_index/workflows/build/badge.svg?branch=master)](https://github.com/ankane/blind_index/actions)
|
10
10
|
|
11
11
|
## How It Works
|
12
12
|
|
@@ -23,12 +23,12 @@ Here’s a [great article](https://blog.cryptographyengineering.com/2019/02/11/a
|
|
23
23
|
Add this line to your application’s Gemfile:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
gem
|
26
|
+
gem "blind_index"
|
27
27
|
```
|
28
28
|
|
29
29
|
## Prep
|
30
30
|
|
31
|
-
Your model should already be set up with Lockbox or attr_encrypted. The examples are for a `User` model with `
|
31
|
+
Your model should already be set up with Lockbox or attr_encrypted. The examples are for a `User` model with `has_encrypted :email` or `attr_encrypted :email`. See the full examples for [Lockbox](https://ankane.org/securing-user-emails-lockbox) and [attr_encrypted](https://ankane.org/securing-user-emails-in-rails) if needed.
|
32
32
|
|
33
33
|
Also, if you use attr_encrypted, [generate a key](#key-generation).
|
34
34
|
|
@@ -262,6 +262,7 @@ For Mongoid, use:
|
|
262
262
|
```ruby
|
263
263
|
class User
|
264
264
|
field :email_bidx, type: String
|
265
|
+
index({email_bidx: 1})
|
265
266
|
end
|
266
267
|
```
|
267
268
|
|
@@ -296,13 +297,13 @@ Unfortunately, blind indexes can’t be used for `LIKE`, `ILIKE`, or full-text s
|
|
296
297
|
For `LIKE`, use:
|
297
298
|
|
298
299
|
```ruby
|
299
|
-
User.
|
300
|
+
User.select { |u| u.email.include?("value") }
|
300
301
|
```
|
301
302
|
|
302
303
|
For `ILIKE`, use:
|
303
304
|
|
304
305
|
```ruby
|
305
|
-
User.
|
306
|
+
User.select { |u| u.email =~ /value/i }
|
306
307
|
```
|
307
308
|
|
308
309
|
For full-text or fuzzy searching, use a gem like [FuzzyMatch](https://github.com/seamusabshere/fuzzy_match):
|
data/lib/blind_index/backfill.rb
CHANGED
@@ -21,8 +21,8 @@ module BlindIndex
|
|
21
21
|
# modify in-place
|
22
22
|
def filter_columns!(columns)
|
23
23
|
columns = Array(columns).map(&:to_s)
|
24
|
-
blind_indexes.select! { |_, v| columns.include?(v[:bidx_attribute]) }
|
25
|
-
bad_columns = columns - blind_indexes.map { |_, v| v[:bidx_attribute] }
|
24
|
+
blind_indexes.select! { |_, v| columns.include?(v[:bidx_attribute].to_s) }
|
25
|
+
bad_columns = columns - blind_indexes.map { |_, v| v[:bidx_attribute].to_s }
|
26
26
|
raise ArgumentError, "Bad column: #{bad_columns.first}" if bad_columns.any?
|
27
27
|
end
|
28
28
|
|
@@ -1,24 +1,6 @@
|
|
1
1
|
module BlindIndex
|
2
2
|
module Extensions
|
3
3
|
module TableMetadata
|
4
|
-
def resolve_column_aliases(hash)
|
5
|
-
new_hash = super
|
6
|
-
if has_blind_indexes?
|
7
|
-
hash.each do |key, _|
|
8
|
-
if key.respond_to?(:to_sym) && (bi = klass.blind_indexes[key.to_sym]) && !new_hash[key].is_a?(ActiveRecord::StatementCache::Substitute)
|
9
|
-
value = new_hash.delete(key)
|
10
|
-
new_hash[bi[:bidx_attribute]] =
|
11
|
-
if value.is_a?(Array)
|
12
|
-
value.map { |v| BlindIndex.generate_bidx(v, **bi) }
|
13
|
-
else
|
14
|
-
BlindIndex.generate_bidx(value, **bi)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
new_hash
|
20
|
-
end
|
21
|
-
|
22
4
|
# memoize for performance
|
23
5
|
def has_blind_indexes?
|
24
6
|
unless defined?(@has_blind_indexes)
|
@@ -28,6 +10,23 @@ module BlindIndex
|
|
28
10
|
end
|
29
11
|
end
|
30
12
|
|
13
|
+
module PredicateBuilder
|
14
|
+
# https://github.com/rails/rails/commit/56f30962b84fc53b76001301fb830c1594fd377e
|
15
|
+
def build(attribute, value, *args)
|
16
|
+
if table.has_blind_indexes? && (bi = table.send(:klass).blind_indexes[attribute.name.to_sym]) && !value.is_a?(ActiveRecord::StatementCache::Substitute)
|
17
|
+
attribute = attribute.relation[bi[:bidx_attribute]]
|
18
|
+
value =
|
19
|
+
if value.is_a?(Array)
|
20
|
+
value.map { |v| BlindIndex.generate_bidx(v, **bi) }
|
21
|
+
else
|
22
|
+
BlindIndex.generate_bidx(value, **bi)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
super(attribute, value, *args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
31
30
|
module UniquenessValidator
|
32
31
|
def validate_each(record, attribute, value)
|
33
32
|
klass = record.class
|
@@ -38,20 +37,11 @@ module BlindIndex
|
|
38
37
|
end
|
39
38
|
|
40
39
|
# change attribute name here instead of validate_each for better error message
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
attribute = bi[:bidx_attribute]
|
45
|
-
end
|
46
|
-
super(klass, attribute, value)
|
47
|
-
end
|
48
|
-
else
|
49
|
-
def build_relation(klass, table, attribute, value)
|
50
|
-
if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
|
51
|
-
attribute = bi[:bidx_attribute]
|
52
|
-
end
|
53
|
-
super(klass, table, attribute, value)
|
40
|
+
def build_relation(klass, attribute, value)
|
41
|
+
if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
|
42
|
+
attribute = bi[:bidx_attribute]
|
54
43
|
end
|
44
|
+
super(klass, attribute, value)
|
55
45
|
end
|
56
46
|
end
|
57
47
|
|
data/lib/blind_index/model.rb
CHANGED
@@ -36,6 +36,14 @@ module BlindIndex
|
|
36
36
|
key ||= -> { BlindIndex.index_key(table: try(:table_name) || collection_name.to_s, bidx_attribute: bidx_attribute, master_key: options[:master_key], encode: false) }
|
37
37
|
|
38
38
|
class_eval do
|
39
|
+
activerecord = defined?(ActiveRecord) && self < ActiveRecord::Base
|
40
|
+
|
41
|
+
if activerecord && ActiveRecord::VERSION::MAJOR >= 6
|
42
|
+
# blind index value isn't really sensitive
|
43
|
+
# but don't need to show it in the Rails console
|
44
|
+
self.filter_attributes += [/\A#{Regexp.escape(bidx_attribute)}\z/]
|
45
|
+
end
|
46
|
+
|
39
47
|
@blind_indexes ||= {}
|
40
48
|
|
41
49
|
unless respond_to?(:blind_indexes)
|
@@ -69,8 +77,6 @@ module BlindIndex
|
|
69
77
|
end
|
70
78
|
|
71
79
|
if callback
|
72
|
-
activerecord = defined?(ActiveRecord) && self < ActiveRecord::Base
|
73
|
-
|
74
80
|
# TODO reuse module
|
75
81
|
m = Module.new do
|
76
82
|
define_method "#{attribute}=" do |value|
|
data/lib/blind_index/version.rb
CHANGED
data/lib/blind_index.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# dependencies
|
2
2
|
require "active_support"
|
3
|
-
require "openssl"
|
4
3
|
require "argon2/kdf"
|
5
4
|
|
5
|
+
# stdlib
|
6
|
+
require "openssl"
|
7
|
+
|
6
8
|
# modules
|
7
9
|
require "blind_index/backfill"
|
8
10
|
require "blind_index/key_generator"
|
@@ -140,10 +142,8 @@ ActiveSupport.on_load(:active_record) do
|
|
140
142
|
|
141
143
|
ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
|
142
144
|
ActiveRecord::DynamicMatchers::Method.prepend(BlindIndex::Extensions::DynamicMatchers)
|
143
|
-
|
144
|
-
|
145
|
-
ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
|
146
|
-
end
|
145
|
+
ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
|
146
|
+
ActiveRecord::PredicateBuilder.prepend(BlindIndex::Extensions::PredicateBuilder)
|
147
147
|
end
|
148
148
|
|
149
149
|
ActiveSupport.on_load(:mongoid) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blind_index
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5'
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5'
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: argon2-kdf
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,134 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.1
|
41
|
-
|
42
|
-
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: attr_encrypted
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activerecord
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: sqlite3
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: scrypt
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: benchmark-ips
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: lockbox
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0.2'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0.2'
|
167
|
-
description:
|
168
|
-
email: andrew@chartkick.com
|
41
|
+
description:
|
42
|
+
email: andrew@ankane.org
|
169
43
|
executables: []
|
170
44
|
extensions: []
|
171
45
|
extra_rdoc_files: []
|
@@ -184,7 +58,7 @@ homepage: https://github.com/ankane/blind_index
|
|
184
58
|
licenses:
|
185
59
|
- MIT
|
186
60
|
metadata: {}
|
187
|
-
post_install_message:
|
61
|
+
post_install_message:
|
188
62
|
rdoc_options: []
|
189
63
|
require_paths:
|
190
64
|
- lib
|
@@ -192,15 +66,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
66
|
requirements:
|
193
67
|
- - ">="
|
194
68
|
- !ruby/object:Gem::Version
|
195
|
-
version: '2.
|
69
|
+
version: '2.6'
|
196
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
71
|
requirements:
|
198
72
|
- - ">="
|
199
73
|
- !ruby/object:Gem::Version
|
200
74
|
version: '0'
|
201
75
|
requirements: []
|
202
|
-
rubygems_version: 3.
|
203
|
-
signing_key:
|
76
|
+
rubygems_version: 3.3.7
|
77
|
+
signing_key:
|
204
78
|
specification_version: 4
|
205
79
|
summary: Securely search encrypted database fields
|
206
80
|
test_files: []
|