Method: CMSScanner::Target#in_scope_urls

Defined in:
lib/cms_scanner/target/scope.rb

#in_scope_urls(res, xpath = '//link|//script|//style|//img|//a', attributes = %w(href src))) {|String, Nokogiri::XML::Element| ... } ⇒ Array<String>

Returns The in scope absolute URLs detected in the response’s body.

Parameters:

  • res (Typhoeus::Response)
  • xpath (String) (defaults to: '//link|//script|//style|//img|//a')
  • attributes (Array<String>) (defaults to: %w(href src)))

Yields:

  • (String, Nokogiri::XML::Element)

    The in scope url and its associated tag

Returns:

  • (Array<String>)

    The in scope absolute URLs detected in the response’s body



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cms_scanner/target/scope.rb', line 25

def in_scope_urls(res, xpath = '//link|//script|//style|//img|//a', attributes = %w(href src))
  found = []

  res.html.xpath(xpath).each do |tag|
    attributes.each do |attribute|
      attr_value = tag[attribute]

      next unless attr_value && !attr_value.empty?

      url = uri.join(attr_value.strip).to_s

      next unless in_scope?(url)

      yield url, tag if block_given? && !found.include?(url)

      found << url
    end
  end

  found.uniq
end