# Is socket secure?

**URL:** <https://forum.elixirforum.com/t/is-socket-secure/44509>\
**Category:** Questions\
**Tags:** phoenix, liveview\
**Created:** [December 14, 2021, 6:06am UTC](https://forum.elixirforum.com/t/is-socket-secure/44509 "2021-12-14T06:06:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![llama](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/llama/32/23675_2.png) [@llama](https://forum.elixirforum.com/u/llama)\
**Post date:** [December 14, 2021, 6:06am UTC](https://forum.elixirforum.com/t/is-socket-secure/44509/1 "2021-12-14T06:06:58Z")

</div>

I’m assuming the answer is ‘yes’, but I need confirmation.

Is the socket private to the server/code? For example, if I assign user info to the socket, that information will not change until I explicitly change it and a malicious user can’t do something on their end to change it?

---

<div class="post-metadata">

**Author:** ![trisolaran](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/32/23748_2.png) [@trisolaran](https://forum.elixirforum.com/u/trisolaran)\
**Post date:** [December 14, 2021, 7:26am UTC](https://forum.elixirforum.com/t/is-socket-secure/44509/2 "2021-12-14T07:26:29Z")

</div>

The answer to your first question is yes, the socket state is controlled by a process on the server side. So only your server-side code can modify the socket state.

However, whether “a malicious user can do something on their end to change it” depends on the security of your implementation. A malicious user has complete control of the code running on their end (the JS client) and you should never assume that information coming from the client is valid or trustworthy.

So, for instance, if you naively set a user\_id in your socket only because the client told you “this is my user id, trust me!” like this:

```elixir
def handle_in("hello_msg", %{"user_id" => user_id}, socket) do
  {:noreply, assign(socket, :user_id, user_id)}
end

```

You’re of course opening yourself up to every kind of exploit.

The general rule (in Phoenix or in any other web application) is: always assume that whatever comes from the client has been manipulated by an attacker 🙂

I hope this helps

---

<div class="post-metadata">

**Author:** ![llama](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/llama/32/23675_2.png) [@llama](https://forum.elixirforum.com/u/llama)\
**Post date:** [December 14, 2021, 7:35am UTC](https://forum.elixirforum.com/t/is-socket-secure/44509/3 "2021-12-14T07:35:26Z")

</div>

Thank you, that helps and brings me peace of mind 🙂
