Class: WPScan::Formatter::Jsonl

Inherits:
Base
  • Object
show all
Defined in:
app/formatters/jsonl.rb

Overview

JSON Lines formatter — streams one self-contained JSON object per template render as the scan progresses. Reuses every app/views/json/*.erb template via base_format, so output content matches ‘-f json` but is emitted incrementally and can be piped directly into tools like `jq`.

Constant Summary

Constants inherited from Base

Base::ERB_SUPPORTS_KVARGS

Instance Attribute Summary

Attributes inherited from Base

#controller_name

Instance Method Summary collapse

Methods inherited from Base

#beautify, #format, #formats, #initialize, #render, #template_vars, #user_interaction?, #view_path, #views_directories

Constructor Details

This class inherits a constructor from WPScan::Formatter::Base

Instance Method Details

#base_formatObject



10
11
12
# File 'app/formatters/jsonl.rb', line 10

def base_format
  'json'
end

#output(tpl, vars = {}, controller_name = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/formatters/jsonl.rb', line 18

def output(tpl, vars = {}, controller_name = nil)
  rendered = render(tpl, vars, controller_name)
             .encode('UTF-8', invalid: :replace, undef: :replace)
  fragment = rendered.strip.chomp(',')
  return if fragment.empty?

  $stdout.puts JSON.generate(JSON.parse("{#{fragment}}"))
  $stdout.flush
end

#streams?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/formatters/jsonl.rb', line 14

def streams?
  true
end