Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rack_strip_client_ip middleware #2954

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

theseanything
Copy link
Contributor

This removes middleware that strips the Client-IP header from requests to prevent Rails from raising a "IpSpoofAttackError" exception. Removing this because it isn't needed, we are stripping the Client-IP header at the CDN level which should prevent this expection being raised anyway. If this header is being set else were in the request path, we should fix that instead of blindly stripping the header altogether.

There is also a bug in the middleware, where it prevents previous middleware from receiving information from following middleware in the 'env' variable. This is because it creates a copy of env, which isn't returned to the calling middleware. This prevents middleware such as the prometheus exporter from generating correct metrics stats.

https://github.com/alext/rack_strip_client_ip


Details of the bug:

Instead of editing the same env object it creates a copy using the "reject" method. This new copy is passed on to subsequent middleware, which means any changes to 'env' isn't available to previous middleware.

https://github.com/alext/rack_strip_client_ip/blob/98029a661616b5a1091e6b822aed5b498a4e5d42/lib/rack_strip_client_ip/middleware.rb#LL14

Follow these steps if you are doing a Rails upgrade.

This removes middleware that strips the Client-IP header from requests
to prevent Rails from raising a "IpSpoofAttackError" exception. Removing
this because it isn't needed, we are stripping the Client-IP header at
the CDN level which should prevent this expection being raised anyway.
If this header is being set else were in the request path, we should fix
that instead of blindly stripping the header altogether.

There is also a bug in the middleware, where it prevents previous
middleware from receiving information from following middleware in the
'env' variable. This is because it creates a copy of env, which isn't
returned to the calling middleware. This prevents middleware such as the
prometheus exporter from generating correct metrics stats.

https://github.com/alext/rack_strip_client_ip

---

Details of the bug:

Instead of editing the same env object it creates a copy using the
"reject" method. This new copy is passed on to subsequent middleware,
which means any changes to 'env' isn't available to previous middleware.

https://github.com/alext/rack_strip_client_ip/blob/98029a661616b5a1091e6b822aed5b498a4e5d42/lib/rack_strip_client_ip/middleware.rb#LL14
@theseanything theseanything merged commit fba9d0f into main Dec 13, 2022
@theseanything theseanything deleted the remove-rack-remove-client-ip-middleware branch December 13, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants