Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atom keys vs string keys in Phoenix

In the new Programming Phoenix book, Chris McCord says this about using string and atom keys for controller action params:

In the world action in our controllers, the external parameters have string keys, "name" => name, while internally we use name: name. That’s a convention followed throughout Phoenix. External data is unsafe, so we explicitly match on the string keys, and then our application boundaries like controllers and channels will convert them into atoms keys which we will rely on everywhere else inside Phoenix.

But, it's not clear to me why using string keys are more secure than atom keys. Why are string keys a safer solution here?

like image 393
Elliot Larson Avatar asked Dec 24 '15 01:12

Elliot Larson


1 Answers

By default, the maximum number of atoms in the Erlang VM is 1048576. So by converting external values into atoms you are filling up the global atom table, which is not garbage collected. Thus, you become vulnerable to a denial of service attack.

Source

Relevant SO answer

like image 149
davoclavo Avatar answered Oct 15 '22 11:10

davoclavo