LostKobrakai
32) ElixirConf 2017: Plugging the Security Holes in Your Phoenix Application
After having watched the talk I’m wondering if this would also be a good opportunity to gather examples / tips about how to prevent or mitigate the mentioned issues. I’d expect the e.g. for the mentioned session issue there might already be examples out there. Also I’m especially curious about the last topic on mass assignment. How do you guys handle changesets which are allowed to change things like admin flags or alike, so at best they’re not accidentally usable from any frontend forms.
Most Liked
LostKobrakai
I’ll start by adding my captain obvious solution to prevent accidental changes to admin flag fields: Don’t handle it through the params sent to changeset/2, but only allow them to be changed by custom functions.
def make_admin(%User{} = user) do
user
|> Ecto.Changeset.change(%{is_admin: true})
|> Repo.update()
end
def put_admin_flag(%Ecto.Changeset{} = changeset) do
Ecto.Changeset.change(changeset, %{is_admin: true})
end
This way in each places, where setting that flag should indeed be possible it has to be done explicitly, independent to any changeset/2 functions/params.
benwilson512
One person’s duplication is another’s de-coupling. ![]()
griffinbyatt
I’ll comment with some of my thoughts a bit later when I have some more time. Until then, I wanted to say thanks for posting, and I’m happy to answer questions about the content if anyone has any!








