Class: Scryer::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/scryer/rule.rb

Overview

Base class for a single detection rule. Subclasses implement #scan and return an Array of Finding. Every rule gets the parsed sexp tree (so it doesn't have to re-parse), the raw source (for snippet extraction), and the relative file path (for reporting).

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, source:, sexp:) ⇒ Rule

Returns a new instance of Rule.



33
34
35
36
37
# File 'lib/scryer/rule.rb', line 33

def initialize(file:, source:, sexp:)
  @file = file
  @source = source
  @sexp = sexp
end

Class Attribute Details

.categoryObject

Returns the value of attribute category.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def category
  @category
end

.confidenceObject

"high"/"medium"/"low" — Scryer's own best-effort estimate of how often this specific rule's pattern-match actually reflects a real issue, independent of severity (how bad it is if real). A rule can be both high-severity and low-confidence at once (idor is the clearest example: a real IDOR is serious, but this rule's heuristic — no visible authorization call anywhere in the controller class — is the least precise in the gem). Defaults to "medium" so every rule doesn't have to set it explicitly; only rules with a clearly different precision (idor's documented false-positive risk, or a narrow literal-match rule with very little room for ambiguity) set this themselves. Not derived from anything measured at runtime — this is a static per-rule estimate, same as default_severity.



22
23
24
# File 'lib/scryer/rule.rb', line 22

def confidence
  @confidence || "medium"
end

.cweObject

Returns the value of attribute cwe.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def cwe
  @cwe
end

.default_severityObject

Returns the value of attribute default_severity.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def default_severity
  @default_severity
end

.owasp_categoryObject

Returns the value of attribute owasp_category.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def owasp_category
  @owasp_category
end

.rule_idObject

Returns the value of attribute rule_id.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def rule_id
  @rule_id
end

.titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def title
  @title
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



39
40
41
# File 'lib/scryer/rule.rb', line 39

def file
  @file
end

#sexpObject (readonly)

Returns the value of attribute sexp.



39
40
41
# File 'lib/scryer/rule.rb', line 39

def sexp
  @sexp
end

#sourceObject (readonly)

Returns the value of attribute source.



39
40
41
# File 'lib/scryer/rule.rb', line 39

def source
  @source
end

Class Method Details

.inherited(subclass) ⇒ Object



27
28
29
30
# File 'lib/scryer/rule.rb', line 27

def inherited(subclass)
  super
  Scryer::RuleSet.register(subclass)
end

Instance Method Details

#scanObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/scryer/rule.rb', line 41

def scan
  raise NotImplementedError, "#{self.class} must implement #scan"
end