Object
# File lib/rack/protection/base.rb, line 20 def self.default_options(options) define_method(:default_options) { super().merge(options) } end
# File lib/rack/protection/base.rb, line 40 def accepts?(env) raise NotImplementedError, "#{self.class} implementation pending" end
# File lib/rack/protection/base.rb, line 44 def call(env) unless accepts? env warn env, "attack prevented by #{self.class}" result = react env end result or app.call(env) end
# File lib/rack/protection/base.rb, line 28 def default_options DEFAULT_OPTIONS end
# File lib/rack/protection/base.rb, line 63 def deny(env) [options[:status], {'Content-Type' => 'text/plain'}, [options[:message]]] end
# File lib/rack/protection/base.rb, line 80 def drop_session(env) session(env).clear if session? env end
# File lib/rack/protection/base.rb, line 100 def encrypt(value) options[:encryptor].hexdigest value.to_s end
# File lib/rack/protection/base.rb, line 106 def html?(headers) return false unless header = headers.detect { |k,v| k.downcase == 'content-type' } options[:html_types].include? header.last[/^\w+\/\w+/] end
# File lib/rack/protection/base.rb, line 90 def origin(env) env['HTTP_ORIGIN'] || env['HTTP_X_ORIGIN'] end
# File lib/rack/protection/base.rb, line 94 def random_string(secure = defined? SecureRandom) secure ? SecureRandom.hex(32) : "%032x" % rand(2**128-1) rescue NotImplementedError random_string false end
# File lib/rack/protection/base.rb, line 52 def react(env) result = send(options[:reaction], env) result if Array === result and result.size == 3 end
# File lib/rack/protection/base.rb, line 84 def referrer(env) ref = env['HTTP_REFERER'].to_s return if !options[:allow_empty_referrer] and ref.empty? URI.parse(ref).host || Request.new(env).host end
# File lib/rack/protection/base.rb, line 67 def report(env) env[options[:report_key]] = true end
# File lib/rack/protection/base.rb, line 36 def safe?(env) ]GET HEAD OPTIONS TRACE].include? env['REQUEST_METHOD'] end
# File lib/rack/protection/base.rb, line 75 def session(env) return env[options[:session_key]] if session? env fail "you need to set up a session middleware *before* #{self.class}" end
Generated with the Darkfish Rdoc Generator 2.