polypush135

polypush135

Can I trust plug's assigns?

If I was storing current_user in the assigns how hard would it be for a hacker to fake that assigns?
Should I do more to assure the assigns is valid?

For example I was reading this auth library example for phoenix

One thing that I don’t like about this pattern is that it expects that you pass the user’s id as a request param and then it compares it to the current_user in the assigns as an extra layer of authorization.

I don’t want to expose the user’s id if I can avoid it so I wonder if this is even necessary
if I can trust my assigns in my plug then I can just lock that user to only even being able to load the user from the assigns alone.

Thus not needing to expose their ID via the params which I feel is a greater risk because of the higher likelihood a hacker would try to use it via a sql injection but, that assumes I can trust my assigns. If I can’t then this makes more sense and in that case I may be better off migrating my ids to UUID for users if only to obscure that vector attempt

Thoughts?

Marked As Solved

polypush135

polypush135

Good to know.

Also something else that has come to my attention is that I at the end of the day I really need to trust my pipeline if I want to trust my plug and I think that is really the big take a way for me.

Also Liked

NobbZ

NobbZ

You can fully trust the assigns, as it only exist serverside. It does not survive a request though, so you need something in the session to repopulate your assigns in subsequent authorized requests.

polypush135

polypush135

The question was more around if someone can fake data in the assigns. IE is the current_user in my plug assigns trustworthy or should I do more to vet that value?

From what I learned the only way you edit the assigns is via plug. So that said it should be noted that you can only trust your assigns as well as you can trust your pipeline (including your hex packages that add to it)

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement