mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
add multisupport for RACK_ATTACK_BYPASS
This commit is contained in:
@@ -2,9 +2,21 @@
|
||||
|
||||
class Rack::Attack
|
||||
if ENV["RACK_ATTACK_BYPASS"].present?
|
||||
begin
|
||||
TOKENS = JSON.parse(ENV["RACK_ATTACK_BYPASS"])
|
||||
unless TOKENS.is_a?(Array)
|
||||
Rails.logger.warn "RACK_ATTACK_BYPASS should be a array, tf is this #{TOKENS.class}"
|
||||
TOKENS = []
|
||||
end
|
||||
rescue JSON::ParserError => e
|
||||
Rails.logger.error "RACK_ATTACK_BYPASS failed to read, you fucked it up #{e.message}"
|
||||
TOKENS = []
|
||||
end
|
||||
|
||||
Rack::Attack.safelist("mark any authenticated access safe") do |request|
|
||||
# Requests are allowed if the return value is truthy
|
||||
request.env["HTTP_RACK_ATTACK_BYPASS"] == ENV["RACK_ATTACK_BYPASS"]
|
||||
bypass = request.env["HTTP_RACK_ATTACK_BYPASS"]
|
||||
bypass.present? && TOKENS.include?(bypass)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user