rubocop-config-captive 1.7.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +1 -0
- data/config/rubocop-captive.yml +7 -0
- data/config/rubocop-magic_numbers.yml +25 -0
- data/lib/rubocop/captive/version.rb +1 -1
- data/lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb +61 -0
- data/lib/rubocop/cop/captive/rspec/specify_before_parameter.rb +2 -1
- data/rubocop-config-captive.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39dbb9aa92c28b0b4fdc2261998070f806320408ccb3c22db2ae1fcfb5d3397a
|
4
|
+
data.tar.gz: 4b57010fca3ff9afa6cd45b9e0b77f53ddae1cf6c2bd529b6351bf8662bdd544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e272228a09888fea439fda8016db538fad6ac7741158685509a8c07ee231466369eb37157218bb3afe18cd99f1caa0c9032a18b19160899acc4d47d3e7910297
|
7
|
+
data.tar.gz: ce886fac54be48d39466999a0552f43be31d60860f95440bf6265999a448150812537c67f02dc6b9001d941bdc013b07bcf6e7da2da46f55072edf01e95bcc06
|
data/config/default.yml
CHANGED
data/config/rubocop-captive.yml
CHANGED
@@ -5,6 +5,7 @@ require:
|
|
5
5
|
- ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
|
6
6
|
- ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
7
7
|
- ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
|
8
|
+
- ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
|
8
9
|
- ../lib/rubocop/cop/captive/string_where_in_scope.rb
|
9
10
|
- ../lib/rubocop/cop/captive/no_app_env.rb
|
10
11
|
|
@@ -42,6 +43,12 @@ Captive/Rails/NoEmailFromController:
|
|
42
43
|
Include:
|
43
44
|
- 'app/controllers/**/*'
|
44
45
|
|
46
|
+
# Rails
|
47
|
+
Captive/Rails/ForceSslEnabledInProduction:
|
48
|
+
Description: "Ensures SSL is forced in production, so that secure cookies are used."
|
49
|
+
Include:
|
50
|
+
- 'config/environments/production.rb'
|
51
|
+
|
45
52
|
# other
|
46
53
|
Captive/StringWhereInScope:
|
47
54
|
Description: 'The `where` method should be used in a scope in a model.'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-magic_numbers
|
3
|
+
|
4
|
+
MagicNumbers/NoArgument:
|
5
|
+
Enabled: true
|
6
|
+
PermittedValues:
|
7
|
+
- 0
|
8
|
+
Exclude:
|
9
|
+
- spec/**/*_spec.rb
|
10
|
+
|
11
|
+
# Cette règle empeche de pouvoir faire des variables d'instances qui servent de compteur
|
12
|
+
MagicNumbers/NoAssignment:
|
13
|
+
Enabled: false
|
14
|
+
Exclude:
|
15
|
+
- spec/**/*_spec.rb
|
16
|
+
|
17
|
+
MagicNumbers/NoDefault:
|
18
|
+
Enabled: true
|
19
|
+
Exclude:
|
20
|
+
- spec/**/*_spec.rb
|
21
|
+
|
22
|
+
MagicNumbers/NoReturn:
|
23
|
+
Enabled: true
|
24
|
+
Exclude:
|
25
|
+
- spec/**/*_spec.rb
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Captive
|
6
|
+
module Rails
|
7
|
+
##
|
8
|
+
# This cop ensures the config force_ssl is set to true.
|
9
|
+
#
|
10
|
+
# Pourquoi il faut configurer le `force_ssl` à `true` en production ?
|
11
|
+
# 1) Ça redirige les requêtes http → https. C’est une option que permet également le routeur de Scalingo
|
12
|
+
# 2) Ça ajoute un flag `Secure` sur les Cookies. S’il n’est pas présent, c’est considéré comme une vulnérabilité car ça peut permettre à un pirate de récupérer le cookie en HTTP et potentiellement voler la session.
|
13
|
+
# @see https://www.notion.so/captive/Corriger-la-vuln-rabilit-Insecure-cookie-setting-missing-Secure-flag-7962ae24774d4de39dcda5a80cca4fcf?pvs=26&qid=
|
14
|
+
# @see https://support.detectify.com/support/solutions/articles/48001048982-cookie-lack-secure-flag article détaillant la sécurité du cookie
|
15
|
+
class ForceSslEnabledInProduction < Base
|
16
|
+
extend AutoCorrector
|
17
|
+
|
18
|
+
MSG = "force_ssl should be enabled in production."
|
19
|
+
|
20
|
+
def on_send(node)
|
21
|
+
if setting_force_ssl_not_true?(node)
|
22
|
+
add_offense(node, message: MSG) do |corrector|
|
23
|
+
# Replace with 'true' only if the argument is not already 'true'
|
24
|
+
unless node.arguments.first.true_type?
|
25
|
+
corrector.replace(
|
26
|
+
node.arguments.first.source_range,
|
27
|
+
"true"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_new_investigation
|
35
|
+
processed_source.comments.each do |comment|
|
36
|
+
check_comment(comment)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def setting_force_ssl_not_true?(node)
|
43
|
+
node.method_name == :force_ssl= && !node.arguments.first.true_type?
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_comment(comment)
|
47
|
+
return unless force_ssl_commented?(comment.text)
|
48
|
+
|
49
|
+
add_offense(comment.loc.expression, message: MSG) do |corrector|
|
50
|
+
corrector.replace(comment.loc.expression, "config.force_ssl = true")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def force_ssl_commented?(comment_text)
|
55
|
+
comment_text.match?(/^\s*#.*config\.force_ssl\s*=\s*true/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -52,8 +52,9 @@ module RuboCop
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def add_parameter(node)
|
55
|
+
magic_number = 6
|
55
56
|
source = node.loc.expression.source
|
56
|
-
source.insert(source.index("before") +
|
57
|
+
source.insert(source.index("before") + magic_number, "(:each)")
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |gem|
|
|
32
32
|
gem.add_dependency("rubocop-rspec", "~> 2.22.0")
|
33
33
|
gem.add_dependency("rubocop-capybara", "~> 2.18.0")
|
34
34
|
gem.add_dependency("rubocop-factory_bot", "~> 2.23.1")
|
35
|
+
gem.add_dependency("rubocop-magic_numbers", "~> 0.4.0")
|
35
36
|
gem.add_development_dependency("rspec", "~> 3.12")
|
36
37
|
# gem.metadata['rubygems_mfa_required'] = 'true'
|
37
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-config-captive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captive
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -110,6 +110,20 @@ dependencies:
|
|
110
110
|
- - "~>"
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 2.23.1
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rubocop-magic_numbers
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 0.4.0
|
120
|
+
type: :runtime
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - "~>"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.4.0
|
113
127
|
- !ruby/object:Gem::Dependency
|
114
128
|
name: rspec
|
115
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +169,7 @@ files:
|
|
155
169
|
- config/rubocop-gemspec.yml
|
156
170
|
- config/rubocop-layout.yml
|
157
171
|
- config/rubocop-lint.yml
|
172
|
+
- config/rubocop-magic_numbers.yml
|
158
173
|
- config/rubocop-metrics.yml
|
159
174
|
- config/rubocop-naming.yml
|
160
175
|
- config/rubocop-performance.yml
|
@@ -169,6 +184,7 @@ files:
|
|
169
184
|
- lib/rubocop/captive/version.rb
|
170
185
|
- lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb
|
171
186
|
- lib/rubocop/cop/captive/no_app_env.rb
|
187
|
+
- lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
|
172
188
|
- lib/rubocop/cop/captive/rails/no_email_from_controller.rb
|
173
189
|
- lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
174
190
|
- lib/rubocop/cop/captive/string_where_in_scope.rb
|