Skip to content

Commit

Permalink
Support loading slim/smart
Browse files Browse the repository at this point in the history
in a very specific case.

Fixes #1570
  • Loading branch information
presidentbeef committed Apr 14, 2021
1 parent aef6253 commit cf3d9ac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/brakeman/parsers/template_parser.rb
Expand Up @@ -9,6 +9,7 @@ class TemplateParser
def initialize tracker, file_parser
@tracker = tracker
@file_parser = file_parser
@slim_smart = nil # Load slim/smart ?
end

def parse_template path, text
Expand Down Expand Up @@ -88,13 +89,36 @@ def parse_haml path, text

def parse_slim path, text
Brakeman.load_brakeman_dependency 'slim'

if @slim_smart.nil? and load_slim_smart?
@slim_smart = true
Brakeman.load_brakeman_dependency 'slim/smart'
else
@slim_smart = false
end

require_relative 'slim_embedded'

Slim::Template.new(path,
:disable_capture => true,
:generator => Temple::Generators::RailsOutputBuffer) { text }.precompiled_template
end

def load_slim_smart?
return !@slim_smart unless @slim_smart.nil?

# Terrible hack to find
# gem "slim", "~> 3.0.1", require: ["slim", "slim/smart"]
if tracker.app_tree.exists? 'Gemfile'
gemfile_contents = tracker.app_tree.file_path('Gemfile').read
if gemfile_contents.include? 'slim/smart'
return true
end
end

false
end

def self.parse_inline_erb tracker, text
fp = Brakeman::FileParser.new(tracker.app_tree, tracker.options[:parser_timeout])
tp = self.new(tracker, fp)
Expand Down
2 changes: 2 additions & 0 deletions test/apps/rails5.2/Gemfile
Expand Up @@ -60,3 +60,5 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem "slim", "~> 3.0.1", require: ["slim", "slim/smart"]
11 changes: 11 additions & 0 deletions test/apps/rails5.2/app/views/users/smart.html.slim
@@ -0,0 +1,11 @@
p
Your credit card
strong will not
> be charged now.

This is a text
which spans
several lines.

footer
Copyright © #{params[:x]} not xss?

0 comments on commit cf3d9ac

Please sign in to comment.