Class: BotAway::ParamParser
- Inherits:
-
Object
- Object
- BotAway::ParamParser
- Defined in:
- lib/bot-away/param_parser.rb
Instance Attribute Summary collapse
-
#authenticity_token ⇒ Object
readonly
Returns the value of attribute authenticity_token.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #deobfuscate!(current = params, object_name = nil) ⇒ Object
-
#initialize(ip, params, authenticity_token = nil) ⇒ ParamParser
constructor
A new instance of ParamParser.
Constructor Details
#initialize(ip, params, authenticity_token = nil) ⇒ ParamParser
Returns a new instance of ParamParser.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bot-away/param_parser.rb', line 5 def initialize(ip, params, authenticity_token = nil) params = params.with_indifferent_access if !params.kind_of?(HashWithIndifferentAccess) authenticity_token ||= params[:authenticity_token] @ip, @params, @authenticity_token = ip, params, authenticity_token if BotAway.dump_params Rails.logger.debug("[BotAway] IP: #{@ip}") Rails.logger.debug("[BotAway] Authenticity token: #{@authenticity_token}") Rails.logger.debug("[BotAway] Parameters: #{params.inspect}") end if authenticity_token if catch(:bastard) { deobfuscate! } == :took_the_bait # don't clear the controller or action keys, as Rails 3 needs them params.keys.each { |key| params.delete(key) unless %w(controller action).include?(key) } params[:suspected_bot] = true end end end |
Instance Attribute Details
#authenticity_token ⇒ Object (readonly)
Returns the value of attribute authenticity_token.
3 4 5 |
# File 'lib/bot-away/param_parser.rb', line 3 def authenticity_token @authenticity_token end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
3 4 5 |
# File 'lib/bot-away/param_parser.rb', line 3 def ip @ip end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/bot-away/param_parser.rb', line 3 def params @params end |
Instance Method Details
#deobfuscate!(current = params, object_name = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bot-away/param_parser.rb', line 25 def deobfuscate!(current = params, object_name = nil) return current if BotAway.excluded?(:controller => params[:controller], :action => params[:action]) if object_name spinner = BotAway::Spinner.new(ip, object_name, authenticity_token) end current.each do |key, value| if value.kind_of?(Hash) deobfuscate!(value, object_name ? "#{object_name}[#{key}]" : key) else if object_name && !BotAway.excluded?(:object_name => object_name, :method_name => key) spun_key = spinner.encode("#{object_name}[#{key}]") if value.blank? && params.keys.include?(spun_key) current[key] = params.delete(spun_key) else #puts "throwing on #{object_name}[#{key}] because its not blank" if !value.blank? #puts "throwing on #{object_name}[#{key}] because its not found" if defined?(spun_key) && !spun_key.nil? throw :bastard, :took_the_bait end end end end end |