Module: WpItem::Vulnerable

Included in:
WpItem
Defined in:
lib/common/models/wp_item/vulnerable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier


5
6
7
# File 'lib/common/models/wp_item/vulnerable.rb', line 5

def identifier
  @identifier
end

#vulns_fileObject

Returns the value of attribute vulns_file


5
6
7
# File 'lib/common/models/wp_item/vulnerable.rb', line 5

def vulns_file
  @vulns_file
end

Instance Method Details

#vulnerabilitiesVulnerabilities

Get the vulnerabilities associated to the WpItem Filters out already fixed vulnerabilities


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/common/models/wp_item/vulnerable.rb', line 11

def vulnerabilities
  json            = json(vulns_file)
  vulnerabilities = Vulnerabilities.new

  json.each do |item|
    asset = item[identifier]

    if asset
      asset['vulnerabilities'].each do |vulnerability|
        vulnerability = Vulnerability.load_from_json_item(vulnerability)
        vulnerabilities << vulnerability if vulnerable_to?(vulnerability)
      end
    end
  end

  vulnerabilities
end

#vulnerable?Boolean


29
30
31
# File 'lib/common/models/wp_item/vulnerable.rb', line 29

def vulnerable?
  vulnerabilities.empty? ? false : true
end

#vulnerable_to?(vuln) ⇒ Boolean

Checks if a item is vulnerable to a specific vulnerability


38
39
40
41
42
43
44
45
46
47
# File 'lib/common/models/wp_item/vulnerable.rb', line 38

def vulnerable_to?(vuln)
  if version && vuln && vuln.fixed_in && !vuln.fixed_in.empty?
    unless VersionCompare::lesser_or_equal?(vuln.fixed_in, version)
      return true
    end
  else
    return true
  end
  return false
end