moderate_parameters 0.2.6 → 0.3.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 +4 -4
- data/Gemfile.lock +37 -37
- data/lib/generators/templates/moderate_parameters.rb +2 -0
- data/lib/moderate_parameters/parameters.rb +55 -6
- data/lib/moderate_parameters/version.rb +1 -1
- data/moderate_parameters.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33118bf4c165859d1135b0628d3c1177560003900ea7637a4d97bb149f00fbef
|
|
4
|
+
data.tar.gz: cef73308c79623677793428b8704e667eca870e2f4463ffc41efb878d030429d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12d73a15669d2af4b6b579b1fe0905efb191bc3474bb174fb011b2065d1efbce9c91efcf9f379984139a506c85cdf1b34ca8966df6dbf996d57c8e291487ff31
|
|
7
|
+
data.tar.gz: 68c48b72df1c5a99a7287330c4cfa2275c6cfdc8ccfc5c6af28db5b24e5b4bff232709e24c949a58d645fbb0ef1ea9fe0e751f7ad6e01c8c9348ab578eb3ff58
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
moderate_parameters (0.
|
|
4
|
+
moderate_parameters (0.3.0)
|
|
5
5
|
actionpack (>= 4.2, < 6.1)
|
|
6
6
|
activemodel (>= 4.2, < 6.1)
|
|
7
7
|
activesupport (>= 4.2, < 6.1)
|
|
@@ -10,51 +10,51 @@ PATH
|
|
|
10
10
|
GEM
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
|
-
actionpack (6.0.
|
|
14
|
-
actionview (= 6.0.
|
|
15
|
-
activesupport (= 6.0.
|
|
16
|
-
rack (~> 2.0)
|
|
13
|
+
actionpack (6.0.2.1)
|
|
14
|
+
actionview (= 6.0.2.1)
|
|
15
|
+
activesupport (= 6.0.2.1)
|
|
16
|
+
rack (~> 2.0, >= 2.0.8)
|
|
17
17
|
rack-test (>= 0.6.3)
|
|
18
18
|
rails-dom-testing (~> 2.0)
|
|
19
19
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
20
|
-
actionview (6.0.
|
|
21
|
-
activesupport (= 6.0.
|
|
20
|
+
actionview (6.0.2.1)
|
|
21
|
+
activesupport (= 6.0.2.1)
|
|
22
22
|
builder (~> 3.1)
|
|
23
23
|
erubi (~> 1.4)
|
|
24
24
|
rails-dom-testing (~> 2.0)
|
|
25
25
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
26
|
-
activemodel (6.0.
|
|
27
|
-
activesupport (= 6.0.
|
|
28
|
-
activesupport (6.0.
|
|
26
|
+
activemodel (6.0.2.1)
|
|
27
|
+
activesupport (= 6.0.2.1)
|
|
28
|
+
activesupport (6.0.2.1)
|
|
29
29
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
30
30
|
i18n (>= 0.7, < 2)
|
|
31
31
|
minitest (~> 5.1)
|
|
32
32
|
tzinfo (~> 1.1)
|
|
33
|
-
zeitwerk (~> 2.
|
|
33
|
+
zeitwerk (~> 2.2)
|
|
34
34
|
appraisal (2.2.0)
|
|
35
35
|
bundler
|
|
36
36
|
rake
|
|
37
37
|
thor (>= 0.14.0)
|
|
38
|
-
builder (3.2.
|
|
38
|
+
builder (3.2.4)
|
|
39
39
|
coderay (1.1.2)
|
|
40
40
|
concurrent-ruby (1.1.5)
|
|
41
|
-
crass (1.0.
|
|
41
|
+
crass (1.0.6)
|
|
42
42
|
diff-lcs (1.3)
|
|
43
43
|
erubi (1.9.0)
|
|
44
|
-
i18n (1.
|
|
44
|
+
i18n (1.8.2)
|
|
45
45
|
concurrent-ruby (~> 1.0)
|
|
46
|
-
loofah (2.
|
|
46
|
+
loofah (2.4.0)
|
|
47
47
|
crass (~> 1.0.2)
|
|
48
48
|
nokogiri (>= 1.5.9)
|
|
49
49
|
method_source (0.9.2)
|
|
50
50
|
mini_portile2 (2.4.0)
|
|
51
|
-
minitest (5.
|
|
52
|
-
nokogiri (1.10.
|
|
51
|
+
minitest (5.14.0)
|
|
52
|
+
nokogiri (1.10.7)
|
|
53
53
|
mini_portile2 (~> 2.4.0)
|
|
54
54
|
pry (0.12.2)
|
|
55
55
|
coderay (~> 1.1.0)
|
|
56
56
|
method_source (~> 0.9.0)
|
|
57
|
-
rack (2.
|
|
57
|
+
rack (2.1.1)
|
|
58
58
|
rack-test (1.1.0)
|
|
59
59
|
rack (>= 1.0, < 3)
|
|
60
60
|
rails-dom-testing (2.0.3)
|
|
@@ -62,40 +62,40 @@ GEM
|
|
|
62
62
|
nokogiri (>= 1.6)
|
|
63
63
|
rails-html-sanitizer (1.3.0)
|
|
64
64
|
loofah (~> 2.3)
|
|
65
|
-
railties (6.0.
|
|
66
|
-
actionpack (= 6.0.
|
|
67
|
-
activesupport (= 6.0.
|
|
65
|
+
railties (6.0.2.1)
|
|
66
|
+
actionpack (= 6.0.2.1)
|
|
67
|
+
activesupport (= 6.0.2.1)
|
|
68
68
|
method_source
|
|
69
69
|
rake (>= 0.8.7)
|
|
70
70
|
thor (>= 0.20.3, < 2.0)
|
|
71
71
|
rake (10.5.0)
|
|
72
|
-
rspec (3.
|
|
73
|
-
rspec-core (~> 3.
|
|
74
|
-
rspec-expectations (~> 3.
|
|
75
|
-
rspec-mocks (~> 3.
|
|
76
|
-
rspec-core (3.
|
|
77
|
-
rspec-support (~> 3.
|
|
78
|
-
rspec-expectations (3.
|
|
72
|
+
rspec (3.9.0)
|
|
73
|
+
rspec-core (~> 3.9.0)
|
|
74
|
+
rspec-expectations (~> 3.9.0)
|
|
75
|
+
rspec-mocks (~> 3.9.0)
|
|
76
|
+
rspec-core (3.9.1)
|
|
77
|
+
rspec-support (~> 3.9.1)
|
|
78
|
+
rspec-expectations (3.9.0)
|
|
79
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
80
|
-
rspec-support (~> 3.
|
|
81
|
-
rspec-mocks (3.
|
|
80
|
+
rspec-support (~> 3.9.0)
|
|
81
|
+
rspec-mocks (3.9.1)
|
|
82
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
-
rspec-support (~> 3.
|
|
84
|
-
rspec-support (3.
|
|
83
|
+
rspec-support (~> 3.9.0)
|
|
84
|
+
rspec-support (3.9.2)
|
|
85
85
|
rspec_junit_formatter (0.4.1)
|
|
86
86
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
87
|
-
thor (0.
|
|
87
|
+
thor (1.0.1)
|
|
88
88
|
thread_safe (0.3.6)
|
|
89
|
-
tzinfo (1.2.
|
|
89
|
+
tzinfo (1.2.6)
|
|
90
90
|
thread_safe (~> 0.1)
|
|
91
|
-
zeitwerk (2.2.
|
|
91
|
+
zeitwerk (2.2.2)
|
|
92
92
|
|
|
93
93
|
PLATFORMS
|
|
94
94
|
ruby
|
|
95
95
|
|
|
96
96
|
DEPENDENCIES
|
|
97
97
|
appraisal (= 2.2.0)
|
|
98
|
-
bundler (~> 2.0
|
|
98
|
+
bundler (~> 2.0)
|
|
99
99
|
moderate_parameters!
|
|
100
100
|
pry (~> 0.12.2)
|
|
101
101
|
rake (~> 10.0)
|
|
@@ -103,4 +103,4 @@ DEPENDENCIES
|
|
|
103
103
|
rspec_junit_formatter (= 0.4.1)
|
|
104
104
|
|
|
105
105
|
BUNDLED WITH
|
|
106
|
-
2.
|
|
106
|
+
2.1.4
|
|
@@ -4,4 +4,6 @@ ModerateParameters.configure do |config|
|
|
|
4
4
|
# Enables/Disables logging occurrences of
|
|
5
5
|
# reading/writing from ActionController::Parameters.
|
|
6
6
|
config.breadcrumbs_enabled = false
|
|
7
|
+
# Sets where to log the ModerateParameters output
|
|
8
|
+
config.logger = ActiveSupport::Logger.new('log/moderate_parameters.log')
|
|
7
9
|
end
|
|
@@ -8,7 +8,11 @@ module ModerateParameters
|
|
|
8
8
|
filters.each do |filter|
|
|
9
9
|
case filter
|
|
10
10
|
when Symbol, String
|
|
11
|
-
|
|
11
|
+
if non_scalar?(self[filter])
|
|
12
|
+
non_scalar_value_filter(params, filter, controller_name, action)
|
|
13
|
+
else
|
|
14
|
+
permitted_scalar_filter(params, filter)
|
|
15
|
+
end
|
|
12
16
|
when Hash
|
|
13
17
|
cust_hash_filter(params, filter, controller_name, action)
|
|
14
18
|
end
|
|
@@ -20,13 +24,26 @@ module ModerateParameters
|
|
|
20
24
|
|
|
21
25
|
private
|
|
22
26
|
|
|
27
|
+
def write_to_log(options)
|
|
28
|
+
ActiveSupport::Notifications.instrument('moderate_parameters') do |payload|
|
|
29
|
+
payload.merge!(options)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
23
33
|
def incoming_params_logging(params, controller_name, action)
|
|
24
34
|
unpermitted_keys(params).each do |k|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
write_to_log(message: "#{@context || 'Top Level'} is missing: #{k}",
|
|
36
|
+
action: action,
|
|
37
|
+
controller: controller_name)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def non_scalar_value_filter(params, key, controller_name, action)
|
|
42
|
+
if has_key?(key) && !permitted_scalar?(self[key])
|
|
43
|
+
params[key] = self[key].class.new
|
|
44
|
+
write_to_log(message: "#{@context || 'Top Level'} is missing: #{params[key]} value for #{key}",
|
|
45
|
+
action: action,
|
|
46
|
+
controller: controller_name)
|
|
30
47
|
end
|
|
31
48
|
end
|
|
32
49
|
|
|
@@ -34,6 +51,38 @@ module ModerateParameters
|
|
|
34
51
|
value.is_a?(Array) || value.is_a?(Parameters)
|
|
35
52
|
end
|
|
36
53
|
|
|
54
|
+
def permit_any_in_array(array)
|
|
55
|
+
[].tap do |sanitized|
|
|
56
|
+
array.each do |element|
|
|
57
|
+
case element
|
|
58
|
+
when ->(e) { permitted_scalar?(e) }
|
|
59
|
+
sanitized << element
|
|
60
|
+
when Parameters
|
|
61
|
+
sanitized << permit_any_in_parameters(element)
|
|
62
|
+
else
|
|
63
|
+
# Log it
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def permit_any_in_parameters(params)
|
|
70
|
+
self.class.new.tap do |sanitized|
|
|
71
|
+
params.each do |key, value|
|
|
72
|
+
case value
|
|
73
|
+
when ->(v) { permitted_scalar?(v) }
|
|
74
|
+
sanitized[key] = value
|
|
75
|
+
when Array
|
|
76
|
+
sanitized[key] = permit_any_in_array(value)
|
|
77
|
+
when Parameters
|
|
78
|
+
sanitized[key] = permit_any_in_parameters(value)
|
|
79
|
+
else
|
|
80
|
+
# Log It
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
37
86
|
EMPTY_HASH ||= {}
|
|
38
87
|
EMPTY_ARRAY ||= []
|
|
39
88
|
def cust_hash_filter(params, filter, controller_name, action)
|
data/moderate_parameters.gemspec
CHANGED
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
|
|
|
41
41
|
spec.add_dependency 'activesupport', '>= 4.2', '< 6.1'
|
|
42
42
|
spec.add_dependency 'railties', '>= 4.2', '< 6.1'
|
|
43
43
|
|
|
44
|
-
spec.add_development_dependency 'bundler', '~> 2.0
|
|
44
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
45
45
|
spec.add_development_dependency 'pry', '~> 0.12.2'
|
|
46
46
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
47
47
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moderate_parameters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Boe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|
|
@@ -96,14 +96,14 @@ dependencies:
|
|
|
96
96
|
requirements:
|
|
97
97
|
- - "~>"
|
|
98
98
|
- !ruby/object:Gem::Version
|
|
99
|
-
version: 2.0
|
|
99
|
+
version: '2.0'
|
|
100
100
|
type: :development
|
|
101
101
|
prerelease: false
|
|
102
102
|
version_requirements: !ruby/object:Gem::Requirement
|
|
103
103
|
requirements:
|
|
104
104
|
- - "~>"
|
|
105
105
|
- !ruby/object:Gem::Version
|
|
106
|
-
version: 2.0
|
|
106
|
+
version: '2.0'
|
|
107
107
|
- !ruby/object:Gem::Dependency
|
|
108
108
|
name: pry
|
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|