Added fix for Analytics SQLi
This commit is contained in:
@@ -7,11 +7,11 @@ class AdminController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def analytics
|
def analytics
|
||||||
|
|
||||||
if params[:field].nil?
|
if params[:field].nil?
|
||||||
fields = "*"
|
fields = "*"
|
||||||
else
|
else
|
||||||
fields = params[:field].map {|k,v| k}.join(",")
|
#fields = params[:field].map {|k,v| k }.join(",")
|
||||||
|
fields = params[:field].map {|k,v| Analytics.parse_field(k) }.join(",")
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:ip]
|
if params[:ip]
|
||||||
|
|||||||
+11
-1
@@ -1,9 +1,19 @@
|
|||||||
class Analytics < ActiveRecord::Base
|
class Analytics < ActiveRecord::Base
|
||||||
attr_accessible :ip_address, :referrer, :user_agent
|
attr_accessible :ip_address, :referrer, :user_agent
|
||||||
|
|
||||||
scope :hits_by_ip, ->(ip,col="*") { select("#{col}").where("ip_address = '#{ip}'")}
|
scope :hits_by_ip, ->(ip,col="*") { select("#{col}").where(:ip_address => ip).order("id DESC")}
|
||||||
|
|
||||||
def self.count_by_col(col)
|
def self.count_by_col(col)
|
||||||
calculate(:count, col)
|
calculate(:count, col)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.parse_field(field)
|
||||||
|
valid_fields = ["ip_address", "referrer", "user_agent"]
|
||||||
|
|
||||||
|
if valid_fields.include?(field)
|
||||||
|
field
|
||||||
|
else
|
||||||
|
"1"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user