Class: Sqreen::Rules::BlacklistIPsCB

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

Overview

Looks for a blacklisted ip and block

Constant Summary

Constants inherited from RuleCB

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(klass, method, rule_hash) ⇒ BlacklistIPsCB

Returns a new instance of BlacklistIPsCB.



15
16
17
18
19
20
# File 'lib/sqreen/rules/blacklist_ips_cb.rb', line 15

def initialize(klass, method, rule_hash)
  super(klass, method, rule_hash)
  @trie_v4 = Sqreen::Trie.new
  @trie_v6 = Sqreen::Trie.new(nil, nil, Socket::AF_INET6)
  insert_values(@data['values'])
end

Instance Method Details

#pre(_inst, _args, _budget = nil, &_block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/sqreen/rules/blacklist_ips_cb.rb', line 22

def pre(_inst, _args, _budget = nil, &_block)
  return unless framework
  ip = framework.client_ip
  return unless ip
  found = find_blacklisted_ip(ip)
  return unless found
  Sqreen.log.debug { "Found blacklisted IP #{ip} - found: #{found}" }
  record_observation('blacklisted', found, 1)
  advise_action(:raise, :skip_rem_cbs => true)
end