When upgrading from rack-attack 6.3.1 to 6.5.0 request object is unable to fetch any custom methods
When I run request.comment it throws the below error
undefined method `comment' for #Hash:0x00007fd2b4f41530
As per the documentation, I updated the method from throttled_callback to throttled_response
Rack::Attack.throttled_response = lambda do |request|
details = {restriction: {name: 'asdas', comment: request.comment}}
if Feature.enabled?(:some_feature)
restrict_user(request.token, details) if request.update_password?
end
end
I have added a lot of method but now after upgradating unable to access any of the method inside the throttled_callback
class Rack::Attack
class Request < ::Rack::Request
##
## Helper Functions
##
# Get the real IP Address of the user/client
attr_accessor :comment
def remote_ip
@remote_ip ||= get_header('HTTP_X_FORWARDED_FOR').try(:to_s)
end
def body_params
unless @body_params
@body_params = JSON.parse(body.read)
body.rewind
end
@body_params
end
def username
(body_params["username"]).to_s.downcase
end
def login?
self.path == '/user_sign_in'
end
end
throttle("ip:user-key-min", limit: 10, period: 1.minute) do |req|
if req.login?
req.comment = "some comment"
req.remote_ip
end
end
When I am inside the throttled_response. So, the request object is not able to access the comment or any method inside the class Request < ::Rack::Request after upgrading to the latest version of rack-attack. In version 6.3.1 in the request object I was able to access the method from the class Request < ::Rack::Request inside the throttled_callback
request.methods
[ :comment, :username, , :comment=, :body_params, :remote_ip, :login?]