SpoonWood
Hello Everyone,
We are using LiveView to build a feature that displays some information in the admin dashboard of our Application, but we are not quite sure how to secure the websocket against access of non registered users.
Is the socket secure if we are using a signing salt and a Session key, having installed LiveView the exact Way thats recommended on Hexdocs.pm (we are using LiveView 0.8.1 currently)
Thank you very much in Advance
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #ai
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bruteforcecat
there should be lots of different approach. But one approach is using Phoenix.Token to sign some user session data. and then in Socket.connect/3 we can verify if the token is valid. because the token is signed, it helps us against of tampering but if you don’t want people able to see what’s inside the token, you can also use
Phoenix.Token.encryptchrismccord
Add your
liveroute definition behind your regular:adminplug/pipeline that performs admin user authentication and you are all set. You can reference the user off the HTTP request, and fallback to the user_id in the session, which comes from a signed token on the client, so you are covered in both HTTP and WebSocket cases security wise:LostKobrakai
I’m wondering if we’d need to talk about another factor of security for liveview:
A liveview process is long lived and potentially valid indefinitely if the connection is kept alive. For http one would check the validity of the user for each request, because it’s stateless. With stateful connections this can be more tiered, e.g. let the user read things for a certain time (or indefinitely) while e.g. checking validity for each writing operation. Even writing operations could be tiered to only creating data and destructive operations overwriting existing data. But I’m not really seeing those options used in the wild. Most people seem to fetch the user once and let it be valid for the lifetime of the liveview process. Isn’t this a potentially dangerous way of handling authentication?
josevalim
Every operation you do against the database needs to be verified for user permission, you need to check if the user belongs to that organization, if they are the manager of a project, if they can access that chat room, etc. This logic is generally kept in the context, tied to the domain operation, so you go through it regardless if you are interacting with your domain via live views or controllers. In code, this means you should do:
Instead of:
Failing to scope this on regular HTTP requests can also be very troublesome, as it means a user can access any other organization.
The scenario you describe is only a concern if you are “preloading” permissions and storing it somewhere, which is not different from putting it in a cache, or an agent, live view state, etc.
And for things like user access, LV supports disconnecting any enabled socket. I even plan to submit changes to
mix phx.gen.authso we perform this disconnection by default on logout.LostKobrakai
This is the part my question was targeted at - user sessions. If a session is compromised and the session key is removed from its storage on the server fresh http requests will fail to validate. For liveview existing connections either need to be closed if a certain session key is invalidated or at least have some means to over time detect that the session is no longer valid.
Edit:
I just looked at the example in detail: I’m not sure if a logout should close all connections scoped to the user. When I’m logging out of my desktop I won’t want to disconnect my laptop at the same time. For normal usage disconnecting by session key would seem like the way to go, possibly having a way to disconnect anything linked to a user account.
Exadra37
I am new to LV, therefore I may be misunderstanding something here, but to me this approach seems to let me run an enumeration attack by changing the id in the
admin_user_id, thus letting me to get access to other admins?LostKobrakai
The session data is signed on the server, returned to the client in the html, sent back to the server and validated. So no user tampering allowed.
Exadra37
Sorry I missed that the signature of
mount/3ismount(params, session, socket)… I am feeling a bit stupid nowjosevalim
You can also disconnect just one of the sessions. All you have to do is identify the connections per session token rather than user id. That’s what I am submitting to
mix phx.gen.auth.josevalim
Here are the changes to enable this feature on top mix phx.gen.auth: Set the live_socket_id on login and disconnect on logout · dashbitco/mix_phx_gen_auth_demo@1eebcae · GitHub
It is really straight-forward and it is per session (i.e. it doesn’t disconnect all sessions, only the current one).