Sha256: a84c4261c89f395a48702690b81f62a458b37fc3a751b9e46a1be03d7b7dfe08
Contents?: true
Size: 1.85 KB
Versions: 44
Compression:
Stored size: 1.85 KB
Contents
# Copyright (c) 2018 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.io/terms.html require 'sqreen/rule_callback' require 'sqreen/actions' require 'sqreen/middleware' module Sqreen module Rules # Runs actions concerned with whether the request ought to be served class RunReqStartActions < FrameworkCB PRIORITY = 95 def initialize(framework) if defined?(Sqreen::Frameworks::SinatraFramework) && framework.is_a?(Sqreen::Frameworks::SinatraFramework) super(Sinatra::ExtendedRack, :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 def whitelisted? whitelisted = SharedStorage.get(:whitelisted) return whitelisted unless whitelisted.nil? framework && !framework.whitelisted_match.nil? end def priority PRIORITY end 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 private # @param action [Sqreen::Actions::Base] def run_client_ip_action(action, client_ip) action.run client_ip end # @return [Sqreen::Actions::Repository] def actions_repo Sqreen::Actions::Repository.instance end end end end
Version data entries
44 entries across 44 versions & 1 rubygems