sensitive_data_filter 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +22 -1
- data/lib/sensitive_data_filter/config.rb +12 -0
- data/lib/sensitive_data_filter/mask.rb +7 -1
- data/lib/sensitive_data_filter/middleware/occurrence.rb +8 -0
- data/lib/sensitive_data_filter/scan.rb +7 -1
- data/lib/sensitive_data_filter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e31778956e211080b72def2da410aa33a3f93b86
|
4
|
+
data.tar.gz: 8234e02dc9e1e69663cd72aa65fb854a5471f0f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4317e1dcf196f132905332abd27ce1227656294edf9b721d6b577d6bab6156860ae687c1aefbbfa122da49245c64aa344841e10f61554027c7ec2a4eacdefd87
|
7
|
+
data.tar.gz: e1f221ad6fc0fb2bf57d36d6b0652de4f410e3ff587f5cb73069b0fa0eac85b21f8343a2e721541d5137abf2527010001bffab58c1c6cbe34f247874a9ae74cf
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
|
5
5
|
|
6
|
+
## [0.3.0] - 2016-12-28
|
7
|
+
### Changed
|
8
|
+
- Allows whitelisting hash values based on the key
|
9
|
+
- Updates README for usage with Rails middleware stack
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Adds `original_env` and `filtered_env` properties to occurrence
|
13
|
+
|
6
14
|
## [0.2.4] - 2016-12-22
|
7
15
|
### Changed
|
8
16
|
- Does not match credit cards numbers that are part of alphanumerical strings
|
@@ -14,7 +22,6 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
|
|
14
22
|
### Changed
|
15
23
|
- Does not match credit cards numbers that are part of longer numbers
|
16
24
|
|
17
|
-
|
18
25
|
## [0.2.2] - 2016-12-21
|
19
26
|
### Fixed
|
20
27
|
- Implements stricter credit cards pattern matching
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
### Enable the middleware
|
30
30
|
|
31
|
-
Insert the middleware in the stack before any parameter parsing is performed
|
31
|
+
Insert the middleware in the stack before any parameter parsing is performed.
|
32
32
|
|
33
33
|
E.g. for Rails, add the following in application.rb
|
34
34
|
|
@@ -37,6 +37,21 @@ E.g. for Rails, add the following in application.rb
|
|
37
37
|
config.middleware.insert_before 'ActionDispatch::ParamsParser', SensitiveDataFilter::Middleware::Filter
|
38
38
|
```
|
39
39
|
|
40
|
+
To ensure that no sensitive data is accessed at any level of the stack, insert the middleware at the top of the stack.
|
41
|
+
|
42
|
+
E.g.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# --- Sensitive Data Filtering ---
|
46
|
+
config.middleware.insert_before 0, SensitiveDataFilter::Middleware::Filter
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Important note for Rails
|
50
|
+
|
51
|
+
Rails logs the URI of the request in ``Rails::Rack::Logger``. At this point of the stack, Rails generally has not yet set the session in the env.
|
52
|
+
If you insert the sensitive data filtering middleware before this middleware you will prevent sensitive data from appearing in the logs,
|
53
|
+
but you will not have access to the session via the occurrence or the env in the occurrence handling block.
|
54
|
+
|
40
55
|
### Configuration
|
41
56
|
|
42
57
|
```ruby
|
@@ -46,6 +61,7 @@ SensitiveDataFilter.config do |config|
|
|
46
61
|
# Report occurrence
|
47
62
|
end
|
48
63
|
config.whitelist pattern1, pattern2 # Allows specifying patterns to whitelist matches
|
64
|
+
config.whitelist_key key_pattern1, key_pattern2 # Allows specifying patterns to whitelist hash values based on their keys
|
49
65
|
config.register_parser('yaml', -> params { YAML.load params }, -> params { YAML.dump params })
|
50
66
|
end
|
51
67
|
```
|
@@ -63,6 +79,8 @@ An occurrence object has the following properties:
|
|
63
79
|
* session: the session properties for the request
|
64
80
|
* matches: the matched sensitive data
|
65
81
|
* matches_count: the number of matches per data type, e.g. { 'CreditCard' => 1 }
|
82
|
+
* original_env: the original unfiltered Rack env
|
83
|
+
* filtered_env: the filtered Rack env which will be passed down the middleware stack
|
66
84
|
|
67
85
|
It also exposes `to_h` and `to_s` methods for hash and string representation respectively.
|
68
86
|
Please note that these representations omit sensitive data,
|
@@ -91,6 +109,9 @@ filtered_body_params = if @occurrence.filtered_body_params.is_a? Hash
|
|
91
109
|
A list of whitelisting patterns can be passed to `config.whitelist`.
|
92
110
|
Any sensitive data match which also matches any of these patterns will be ignored.
|
93
111
|
|
112
|
+
A list of whitelisting patterns can be passed to `config.whitelist_key`.
|
113
|
+
When scanning and matching hashes, any value whose key matches any of these patterns will be ignored.
|
114
|
+
|
94
115
|
#### Parameter Parsing
|
95
116
|
|
96
117
|
Parsers for parameters encoded for a specific content type can be defined.
|
@@ -20,6 +20,10 @@ module SensitiveDataFilter
|
|
20
20
|
config.whitelist_patterns.any? { |pattern| value.match pattern }
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.whitelisted_key?(key)
|
24
|
+
config.whitelist_key_patterns.any? { |pattern| key.match pattern }
|
25
|
+
end
|
26
|
+
|
23
27
|
class Config
|
24
28
|
DEFAULT_TYPES = %i(credit_card).freeze
|
25
29
|
|
@@ -45,6 +49,14 @@ module SensitiveDataFilter
|
|
45
49
|
@whitelist_patterns ||= []
|
46
50
|
end
|
47
51
|
|
52
|
+
def whitelist_key(*patterns)
|
53
|
+
@whitelist_key_patterns = patterns
|
54
|
+
end
|
55
|
+
|
56
|
+
def whitelist_key_patterns
|
57
|
+
@whitelist_key_patterns ||= []
|
58
|
+
end
|
59
|
+
|
48
60
|
def register_parser(content_type, parser, unparser)
|
49
61
|
SensitiveDataFilter::Middleware::ParameterParser
|
50
62
|
.register_parser(content_type, parser, unparser)
|
@@ -12,7 +12,13 @@ module SensitiveDataFilter
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module_function def mask_hash(hash)
|
15
|
-
hash.map { |key, value|
|
15
|
+
hash.map { |key, value| mask_key_value(key, value) }.to_h
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function def mask_key_value(key, value)
|
19
|
+
masked_key = mask(key)
|
20
|
+
return [masked_key, value] if SensitiveDataFilter.whitelisted_key? key
|
21
|
+
[masked_key, mask(value)]
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -35,6 +35,14 @@ module SensitiveDataFilter
|
|
35
35
|
@filtered_env_parser.body_params
|
36
36
|
end
|
37
37
|
|
38
|
+
def original_env
|
39
|
+
@original_env_parser.env
|
40
|
+
end
|
41
|
+
|
42
|
+
def filtered_env
|
43
|
+
@filtered_env_parser.env
|
44
|
+
end
|
45
|
+
|
38
46
|
def_delegators :@filtered_env_parser, :request_method, :url, :content_type, :session
|
39
47
|
|
40
48
|
def matches_count
|
@@ -17,7 +17,13 @@ module SensitiveDataFilter
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.scan_hash(hash)
|
20
|
-
hash.map { |key, value|
|
20
|
+
hash.map { |key, value| scan_key_value(key, value) }.inject(:collate) || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.scan_key_value(key, value)
|
24
|
+
key_scan = scan(key)
|
25
|
+
return key_scan if SensitiveDataFilter.whitelisted_key? key
|
26
|
+
key_scan.collate(scan(value))
|
21
27
|
end
|
22
28
|
|
23
29
|
def self.whitelist(matches)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensitive_data_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Berardi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-12-
|
12
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|