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 = params[:authenticity_token]) ⇒ ParamParser
constructor
A new instance of ParamParser.
Constructor Details
#initialize(ip, params, authenticity_token = params[:authenticity_token]) ⇒ ParamParser
Returns a new instance of ParamParser.
5 6 7 8 9 10 11 12 13 |
# File 'lib/bot-away/param_parser.rb', line 5 def initialize(ip, params, authenticity_token = params[:authenticity_token]) @ip, @params, @authenticity_token = ip, params, authenticity_token if authenticity_token if catch(:bastard) { deobfuscate! } == :took_the_bait params.clear 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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bot-away/param_parser.rb', line 15 def deobfuscate!(current = params, object_name = nil) if object_name spinner = BotAway::Spinner.new(ip, object_name, authenticity_token) end current.each do |key, value| if object_name && !value.kind_of?(Hash) && !ActionController::Request.unfiltered_params.include?(key) if value.blank? && params.keys.include?(spun_key = spinner.encode("#{object_name}[#{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 if value.kind_of?(Hash) deobfuscate!(value, object_name ? "#{object_name}[#{key}]" : key) end end end |