Class: Sqreen::Rules::RegexpRuleCB

Inherits:
RuleCB show all
Defined in:
lib/sqreen/rules/regexp_rule_cb.rb

Overview

Generic regexp based matching

Direct Known Subclasses

ShellEnvCB, URLMatchesCB, UserAgentMatchesCB, XSSCB

Constant Summary

Constants inherited from RuleCB

Sqreen::Rules::RuleCB::DEFAULT_PAYLOAD

Constants included from CallCountable

CallCountable::COUNT_CALLS, CallCountable::FAILING, CallCountable::POST, CallCountable::PRE

Constants inherited from CB

CB::DEFAULT_PRIORITY

Instance Attribute Summary

Attributes inherited from RuleCB

#block, #payload_tpl, #test

Attributes included from CallCountable

#call_count_interval, #call_counts

Attributes inherited from FrameworkCB

#framework

Attributes inherited from CB

#klass, #method, #overtimeable

Instance Method Summary collapse

Methods inherited from RuleCB

#advise_action, #overtime!, #priority, #record_event, #record_exception, #rule_name, #rulespack_id

Methods included from CallCountable

#count_callback_calls, #failing_with_count, #post_with_count, #pre_with_count

Methods included from Conditionable

#condition_callbacks, #failing_with_conditions, #post_with_conditions, #pre_with_conditions

Methods inherited from FrameworkCB

#record_observation, #whitelisted?

Methods inherited from CB

#failing?, #framework, #overtime!, #post?, #pre?, #priority, #to_s, #whitelisted?

Constructor Details

#initialize(*args) ⇒ RegexpRuleCB

Returns a new instance of RegexpRuleCB.



12
13
14
15
# File 'lib/sqreen/rules/regexp_rule_cb.rb', line 12

def initialize(*args)
  super(*args)
  prepare
end

Instance Method Details

#match_regexp(str) ⇒ Object



31
32
33
34
35
36
# File 'lib/sqreen/rules/regexp_rule_cb.rb', line 31

def match_regexp(str)
  @patterns.each do |pattern|
    return pattern if pattern.match?(str)
  end
  nil
end

#prepareObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sqreen/rules/regexp_rule_cb.rb', line 17

def prepare
  @patterns = []
  raw_patterns = @data['values']
  if raw_patterns.nil?
    msg = "no key 'values' in data (had #{@data.keys})"
    raise Sqreen::Exception, msg
  end

  @patterns = raw_patterns.map do |pattern|
    Regexp.compile(pattern, Regexp::IGNORECASE)
  end
end