Class: Arachni::Browser::Javascript::Proxy

Inherits:
BasicObject
Defined in:
lib/arachni/browser/javascript/proxy.rb,
lib/arachni/browser/javascript/proxy/stub.rb

Overview

Note:

Extends ‘BasicObject` because we don’t want any baggage to avoid method-name clashes with the Javascript-side objects.

Provides a proxy to a Javascript object.

Author:

Direct Known Subclasses

DOMMonitor, TaintTracer

Defined Under Namespace

Classes: Stub

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(javascript, object) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:



33
34
35
36
37
38
# File 'lib/arachni/browser/javascript/proxy.rb', line 33

def initialize( javascript, object )
    @javascript = javascript
    @object     = object
    @stub       = Stub.new( self )
    @isFunction = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Parameters:

  • function (Symbol)

    Javascript property/function.

  • arguments (Array)


75
76
77
# File 'lib/arachni/browser/javascript/proxy.rb', line 75

def call( function, *arguments )
    @javascript.run "return #{stub.write( function, *arguments )}"
end

Instance Attribute Details

#javascriptJavascript (readonly)

Returns Active Arachni::Browser::Javascript interface.

Returns:



27
28
29
# File 'lib/arachni/browser/javascript/proxy.rb', line 27

def javascript
  @javascript
end

#stubStub (readonly)

Returns Stub interface for JS code.

Returns:

  • (Stub)

    Stub interface for JS code.



23
24
25
# File 'lib/arachni/browser/javascript/proxy.rb', line 23

def stub
  @stub
end

Instance Method Details

#call(function, *arguments) ⇒ Object Also known as: method_missing

Parameters:

  • function (Symbol)

    Javascript property/function.

  • arguments (Array)


72
73
74
# File 'lib/arachni/browser/javascript/proxy.rb', line 72

def call( function, *arguments )
    @javascript.run "return #{stub.write( function, *arguments )}"
end

#classObject



86
87
88
# File 'lib/arachni/browser/javascript/proxy.rb', line 86

def class
    Proxy
end

#function?(name) ⇒ Bool

Returns ‘true` if the `name` property of the current object points to a function, `false` otherwise.

Parameters:

  • name (#to_sym)

    Function name to check.

Returns:

  • (Bool)

    ‘true` if the `name` property of the current object points to a function, `false` otherwise.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/arachni/browser/javascript/proxy.rb', line 46

def function?( name )
    return @isFunction[name.to_sym] if @isFunction.include?( name.to_sym )

    if name.to_s.end_with? '='
        name = name.to_s
        return @isFunction[name.to_sym] = @javascript.run(
            "return ('#{name[0...-1]}' in #{js_object})"
        )
    end

    @isFunction[name.to_sym] =
        @javascript.run(
            "return Object.prototype.toString.call( #{js_object}." <<
                "#{name} ) == '[object Function]'"
        )
end

#js_objectString

Returns Active JS-side object name – prefixed with the relevant ‘_token`.

Returns:

  • (String)

    Active JS-side object name – prefixed with the relevant ‘_token`.



65
66
67
# File 'lib/arachni/browser/javascript/proxy.rb', line 65

def js_object
    "_#{@javascript.token}#{@object}"
end

#respond_to?(property) ⇒ Bool

Returns ‘true` if `self` of the JS object responds to `property`, `false` otherwise.

Parameters:

  • property (Symbol)

Returns:

  • (Bool)

    ‘true` if `self` of the JS object responds to `property`, `false` otherwise.



82
83
84
# File 'lib/arachni/browser/javascript/proxy.rb', line 82

def respond_to?( property )
    stub.respond_to?( property )
end