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

Support loading slim/smart #1582

Merged
merged 1 commit into from Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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?