pow-auth/pow

Instructions for WebSocket usage (e.g. Phoenix Channels and LiveView)

开放

#271 创建于 2019年9月11日

 (68 条评论) (10 个反应) (0 位负责人)Elixir (161 个派生)batch import
enhancementhelp wanted

仓库指标

星标
 (1,670 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

It's not obvious how to deal with Pow sessions and WebSockets. There are a few caveats to using WebSockets since browsers don't enforce CORS. Also, Phoenix LiveView won't run subsequent requests through the endpoint (so @current_user is not available).

Some details on WebSocket security: https://devcenter.heroku.com/articles/websocket-security https://gist.github.com/subudeepak/9897212

Support for pulling session data in WebSockets was added to Phoenix in 1.4.7:

socket "/socket", AppWeb.UserSocket,
  websocket: [
    connect_info: [:peer_data, :x_headers, :uri, session: [store: :cookie]]
  ]

A few questions I want to answer are:

  1. Should the session be fetched for requests after initial handshake?
  2. If so, should the session be renewed after timeout in the socket? This would require the reply to update the session cookie.
  3. If not, should the socket be signed somehow, e.g. like a signed url? Not sure if this even makes sense.
  4. What should happen if the session expires while a socket is open (e.g. someone logs out). Should it be aware, and close the socket (if possible)?

I haven't worked much with WebSockets, so I'll have to read up on this and experiment. I will see if I can find some best practices when it comes to sessions and WebSockets. Any comments are welcome 😄


Here's a few links that may be of interest:

https://www.owasp.org/index.php/Testing_WebSockets_(OTG-CLIENT-010) https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#websockets https://spring.io/projects/spring-session https://github.com/spring-projects/spring-session https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html https://abhirockzz.wordpress.com/2017/06/03/accessing-http-session-in-websocket-endpoint/ https://abhirockzz.wordpress.com/2017/06/03/accessing-http-session-in-websocket-endpoint/

贡献者指南