class Arachni::Element::JSON
Represents an auditable JSON
element
@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>
Private Class Methods
decode( v )
click to toggle source
No-op
# File lib/arachni/element/json.rb, line 94 def decode( v ) v end
encode( v )
click to toggle source
No-op
# File lib/arachni/element/json.rb, line 89 def encode( v ) v end
from_request( url, request )
click to toggle source
Extracts JSON
elements from an HTTP
request.
@param [Arachni::HTTP::Request] request
@return [JSON, nil]
# File lib/arachni/element/json.rb, line 103 def from_request( url, request ) return if !request.body.is_a?( String ) || request.body.empty? return if too_big?( request.body ) data = begin ::JSON.load( request.body ) rescue ::JSON::ParserError end return if !data.is_a?( Hash ) || data.empty? new( url: url, action: request.url, method: request.method, inputs: data, source: request.body ) end
new( options )
click to toggle source
@param [Hash] options @option options [String] :url
URL of the page which includes the link.
@option options [String] :action
Link URL -- defaults to `:url`.
@option options [Hash] :inputs
Query parameters as `name => value` pairs. If none have been provided they will automatically be extracted from {#action}.
Calls superclass method
Arachni::Element::Capabilities::WithSource::new
# File lib/arachni/element/json.rb, line 43 def initialize( options ) self.http_method = options[:method] || :post super( options ) self.inputs = (self.inputs || {}).merge( options[:inputs] || {} ) if @source && self.inputs.empty? self.inputs = ::JSON.load( self.source ) end @default_inputs = self.inputs.dup.freeze end
Private Instance Methods
decode( *args )
click to toggle source
@see .decode
# File lib/arachni/element/json.rb, line 78 def decode( *args ) self.class.decode( *args ) end
dup()
click to toggle source
Calls superclass method
Arachni::Element::Capabilities::WithSource#dup
# File lib/arachni/element/json.rb, line 82 def dup super.tap { |e| e.inputs = @inputs.rpc_clone } end
encode( *args )
click to toggle source
@see .encode
# File lib/arachni/element/json.rb, line 73 def encode( *args ) self.class.encode( *args ) end
http_request( opts, &block )
click to toggle source
# File lib/arachni/element/json.rb, line 127 def http_request( opts, &block ) opts = opts.dup opts.delete :parameters opts.merge!( headers: { 'Content-Type' => 'application/json' } ) opts[:body] = self.to_json opts[:method] = self.http_method http.request( self.action, opts, &block ) end
simple()
click to toggle source
@return [Hash]
Simple representation of self in the form of `{ {#action} => {#inputs} }`.
# File lib/arachni/element/json.rb, line 68 def simple { self.action => self.inputs } end
to_h()
click to toggle source
Calls superclass method
Arachni::Element::Capabilities::WithSource#to_h
# File lib/arachni/element/json.rb, line 62 def to_h super.merge( source: @source ) end
to_json()
click to toggle source
JSON
formatted {#inputs}.
# File lib/arachni/element/json.rb, line 58 def to_json @inputs.to_json end