Class: Sqreen::Rules::RunReqStartActions

Inherits:
FrameworkCB show all
Defined in:
lib/sqreen/rules/run_req_start_actions.rb

Overview

Runs actions concerned with whether the request ought to be served

Constant Summary collapse

PRIORITY =
95

Constants inherited from CB

CB::DEFAULT_PRIORITY

Instance Attribute Summary

Attributes inherited from FrameworkCB

#framework

Attributes inherited from CB

#klass, #method, #overtimeable

Instance Method Summary collapse

Methods inherited from FrameworkCB

#record_observation

Methods inherited from CB

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

Constructor Details

#initialize(framework) ⇒ RunReqStartActions

Returns a new instance of RunReqStartActions.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sqreen/rules/run_req_start_actions.rb', line 18

def initialize(framework)
  if defined?(Sqreen::Frameworks::SinatraFramework) &&
     framework.is_a?(Sqreen::Frameworks::SinatraFramework)
    super(Sqreen::SinatraMiddleware, :call)
  elsif defined?(Sqreen::Frameworks::RailsFramework) &&
        framework.is_a?(Sqreen::Frameworks::RailsFramework)
    super(Sqreen::RailsMiddleware, :call)
  else
    # last resort; we won't get nice errors
    super(Sqreen::Middleware, :call)
  end

  self.framework = framework
end

Instance Method Details

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sqreen/rules/run_req_start_actions.rb', line 43

def pre(_inst, _args, _budget = nil, &_block)
  return unless framework
  ip = framework.client_ip
  return unless ip

  actions = actions_repo.get(Sqreen::Actions::BlockIp, ip) +
            actions_repo.get(Sqreen::Actions::RedirectIp, ip)

  actions.each do |act|
    res = run_client_ip_action(act, ip)
    return res unless res.nil?
  end
  nil
end

#priorityObject



39
40
41
# File 'lib/sqreen/rules/run_req_start_actions.rb', line 39

def priority
  PRIORITY
end

#whitelisted?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/sqreen/rules/run_req_start_actions.rb', line 33

def whitelisted?
  whitelisted = SharedStorage.get(:whitelisted)
  return whitelisted unless whitelisted.nil?
  framework && !framework.whitelisted_match.nil?
end