I have a Django application running on an Nginx + Gunicorn server where I use DRF throttling. Whenever I make API requests to my server and change the X-Forwarded-For header value in the client I'm then able to bypass the throttling for unauthenticated users and thereby have unlimited access to the API. This is of course not desired.
I think a way to deal with this is to have Nginx append the real IP to the end of the X-Forwarded-For request header before it reaches the server by using proxy params. It just doesn't seem to change the header when I inspect Postman / RapidApi client. I assume that's what causes the error but ultimately I don't know.
Nginx conf:
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
The proxy_params file from Nginx includes setting the X-Forwarded-For request header like so:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Can somebody tell me what I'm doing wrong and how to fix it so you can't make unlimited API requests? If you need more information or clarification please let me know.