Class: Contrast::Agent::Reporting::Details::XssMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/reporting/details/xss_match.rb

Overview

Matcher data for XSS rule.

Constant Summary collapse

EVIDENCE_START =
/<script.*?>/i.cs__freeze
EVIDENCE_END =
%r{</script.*?>}i.cs__freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xss_string = '') ⇒ XssMatch

Returns a new instance of XssMatch.

Parameters:

  • xss_string (String) (defaults to: '')

    to check for matches.



23
24
25
26
27
28
29
30
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 23

def initialize xss_string = ''
  return if xss_string.empty?

  @evidence_start = xss_string.index(EVIDENCE_START)
  @offset = (xss_string[0...@evidence_start] || '').length
  @evidence = xss_string[@evidence_start...xss_string.index(EVIDENCE_END)].gsub(EVIDENCE_START, '').
      gsub(EVIDENCE_END, '')
end

Instance Attribute Details

#evidenceString

Returns:



18
19
20
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 18

def evidence
  @evidence
end

#evidence_startInteger

Returns in ms.

Returns:

  • (Integer)

    in ms



16
17
18
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 16

def evidence_start
  @evidence_start
end

#offsetInteger

Returns:

  • (Integer)


20
21
22
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 20

def offset
  @offset
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 40

def empty?
  evidence_start.nil? || evidence.nil? || offset.nil?
end

#to_controlled_hashObject



32
33
34
35
36
37
38
# File 'lib/contrast/agent/reporting/details/xss_match.rb', line 32

def to_controlled_hash
  {
      evidenceStart: evidence_start,
      evidence: evidence,
      offset: offset
  }
end