-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use more secure methods #3291
Use more secure methods #3291
Conversation
@@ -186,7 +186,7 @@ def self.hash_value(val, opts = {}, name = nil) | |||
return nil if val.nil? | |||
|
|||
param = if val.is_a?(String) | |||
val.start_with?('{') ? JSON.load(val) : Hash[val.strip.split(/\s*,\s*/).map{|v| v.split(':', 2)}] | |||
val.start_with?('{') ? JSON.parse(val) : Hash[val.strip.split(/\s*,\s*/).map{|v| v.split(':', 2)}] |
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.
Memo:
JSON.load
wraps JSON.parse
and it modifies some default options of JSON::Parser
:
https://github.com/flori/json/blob/7b452b290502a5cca8fc6403f31275c83e0e3d48/lib/json/common.rb#L569
https://github.com/flori/json/blob/7b452b290502a5cca8fc6403f31275c83e0e3d48/lib/json/common.rb#L422
https://docs.ruby-lang.org/ja/latest/class/JSON=3a=3aParser.html
So that the behavior is also changed a bit but I believe it's no problem on this case.
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.
Thanks for the clarification. Yeah, in this case, using JSON.parse
instead of JSON.load
does not cause issues.
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.
Could you add a reference to why it should be fixed in the commit message?
Then LGTM.
27ed7dd
to
a6af121
Compare
I doubt whether https://deepsource.io/gh/cosmo0920/fluentd/issue/RB-SC1002 is consistent or not. How about quoting the following:
|
* https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Security/Open ``` `Kernel#open` and `URI.open` enable not only file access but also process invocation by prefixing a pipe symbol (e.g., `open(“| ls”)`). So, it may lead to a serious security risk by using variable input to the argument of `Kernel#open` and `URI.open`. It would be better to use `File.open`, `IO.popen` or `URI.parse#open` explicitly. ``` Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
* https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Security/JSONLoad ``` Autocorrect is disabled by default because it's potentially dangerous. If using a stream, like `JSON.load(open('file'))`, it will need to call `#read` manually, like `JSON.parse(open('file').read)`. If reading single values (rather than proper JSON objects), like `JSON.load('false')`, it will need to pass the `quirks_mode: true` option, like `JSON.parse('false', quirks_mode: true)`. Other similar issues may apply. ``` Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
a6af121
to
77d79e9
Compare
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.
LGTM
Which issue(s) this PR fixes:
None
What this PR does / why we need it:
DeepSource complains that fluentd uses insecure methods:
Kernel.open
: https://deepsource.io/gh/cosmo0920/fluentd/issue/RB-SC1004/JSON.load
: https://deepsource.io/gh/cosmo0920/fluentd/issue/RB-SC1002/occurrencesDocs Changes:
No need.
Release Note:
Same as title.