class Arachni::Element::Link::DOM

Provides access to DOM operations for {Link links}.

@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

Attributes

fragment[R]

@return [String, nil]

URL fragment.

`http://test.com/stuff#/path/in/fragment?with-input=too` =>
`/path/in/fragment?with-input=too`
fragment_path[R]

@return [String, nil]

Path extracted from the {#fragment}.

`http://test.com/stuff#/path/in/fragment?with-input=too` =>
`/path/in/fragment`
fragment_query[R]

@return [String, nil]

Query extracted from the {#fragment}.

`http://test.com/stuff#/path/in/fragment?with-input=too` =>
`with-input=too`

Public Class Methods

data_from_node( node ) click to toggle source
# File lib/arachni/element/link/dom.rb, line 89
def self.data_from_node( node )
    fragment_path = fragment = nil

    href = node.attributes['href'].to_s
    return if !href.include? '#'

    fragment = href.split( '#', 2 ).last
    fragment_path, fragment_query = fragment.split( '?', 2 )

    inputs = uri_parse_query( "?#{fragment_query}" )
    return if inputs.empty?

    {
        inputs:         inputs,
        fragment:       fragment.freeze,
        fragment_path:  fragment_path.freeze,
        fragment_query: fragment_query.freeze,
    }
end
new(*) click to toggle source
Calls superclass method Arachni::Element::DOM::new
# File lib/arachni/element/link/dom.rb, line 54
def initialize(*)
    super

    prepare_data_from_node
    @method = :get
end
type() click to toggle source
# File lib/arachni/element/link/dom.rb, line 85
def self.type
    :link_dom
end

Public Instance Methods

hash() click to toggle source
# File lib/arachni/element/link/dom.rb, line 109
def hash
    to_s.hash
end
message_action() click to toggle source
# File lib/arachni/element/link/dom.rb, line 78
def message_action
    "#{@action}##{fragment}"
end
to_s() click to toggle source

@return [String]

URL including the DOM {#inputs}.
# File lib/arachni/element/link/dom.rb, line 72
def to_s
    "#{@action}##{fragment_path}?" << inputs.
        map { |k, v| "#{encode(k)}=#{encode(v)}" }.
        join( '&' )
end
trigger() click to toggle source

Loads the page with the {#inputs} in the {#fragment}.

# File lib/arachni/element/link/dom.rb, line 62
def trigger
    [ browser.goto( to_s, take_snapshot: false, update_transitions: false ) ]
end
type() click to toggle source
# File lib/arachni/element/link/dom.rb, line 82
def type
    self.class.type
end
valid_input_name?( name ) click to toggle source
# File lib/arachni/element/link/dom.rb, line 66
def valid_input_name?( name )
    @valid_input_names.include? name
end

Private Instance Methods

prepare_browser( browser, options ) click to toggle source
# File lib/arachni/element/link/dom.rb, line 127
def prepare_browser( browser, options )
    @browser = browser
    browser.javascript.custom_code = options[:custom_code]
    browser.javascript.taint       = options[:taint]
end
prepare_data_from_node() click to toggle source
# File lib/arachni/element/link/dom.rb, line 115
def prepare_data_from_node
    return if !(data = self.class.data_from_node( node ))

    @valid_input_names = data[:inputs].keys

    self.inputs     = data[:inputs]
    @default_inputs = self.inputs.dup.freeze
    @fragment       = data[:fragment]
    @fragment_path  = data[:fragment_path]
    @fragment_query = data[:fragment_query]
end