-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rubocop security fix #253
Rubocop security fix #253
Conversation
cc @abonas |
okay, I see there is some work in progress.. |
Upgrading the gem, adds new rules to check. What do you think it would be better: fix the offences? adjust the rubocop rules to silent them? |
@@ -2,6 +2,7 @@ | |||
# https://github.com/bbatsov/rubocop/blob/master/config/ | |||
|
|||
AllCops: | |||
TargetRubyVersion: 2.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this parameter required?
does it mean that it should "=" 2.2? or >= 2.2 ? the gemspec defines it as >= 2.2, and miq is already at a higher version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tag is used to describe the minimum supported version. So it is a '>= 2.2'.
When running rubocop on my local, it uses ruby 2.1 parser instead that the current ruby version (i.e. 2.4.1). Adding this line, it ensures that Rubocop doesn't use a parser for a version below 2.2.0.
I think it varies. some most likely should be fixed, and some should be silenced. |
Cool! Then, it would be great than contributors here would say which rules keep and which one disable. |
|
LGTM. Specs are failing though, can you check why? |
@cfcosta ^ |
I have tried to apply same cops as ManageIQ, but it raises 1.1k offenses. |
@xeviknal I agree with @abonas that each warning should be evaluated.
I think everything else should be fixed... But it's a lot of work :S |
8c8347b
to
7ebec18
Compare
@josejulio @israel-hdez @cfcosta @abonas I totally agree with what you said before. I also introduced the following disabling:
Apart from that, looking at Travis, there are some tricky scenarios I would appreciate some of your advice:
Any suggestion? |
See in rubocop manual: disabling cops within the source |
lib/hawkular/alerts/alerts_api.rb
Outdated
else | ||
plugins = [action_plugin] | ||
end | ||
plugins = if action_plugin.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ternary operator will look better:
plugins = action_plugin.nil? ? http_get('plugins') : [action_plugin]
lib/hawkular/hawkular_client.rb
Outdated
@@ -18,6 +16,10 @@ def initialize(hash) | |||
@state = hash | |||
end | |||
|
|||
def respond_to_missing? | |||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. It should only return true
if method_missing
will process the call (won't fail).
else | ||
ret = subs[0] | ||
end | ||
ret = if subs.length > 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I also think ternary operator looks better:
ret = subs.length > 1 ? subs.collect(&:capitalize).join : subs[0]
7ebec18
to
0b0fc98
Compare
0b0fc98
to
6ac022c
Compare
@israel-hdez for C: Style/MethodMissing, falling back to super will change the behavior of method missing. If a consumer expected to rescue a Hawkular::ArgumentError, it would fail since now the error thrown is a NoMethodError. |
Conflicts: spec/integration/prometheus_spec.rb
@xeviknal yes, it'll be a small difference. |
@israel-hdez changes are introduced. But specs are not passing. I see they are not passing as well in master. Do you think I could help you with that? |
@xeviknal Those errors are because of the new inventory work. Still pending to fix. |
Cool! For me, they are ready :) |
lib/hawkular/hawkular_client.rb
Outdated
@@ -18,6 +16,10 @@ def initialize(hash) | |||
@state = hash | |||
end | |||
|
|||
def respond_to_missing?(method_name, include_private = false) | |||
method_name.to_s.start_with?('inventory_', 'alerts_', 'operations_', 'tokens_', 'prometheus_') || super |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rechecked this one, and I think that you still need to delegate to respond_to? to the relevant sub_client. Since the prefix won't guarantee that the method exists in the subclient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@israel-hdez I got what you said. Then answer to respond_to?
becomes more precise when checking to the corresponding subclient.
In the proposed solution, i used respond_to?
inside method_missing
. I am wondering if this is a bad approach. Does anybody know?
For me, if it is okay, it is ready to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now looks 👍
This PR is fixing a small vulnerability for Rubocop < 0.48.1.
Here the vulnerability details:
https://www.cvedetails.com/cve/CVE-2017-8418/
rubocop/rubocop#4336
It is related to unsecure metadata stored in a /tmp folder. Allowing any user of the machine to tamper that caching data.
In order to fix it, I just upgrade rubocop version to the latest available one.
On the other hand, I have updated the minimum supported ruby version for rubocop to analyze. This stopped to show errors on 2.2+ new syntax.