Running Librechat bebind GCP Loadbalancer - Not able to disable IP based login ratelimit #3916
-
What happened?We are running Librechat behind Google LB. Our users logins can be easily blocked if there are many users try to login at the same time because the request comes from same IP. They get The only IP related env we can find is LIMIT_MESSAGE_IP=, but it doesn't help login attempts ratelimit based on IP. Is there a way to workaround this or hidden configuration)s) can tune to disable IP based login ratelimits? Steps to ReproduceConfiguration:
Have a few users to login/logout at the same time. They would bump into Basically the requests are coming from the same LB IP and shared the same limits. I would think the behavior would be the same for any reverse proxy, include nginx, no? short of disable IP based login attempts limits, or use real client IP for ratelimit, would set LOGIN_MAX to a very large number help? Any help is much appreciated! Xueshan What browsers are you seeing the problem on?No response Relevant log outputNo response ScreenshotsNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
If the LibreChat API is sitting behind a reverse-proxy/load-balancer, we can still receive the origin IP if it's properly forwarded. app.set('trust proxy', 1); You can also experiment with this for testing: app.set('trust proxy', true); This should in theory help express.js identify the req.ip, though we can investigate further in Express and load balancer context: Worth checking:
simple log statements within the login limiter handler, in console.log('req.ip:', req.ip);
console.log('X-Forwarded-For:', req.headers['x-forwarded-for']);
console.log('X-Real-IP:', req.headers['x-real-ip']); If all else fails, and if disabling the I have my own instance running behind Traefik, and I can confirm from the Login info logs that my IP is recognized as expected (also tested for difference with vpn) # ips redacted
{"level":"info","message":"[Login] [Login successful] [Username: [email protected]] [Request-IP: x.x.x.43]","timestamp":"2024-09-04T05:04:13.354Z"}
{"level":"info","message":"[Login] [Login successful] [Username: [email protected]] [Request-IP: x.x.x.72]","timestamp":"2024-09-04T05:04:57.846Z"} |
Beta Was this translation helpful? Give feedback.
-
I did see app.set('trust proxy', 1); in librechat code, and GCP LB also have X-Forwarded-For. Not sure why it’s not taken. I am trying X-Real-IP now. Will see that take or not and will output request header info for further debugging. Thank you so much for your helpful and fast reply! I will share our results. Xueshan |
Beta Was this translation helpful? Give feedback.
-
I have tested with GCP LB. I am also able to output logs as you suggested. When I think it might worthwhile to 1. Make an env so to allow customize app.set call. 2. output request ips really helped to nail this down, so a flag to turn it on/off would also be good. My problem is resolved by |
Beta Was this translation helpful? Give feedback.
@danny-avila
I have tested with GCP LB.
app.set('trust proxy', true);
works, instead ofapp.set('trust proxy', 1)
;I am also able to output logs as you suggested. When
app.set('trust proxy', 1)
, the code doesn't not use client ip (req.ip is LB's address), even X-Forwarded-For and X-Real-IP are both presented in the log.app.set('trust proxy', true);
will show req.ip is the real client ip.I think it might worthwhile to 1. Make an env so to allow customize app.set call. 2. output request ips really helped to nail this down, so a flag to turn it on/off would also be good.
My problem is resolved by
app.set('trust proxy', true);
Thank you!