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

Clean up XForwardedForMiddleware #36075

Open
5 tasks
timmc-edx opened this issue Jan 6, 2025 · 1 comment
Open
5 tasks

Clean up XForwardedForMiddleware #36075

timmc-edx opened this issue Jan 6, 2025 · 1 comment

Comments

@timmc-edx
Copy link
Contributor

timmc-edx commented Jan 6, 2025

XForwardedForMiddleware in edxapp contains several pieces of code relating to IP addresses.

The most recent part of the code (closest to the top, in that permalink) uses edx-django-utils to make various information about the client IP chain available to the application. This is currently working as desired, although it might not be the best place for it. However, the oldest part assumes there is only one true client IP, and then uses that to overwrite request.META['REMOTE_ADDR']. We'd like to delete this part, since it creates an incorrect and inconsistent view of the IP chain. This needs to be removed before the newer code can properly be extracted to a utility module somewhere—it overwrites information that the newer block needs to read. That order dependence is fragile.

In between, there's also some code that copies some values in request.META to new names, for a past Gunicorn upgrade. This will need to be carefully evaluated to determine whether it is still needed, and what to do with it. (Caution: The field and header variable names might be reversed here.) At the very least we'll want to expand the comments.

Acceptance criteria:

  • DEPRs filed and accepted as needed
  • Sweep for any remaining uses of REMOTE_ADDR or other code that thinks it has the "real client IP" and isn't already using the edx_django_utils.ip utils
  • No longer overwrite request.META['REMOTE_ADDR']
  • Move newer code (call to ip.init_client_ips, instrumentation) into a edx-django-utils middleware, and use that middleware instead
    • Also recommend to other teams that they use this
  • Do something with the request.META field copying/renaming (delete? document better?)

Notes:

@robrap
Copy link
Contributor

robrap commented Jan 7, 2025

We should consider adding observability (maybe even a utility) for monitoring if a getter is called to know whether anyone is calling request.META['REMOTE_ADDR']. If no one is, we can remove the override that is changing its value.

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

No branches or pull requests

2 participants