1

我使用机架攻击来阻止 IP。

# Block requests from 1.2.3.4
Rack::Attack.blocklist('block 1.2.3.4') do |req|
# Requests are blocked if the return value is truthy
'1.2.3.4' == req.ip
end

IP 被成功阻止。此人可以查看左上角带有“禁止”字样的白页。有什么办法可以改变字符串 "forbidden" 吗?

编辑 :

试过用这个。我所有的其他错误页面也都是类似的配置。 https://mattbrictson.com/dynamic-rails-error-pages 但它在机架攻击 403 禁止页面上不起作用。

4

2 回答 2

4

要自定义列入黑名单和限制请求的响应,请使用符合 Rack 应用界面的对象。

Rack::Attack.blocklisted_response = lambda do |env|
  # Using 503 because it may make the attacker think that he had successfully
  # DOSed the site. Rack::Attack returns 403 for blocklists by default
  [ 503, {}, ['Your custom string here']]
end

查看相关文档

于 2016-09-05T04:34:30.413 回答
1

覆盖blocklisted_response

@Tony Vincent 是正确的。我想我会再详细说明一下。

您只需要覆盖blocklisted_response.

您可以在此处查看默认值:

@blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] }

因此,在您的rack_attack.rb初始化程序中,您可以执行以下操作:

Rack::Attack.blocklisted_response = lambda{ |_env| [ 403, { "Content-Type" => "text/plain" }, [ "You have been blocked from the system. If you think this has been done in error, please contact Support at support@system.com. Thank you." ] ] }
于 2018-07-24T22:28:54.173 回答