[deploy] Track Client IPs to Help Block Bad Actors (#7730)

This commit is contained in:
Molly Struve 2020-05-07 12:45:30 -05:00 committed by GitHub
parent 64f584fffd
commit f190f4c6c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -28,4 +28,10 @@ class Rack::Attack
request.env["HTTP_FASTLY_CLIENT_IP"].to_s
end
end
track("request_tracking") do |request|
if request.env["HTTP_FASTLY_CLIENT_IP"].present?
Honeycomb.add_field("fastly_client_ip", request.env["HTTP_FASTLY_CLIENT_IP"])
end
end
end

View file

@ -96,4 +96,13 @@ describe Rack::Attack, type: :request, throttle: true do
end
end
end
describe "request_tracking" do
it "adds fastly client IP to Honeycomb span" do
allow(Honeycomb).to receive(:add_field)
get api_articles_path, headers: { "HTTP_FASTLY_CLIENT_IP" => "5.6.7.8" }
expect(Honeycomb).to have_received(:add_field).with("fastly_client_ip", "5.6.7.8")
end
end
end