Ответы пользователя по тегу Express.js
  • Как организовать взаимодействие sock.js и express?

    @Kilai Автор вопроса
    Более подробное перечитывание документации дало свои результаты. Создатели SockJS заблокировали авторизацию через кукиз. Мотивировали это возникновением проблем безопасности если используется эмуляция через iframe.

    Authorisation

    SockJS-node does not expose cookies to the application. This is done deliberately as using cookie-based authorisation with SockJS simply doesn't make sense and will lead to security issues.

    Cookies are a contract between a browser and an http server, and are identified by a domain name. If a browser has a cookie set for particular domain, it will pass it as a part of all http requests to the host. But to get various transports working, SockJS uses a middleman

    an iframe hosted from target SockJS domain. That means the server will receive requests from the iframe, and not from the real domain. The domain of an iframe is the same as the SockJS domain. The problem is that any website can embed the iframe and communicate with it - and request establishing SockJS connection. Using cookies for authorisation in this scenario will result in granting full access to SockJS communication with your website from any website. This is a classic CSRF attack.

    Basically - cookies are not suited for SockJS model. If you want to authorise a session - provide a unique token on a page, send it as a first thing over SockJS connection and validate it on the server side. In essence, this is how cookies work.

    Ссылка на оригинал
    Ответ написан
    Комментировать
  • Как организовать взаимодействие sock.js и express?

    @Kilai Автор вопроса
    @pomeo команда

    echo.installHandlers(server, {prefix:'/echo'});

    вешает обработчик на путь '/echo' явно не затрагивая express. А следовательно, ни какая переменная req, не доступна в обработчике нового Web Socket подключения

    echo.on('connection', function (conn) {
        connList.push({connaction: conn})
        conn.on('data', function (message) {
            connList.forEach(function (thisConnaction){
                thisConnaction.write(message);
            });
        });
        conn.on('close', function () { });
    });
    Ответ написан
    Комментировать
  • Как организовать взаимодействие sock.js и express?

    @Kilai Автор вопроса
    Предполагается что есть два пути.
    Первый устанавливать в cookies страницы несколько ключей, которые после установления соединения будут отправлены по Web Socket. И по ним из переменной app будет выужена нужная информация.
    Второй если это возможно при установлении соединения пока клиент и сервер ещё общаются через HTTP переслать идентификатор сессии.

    Интересно как это реализовать если возможно.
    Ответ написан
    Комментировать