#37107: Request META key `REMOTE_ADDR` not set anywhere in wsgi applications
-------------------------------------+-------------------------------------
     Reporter:  Rami Boutassghount   |                     Type:
                                     |  Uncategorized
       Status:  new                  |                Component:  Core
                                     |  (Other)
      Version:  6.0                  |                 Severity:  Normal
     Keywords:  REMOTE_ADDR,         |             Triage Stage:
  WSGIRequest, HttpRequest, META     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 The docs suggest that the `REMOTE_ADDR? is the IP address of the client.
 See: https://docs.djangoproject.com/en/6.0/ref/request-
 response/#django.http.HttpRequest.META

 However I searched all over the django codebase and that key is not set
 anywhere in  `HttpRequest` or in its subclass `WSGIRequest`.

 The only place where that key is set is in asgi module:
 
https://github.com/django/django/blob/3e4e0db66961a48a080ff3ff91f6c0d954261366/django/core/handlers/asgi.py#L80

 I run a small experiment to see what is the value on my test environment
 and it is always empty, see:


 {{{
     def get_ip_address(self, request) -> str:
         meta = request.META
         remote_addr = meta.get("REMOTE_ADDR", "")
         x_forwarded_for = meta.get("HTTP_X_FORWARDED_FOR", "")
         x_real_ip = meta.get("HTTP_X_REAL_IP", "")
         Bot.to_admin(
             f"IP Address: \n"
             f"HTTP_X_FORWARDED_FOR: {x_forwarded_for}\n"
             f"REMOTE_ADDR: {remote_addr}\n"
             f"HTTP_X_REAL_IP: {x_real_ip}\n"
         )

 }}}


 Chat in Telegram:

 {{{
 [5/19/26 10:21 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 198.244.242.58
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 198.244.242.58
 [5/19/26 10:21 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 2a03:2880:f814:19::
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 2a03:2880:f814:19::
 [5/19/26 10:21 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 198.244.183.201
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 198.244.183.201
 [5/19/26 10:22 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 5.39.1.228
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 5.39.1.228
 [5/19/26 10:22 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 66.249.77.71
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 66.249.77.71
 [5/19/26 10:22 AM] Rami Bot: IP Address:
 HTTP_X_FORWARDED_FOR: 2606:65c0:20:43d:a16b:57fd:233b:4fe6
 REMOTE_ADDR:
 HTTP_X_REAL_IP: 2606:65c0:20:43d:a16b:57fd:233b:4fe6

 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37107>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019e3f634364-a18bb0a4-061b-4f2a-8f59-ecf247b8e05b-000000%40eu-central-1.amazonses.com.

Reply via email to