Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Sharing Session ID between Express.js and Socket.io under iframe different origin

I have a problem with my Node application using Express.js, Socket.io and they both share the same session ID. If I open my website without iframe or iframe with same origins, it works perfectly fine (same session ID sharing between HTTP and Socket.io). However, the shared session ID between Express.js and Socket.io doesn't work when it runs under iframe with different origins (parent and child). I don't see the cookie set into Chrome browser under dev tools.

Both origins are non-secure HTTP website (e.g. http://ip.ad.dr.ess/ (parent) to http://ip.ad.dr.ess:6175/ (child)). I access my website directly without going through any web server because I publish my node backend with this port 6175.

Here's the sample code:

Set up express-session:

const sessionMiddleware = session({
  resave: true,
  saveUninitialized: true,
  secret: config.session.secretKey,
  httpOnly: true,  // dont let browser javascript access cookie ever
  ephemeral: true, // delete this cookie while browser close
  cookie: { maxAge: config.session.maxAge, secure: false, sameSite: "none", path: "/" },
  store: new (FileStore(session))({
    logFn: logger.info,
    reapInterval: config.session.reapInterval,
  })
});

app.use(sessionMiddleware);

Set up additional middleware for Express.js:

app.use(cors());
app.options('*', cors());
app.use(helmet({ frameguard: false }));
app.use(compression());
app.use(bodyParser.json());
app.use(cookieParser());

Set up Socket.io with express-session package:

this.io = new Server(server, {
   cors: {
      origin: '*',
      methods: ["GET", "POST", "PUT", "DELETE"],
   },
});

this.socket.io.use((socket, next) => {
   sessionMiddleware(socket.handshake, {}, next);
});
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The issue is fixed in Chrome browser but not in Safari so you might have to work with URL by appending it with session ID and get it on the server. On the Node server, I set only maxAge in cookie object of express-session and both origins must be secure HTTPs website to make it work. Follow this link to fix in Chrome browser: https://serverfault.com/questions/1010706/setup-samesite-none-value-in-nginx-webserver

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda