CSRF token validation failing behind nginx proxy (#38)
Express was not configured to trust proxy headers, causing req.ip to return nginx's internal container IP instead of the actual client IP. In Docker environments, nginx can appear with different internal IPs between requests, causing the CSRF clientId to change and token validation to fail.
This commit is contained in:
@@ -129,6 +129,12 @@ const initializeUploadDir = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Trust proxy headers (X-Forwarded-For, X-Real-IP) from nginx
|
||||||
|
// Required for correct client IP detection when running behind a reverse proxy
|
||||||
|
// This fixes CSRF token validation failures in Docker/K8s environments
|
||||||
|
app.set("trust proxy", 1);
|
||||||
|
|
||||||
const httpServer = createServer(app);
|
const httpServer = createServer(app);
|
||||||
const io = new Server(httpServer, {
|
const io = new Server(httpServer, {
|
||||||
cors: {
|
cors: {
|
||||||
|
|||||||
Reference in New Issue
Block a user