Sha256: c59ee01818712f6a8594a6ced6d278bfa6607e6b377a53a0791474e6be8b757b
Contents?: true
Size: 1.94 KB
Versions: 39
Compression:
Stored size: 1.94 KB
Contents
# typed: ignore # Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html require 'sqreen/rules/rule_cb' require 'sqreen/actions' require 'sqreen/middleware' require 'sqreen/rails_middleware' require 'sqreen/sinatra_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(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 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.current end end end end
Version data entries
39 entries across 39 versions & 1 rubygems