Module: SastBox::SeverityCalculator

Included in:
Scanner
Defined in:
lib/sastbox-sdk/severity_calculator.rb

Instance Method Summary collapse

Instance Method Details

#add_severity(issue) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sastbox-sdk/severity_calculator.rb', line 4

def add_severity(issue)
  accepted_levels =  [:info, :low, :medium, :high, :critical]

  if issue.key?(:severity)
    issue[:severity] = issue[:severity].to_s.downcase.to_sym

    unless accepted_levels.include?(issue[:severity])
      issue[:severity] = attempt_to_determine_severity(issue)
    end
  else
    issue[:severity] = attempt_to_determine_severity(issue)
  end

end

#attempt_to_determine_severity(issue) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sastbox-sdk/severity_calculator.rb', line 26

def attempt_to_determine_severity(issue)
  text = "#{issue[:title]} #{issue[:description]}".downcase.gsub(/[^a-z ]/, ' ')

  level = :undefined

  critical = ['command exec', 'cmd exec', 'command inj', 'cmd inj', 'code inj', 'code exec',
    'file inclusion', 'dangerous send', 'insecure deserialization']

  high = ['xss', 'cross site scripting', 'sqli', 'sql injection', 'insecure url',
    'file manipulation', 'file access', 'file disclosure', 'idor', 'xpath inj',
    'weak cipher', 'weak crypto', 'insecure cipher', 'insecure crypto', 'insecure encryption',
    'broken cipher', 'broken crypto', 'weak hash', 'insecure hash', 'broken hash',
    'pathtraversal', 'path traversal', 'xxe', 'xml external entities']

  medium = ['mass assignment', 'secret keyword',
    'hard coded pass', 'hardcoded pass', 'pass hardcoded', 'password hardcoded',
    'password hard coded', 'secret hardcoded',
    'session fixation', 'security misconfiguration', 'vulnerable component',
    'header injection', 'csrf', 'cross site request forgery',
    'toctou', 'session setting', 'response splitting'
  ]

  low = ['open redirect', 'resource leak', 'format validation',
  'information disclosure', 'logging', 'logger', 'stacktrace', 'stack trace',
  'null pointer deref']

  info = []


  if level == :undefined
    level = :critical if severity_pattern_found?(critical, text)
  end

  if level == :undefined
    level = :high if severity_pattern_found?(high, text)
  end

  if level == :undefined
    level = :medium if severity_pattern_found?(medium, text)
  end

  if level == :undefined
    level = :low if severity_pattern_found?(low, text)
  end

  if level == :undefined
    level = :info if severity_pattern_found?(info, text)
  end

  level
end

#severity_pattern_found?(patterns, text) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/sastbox-sdk/severity_calculator.rb', line 19

def severity_pattern_found?(patterns, text)
  patterns.each do |pattern|
    return true if text.include?(pattern)
  end
  false
end