class Sqreen::Rules::CustomErrorCB
Display sqreen presence
Attributes
redirect_url[R]
status_code[R]
Public Class Methods
new(klass, method, rule_hash)
click to toggle source
Calls superclass method
# File lib/sqreen/rules/custom_error_cb.rb, line 14 def initialize(klass, method, rule_hash) @redirect_url = nil @status_code = nil super(klass, method, rule_hash) if @data.nil? || @data['values'].empty? raise Sqreen::Exception, 'No data' end configure_custom_error(@data['values'][0]) @overtimeable = false end
Public Instance Methods
configure_custom_error(custom_error)
click to toggle source
# File lib/sqreen/rules/custom_error_cb.rb, line 25 def configure_custom_error(custom_error) case custom_error['type'] when 'custom_error_page' then @status_code = custom_error['status_code'].to_i when 'redirection' then @redirect_url = custom_error['redirection_url'] @status_code = custom_error.fetch('status_code', 303).to_i else raise Sqreen::Exception, "No custom error #{custom_error['type']}" end end
failing(except, _inst, _args, _budget = nil, &_block)
click to toggle source
# File lib/sqreen/rules/custom_error_cb.rb, line 37 def failing(except, _inst, _args, _budget = nil, &_block) oexcept = nil if except.respond_to?(:original_exception) oexcept = except.original_exception end if !except.is_a?(Sqreen::AttackBlocked) && !oexcept.is_a?(Sqreen::AttackBlocked) return advise_action(nil) end if @redirect_url advise_action(:override, :new_return_value => respond_redirect) else advise_action(:override, :new_return_value => respond_page) end end
respond_page()
click to toggle source
# File lib/sqreen/rules/custom_error_cb.rb, line 57 def respond_page @page ||= File.open(File.join(File.dirname(__FILE__), '../attack_detected.html'), 'rb', &:read) headers = { 'Content-Type' => 'text/html', 'Content-Length' => @page.size.to_s, } [@status_code, headers, [@page]] end
respond_redirect()
click to toggle source
# File lib/sqreen/rules/custom_error_cb.rb, line 53 def respond_redirect [@status_code, { 'Location' => @redirect_url }, ['']] end