Skip to content
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

https://github.com/presidentbeef/brakeman/issues/1841 #1842

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kwerle
Copy link

@kwerle kwerle commented Apr 30, 2024

brakeman still references haml 4 - which is a bit long in the tooth (Haml::Filter::Coffee class vs. module) #1841

brakeman still references haml 4 - which is a bit long in the tooth (Haml::Filter::Coffee class vs. module) presidentbeef#1841
Copy link

Hi there 👋, @DryRunSecurity here, below is a summary of our analysis and findings.

DryRun Security Status Findings
Configured Codepaths Analyzer 0 findings
Sensitive Files Analyzer 0 findings
Authn/Authz Analyzer 0 findings
AppSec Analyzer 0 findings
Secrets Analyzer 0 findings

Note

🟢 Risk threshold not exceeded.

Powered by DryRun Security

@presidentbeef
Copy link
Owner

Hmmm... I kind of think if Haml has these filters installed by default now, that the fake filters aren't needed? 🤔 And I think they were added in 6.0 when Hamlit became Haml?

If I recall correctly, the fake filters were just to stub out the embedding of other languages and avoid raising errors. It wasn't to override the filters.

@kwerle
Copy link
Author

kwerle commented Nov 20, 2024

Hmmm... I kind of think if Haml has these filters installed by default now, that the fake filters aren't needed? 🤔 And I think they were added in 6.0 when Hamlit became Haml?

If I recall correctly, the fake filters were just to stub out the embedding of other languages and avoid raising errors. It wasn't to override the filters.

I'm a little lost. What is the correct solution to #1841?

@kwerle
Copy link
Author

kwerle commented Nov 20, 2024

Specifically, we would like to use brakeman-min (6.1.2 or so) with haml (6.3.0) and we can't because brakeman refers to these constants as modules and haml declares them as classes. I can't think of any solution to this other than the one I've proposed (short of forking brakeman - which seems ridiculous).

Our version of brakeman-min is a little behind, but this is the most recent version of haml.

@presidentbeef
Copy link
Owner

I might have to look again, but I believe I was thinking instead of defining the classes if defined?(Haml::Filters::Coffee) && Haml::Filters::Coffee.class == Class to only define the modules if the classes aren't available.

In other words, for newer Haml Brakeman doesn't need to do anything, just skip defining the modules.

@kwerle
Copy link
Author

kwerle commented Nov 20, 2024

In other words, for newer Haml Brakeman doesn't need to do anything, just skip defining the modules.

I see! I can take a poke at that.

Copy link

dryrunsecurity bot commented Nov 21, 2024

DryRun Security Summary

The provided code change is a maintenance update to the Brakeman project, a security scanner for Ruby on Rails applications, which involves handling the parsing of HAML files that contain embedded code, including the definition of "fake" filters for CoffeeScript, Markdown, and Sass code embedded within HAML templates.

Expand for full summary

Summary:

The provided code change is related to the Brakeman project, a security scanner for Ruby on Rails applications. The change is made to the lib/brakeman/parsers/haml_embedded.rb file, which is responsible for handling the parsing of HAML (HTML Abstraction Markup Language) files that contain embedded code. The key change is the handling of the Haml::Filters::Coffee module, which is now checked to see if it is defined as a class. If it is defined as a module, the code proceeds to define the Haml::Filters::Coffee, Haml::Filters::Markdown, and Haml::Filters::Sass modules, which are "fake" filters for HAML. These filters are used to handle the compilation of CoffeeScript, Markdown, and Sass code embedded within HAML templates.

From an application security perspective, this change does not appear to introduce any significant security concerns. However, it's worth noting that the use of "fake" filters for handling embedded code could potentially introduce some complexity and maintainability issues if not properly managed. It's important to ensure that these filters are kept up-to-date and properly tested to avoid any potential security vulnerabilities that could arise from the handling of embedded code. Overall, this code change seems to be a maintenance update to the Brakeman project, and it does not appear to introduce any obvious security risks.

Files Changed:

  • lib/brakeman/parsers/haml_embedded.rb: This file is responsible for handling the parsing of HAML files that contain embedded code. The key change is the handling of the Haml::Filters::Coffee module, which is now checked to see if it is defined as a class. If it is defined as a module, the code proceeds to define the Haml::Filters::Coffee, Haml::Filters::Markdown, and Haml::Filters::Sass modules, which are "fake" filters for HAML. These filters are used to handle the compilation of CoffeeScript, Markdown, and Sass code embedded within HAML templates.

Code Analysis

We ran 9 analyzers against 1 file and 0 analyzers had findings. 9 analyzers had no findings.

Riskiness

🟢 Risk threshold not exceeded.

View PR in the DryRun Dashboard.

@kwerle
Copy link
Author

kwerle commented Nov 21, 2024

OK, the good news is that I think that will all work. The .. bad? new is that brakeman is locked to haml 5.1 so I'm having to do some other gymnastics to work around this issue anyway. Mostly it means no longer including brakeman in our gemfile (probably the right thing to do) and just run it from a container.

So... victory? I guess merge this if you think it's the right thing.

And thank you!

@presidentbeef
Copy link
Owner

Yes, looks like there are some breaking changes with Haml 6.x that need to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants