Sha256: 67bafb280eee02041fac1aa96c3923414680ff7809bd9ea8762f407e726865bd
Contents?: true
Size: 1.76 KB
Versions: 27
Compression:
Stored size: 1.76 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 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 pre(_inst, _args, _budget = nil, &_block) return unless framework ip = framework.client_ip return unless ip actions = actions_repo[Sqreen::Actions::BlockIp] + actions_repo[Sqreen::Actions::RedirectIp] 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
27 entries across 27 versions & 2 rubygems