Skip to content

Commit

Permalink
Merge pull request #20 from SonicGarden/fix-ipv6
Browse files Browse the repository at this point in the history
[review] fix: ip6アドレスの考慮漏れ
  • Loading branch information
aki77 authored Oct 29, 2023
2 parents ed2c8cf + 72d26f2 commit 9ed506f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sg_fargate_rails/remote_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module SgFargateRails
class RemoteIp < ActionDispatch::RemoteIp
def call(env)
req = ActionDispatch::Request.new env
req.remote_ip = req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'] ? req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'].split(':').first : ActionDispatch::RemoteIp::GetIp.new(req, check_ip, proxies)
# NOTE: HTTP_CLOUDFRONT_VIEWER_ADDRESSヘッダには127.0.0.1:3000といったIP4アドレスや2406:2d40:3090:af00:25c1:6071:b820:8e47:3000といったIP6アドレスが入っている
req.remote_ip = req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'] ? req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'].remove(/:\d+$/) : ActionDispatch::RemoteIp::GetIp.new(req, check_ip, proxies)
@app.call(req.env)
end
end
Expand Down

0 comments on commit 9ed506f

Please sign in to comment.