Class: TaintedLove::Reporter::StdoutReporter
- Defined in:
- lib/tainted_love/reporter/stdout_reporter.rb
Overview
Reporter that outputs warnings in the console
Instance Attribute Summary collapse
-
#app_path ⇒ Object
Returns the value of attribute app_path.
-
#stack_trace_size ⇒ Object
Returns the value of attribute stack_trace_size.
Attributes inherited from Base
Instance Method Summary collapse
- #add_warning(warning) ⇒ Object
- #format_line(line) ⇒ Object
- #format_warning(warning) ⇒ Object
-
#initialize ⇒ StdoutReporter
constructor
A new instance of StdoutReporter.
Methods inherited from Base
Constructor Details
#initialize ⇒ StdoutReporter
Returns a new instance of StdoutReporter.
9 10 11 12 13 14 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 9 def initialize super @stack_trace_size = 5 @app_path = Dir.pwd end |
Instance Attribute Details
#app_path ⇒ Object
Returns the value of attribute app_path.
7 8 9 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 7 def app_path @app_path end |
#stack_trace_size ⇒ Object
Returns the value of attribute stack_trace_size.
7 8 9 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 7 def stack_trace_size @stack_trace_size end |
Instance Method Details
#add_warning(warning) ⇒ Object
16 17 18 19 20 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 16 def add_warning(warning) puts format_warning(warning) puts end |
#format_line(line) ⇒ Object
46 47 48 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 46 def format_line(line) line[:file].sub(Dir.pwd, '.') + ':' + line[:line_number].to_s + ' in ' + line[:method] end |
#format_warning(warning) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tainted_love/reporter/stdout_reporter.rb', line 22 def format_warning(warning) puts '[!] TaintedLove' puts "#{warning.stack_trace.trace_hash[0...8]} #{warning.} [#{warning..join(', ')}]" tainted_input = if warning.tainted_input.size < 100 warning.tainted_input.inspect else warning.tainted_input.inspect[0..100] + '...' end puts 'Tainted input: ' + tainted_input puts 'Taint tags: ' + warning.tainted_input..uniq.inspect warning.stack_trace.lines.take(@stack_trace_size).each do |line| puts format_line(line) next unless line[:file].start_with?(@app_path) File.read(line[:file]).lines.each_with_index.drop([0, line[:line_number] - 2].max).take(3).each do |(code, n)| puts "| #{n + 1}\t#{code}" end end end |