-
Notifications
You must be signed in to change notification settings - Fork 738
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
Fix compatibility with --enable-frozen-string-literal
#1855
Fix compatibility with --enable-frozen-string-literal
#1855
Conversation
Hi there 👋, @DryRunSecurity here, below is a summary of our analysis and findings.
Note 🟢 Risk threshold not exceeded. Change Summary (click to expand)The following is a summary of changes in this pull request made by me, your security buddy 🤖. Note that this summary is auto-generated and not meant to be a definitive list of security issues but rather a helpful summary from a security perspective. Summary: The changes in this pull request are primarily focused on improving the functionality and usability of the Brakeman security scanner for Ruby on Rails applications. The changes span several files and cover a range of improvements, including:
While these changes do not directly address any known security vulnerabilities, they contribute to the overall security and reliability of the Brakeman tool, which is an important application security tool for Ruby on Rails developers. By improving the usability, performance, and robustness of the Brakeman scanner, these changes can indirectly enhance the security of the applications being analyzed. Files Changed:
Powered by DryRun Security |
lib/brakeman/warning.rb
Outdated
@@ -53,6 +53,7 @@ def initialize options = {} | |||
OPTIONS.each do |key, var| | |||
self.instance_variable_set(var, options[key]) | |||
end | |||
@warning_type = @warning_type.dup |
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.
Most of these look okay, but I'm a bit surprised by this one. I don't expect warning_type
to get modified. Any clues to where that might be happening?
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.
It fails two tests:
1) Error:
TestReportGeneration#test_tabs_sanity:
FrozenError: can't modify frozen String: "Cross-Site Scripting", created at /Users/byroot/src/github.com/casperisfine/brakeman/lib/brakeman/checks/check_content_tag.rb:199
lib/brakeman/report/report_tabs.rb:12:in `gsub!'
lib/brakeman/report/report_tabs.rb:12:in `block (2 levels) in generate_report'
lib/brakeman/report/report_tabs.rb:10:in `map'
lib/brakeman/report/report_tabs.rb:10:in `block in generate_report'
lib/brakeman/report/report_tabs.rb:8:in `map'
lib/brakeman/report/report_tabs.rb:8:in `generate_report'
lib/brakeman/report.rb:107:in `generate'
lib/brakeman/report.rb:58:in `format'
lib/brakeman/report.rb:63:in `method_missing'
test/tests/report_generation.rb:67:in `test_tabs_sanity'
2) Error:
TestTabsOutput#test_reported_warnings:
FrozenError: can't modify frozen String: "Cross-Site Request Forgery", created at /Users/byroot/src/github.com/casperisfine/brakeman/lib/brakeman/checks/check_csrf_token_forgery_cve.rb:19
lib/brakeman/report/report_tabs.rb:12:in `gsub!'
lib/brakeman/report/report_tabs.rb:12:in `block (2 levels) in generate_report'
lib/brakeman/report/report_tabs.rb:10:in `map'
lib/brakeman/report/report_tabs.rb:10:in `block in generate_report'
lib/brakeman/report/report_tabs.rb:8:in `map'
lib/brakeman/report/report_tabs.rb:8:in `generate_report'
lib/brakeman/report.rb:107:in `generate'
lib/brakeman/report.rb:58:in `format'
lib/brakeman/report.rb:63:in `method_missing'
test/tests/tabs_output.rb:9:in `setup'
class Brakeman::Report::Tabs < Brakeman::Report::Table
def generate_report
[[:generic_warnings, "General"], [:controller_warnings, "Controller"],
[:model_warnings, "Model"], [:template_warnings, "Template"]].map do |meth, category|
self.send(meth).map do |w|
line = w.line || 0
w.warning_type.gsub!(/[^\w\s]/, ' ')
"#{(w.file.absolute)}\t#{line}\t#{w.warning_type}\t#{category}\t#{w.format_message}\t#{w.confidence_name}"
end.join "\n"
end.join "\n"
end
end
It very explicitly mutate that string in place, hence why I chose to make it mutable. But to be honest it looks like a bug, but I don't know brakeman enough to decide.
If I delete that gsub!
the test suite still pass.
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.
Let's delete the gsub!
. Not sure what I thought it was doing... but it doesn't. Also I plan to deprecate+remove that report format.
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.
Done.
62904ec
to
a34e5be
Compare
About the dependencies
Looks like @zenspider merged a fix: seattlerb/ruby2ruby@3d5966e, not sure when we'll get a release thought.
I could monkey patch the one |
I can have a release of r2r out this week. |
Ok, so I did it without monkey patch, I just include a module in all of Brakeman's |
8675374
to
c6344ea
Compare
DryRun Security SummaryThe provided code changes cover a variety of updates and improvements to the Brakeman security scanner for Ruby on Rails applications, including dependency version updates, CircleCI configuration improvements, refactoring and optimizations, and integration of specific features, all focused on improving the functionality, performance, and security of the Brakeman tool. Expand for full summarySummary: The provided code changes cover a variety of updates and improvements to the Brakeman security scanner for Ruby on Rails applications. The changes include:
Overall, the changes appear to be focused on improving the functionality, performance, and security of the Brakeman tool. While none of the individual changes introduce obvious security vulnerabilities, the reviewer should carefully consider the potential impact of each change, especially those related to user input handling, file path management, and report generation, to ensure the ongoing security and reliability of the Brakeman scanner. Files Changed:
Code AnalysisWe ran
Riskiness🟢 Risk threshold not exceeded. |
thanks @zenspider I updated the dependency, now the entire test suite passes with |
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.
Having fixed a lot of these now, I fully approve of this PR. One style note that I eschew String#<<
which seems in high use here.
@@ -27,7 +27,7 @@ def initialize *args | |||
end | |||
|
|||
def generate_report | |||
out = "# BRAKEMAN REPORT\n\n" << | |||
out = +"# BRAKEMAN REPORT\n\n" << |
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.
Personally I really don't like String#<<
... I wound up changing a lot of my old code from this to Array#<<
+ #join
. It led to similarly sized diffs, array mutation (which I don't mind) instead of string mutation (which I do), and fits my current style a lot more.
Not recommending this change here... just something to consider.
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.
Indeed... I'm sure there are a lot of improvements that could be made 😄
c6344ea
to
ccd4db3
Compare
Since Ruby 2.3, Ruby can be started with this options, and it's expected to become the default in Ruby 4.0 (no release date yet). This commit fixes the callsites that assume string literal are mutable. Note however that a large part of the test suite is still failing, because of two dependencies: - ruby2ruby: seattlerb/ruby2ruby#58 - erubis: (this one is abandoned so can hardly be fixed).
ccd4db3
to
491e62c
Compare
Took some time to get all the testing done, but other than one ruby2ruby output that changed (will follow up on that), looks good! Thanks for your contribution! |
Since Ruby 2.3, Ruby can be started with this options, and it's expected to become the default in Ruby 4.0 (no release date yet).
This commit fixes the callsites that assume string literal are mutable.
Note however that a large part of the test suite is still failing, because of two dependencies:
--enable-frozen-string-literal
seattlerb/ruby2ruby#58