Skip to content

Commit e4ea11b

Browse files
authored
Merge pull request #1292 from joshprice/enable-unsafe-to-atom-check
Enable UnsafeToAtom by default and frame it as a security check
2 parents 6501c08 + a16feea commit e4ea11b

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

.credo.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
{Credo.Check.Warning.SpecWithStruct, []},
158158
{Credo.Check.Warning.StructFieldAmount, []},
159159
{Credo.Check.Warning.UnsafeExec, []},
160+
{Credo.Check.Warning.UnsafeToAtom, []},
160161
{Credo.Check.Warning.UnusedEnumOperation, []},
161162
{Credo.Check.Warning.UnusedFileOperation, []},
162163
{Credo.Check.Warning.UnusedKeywordOperation, []},
@@ -213,8 +214,7 @@
213214
{Credo.Check.Warning.LazyLogging, []},
214215
{Credo.Check.Warning.LeakyEnvironment, []},
215216
{Credo.Check.Warning.MapGetUnsafePass, []},
216-
{Credo.Check.Warning.MixEnv, []},
217-
{Credo.Check.Warning.UnsafeToAtom, []}
217+
{Credo.Check.Warning.MixEnv, []}
218218

219219
# {Credo.Check.Refactor.MapInto, []},
220220

lib/credo/check/warning/unsafe_to_atom.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ defmodule Credo.Check.Warning.UnsafeToAtom do
33
id: "EX5016",
44
base_priority: :high,
55
category: :warning,
6-
tags: [:controversial],
76
explanations: [
87
check: """
9-
Creating atoms from unknown or external sources dynamically is a potentially
10-
unsafe operation because atoms are not garbage-collected by the runtime.
8+
Creating atoms from unknown or external input is a security risk, not just a
9+
style preference.
10+
11+
Atoms are not garbage-collected by the runtime and the number of atoms a node
12+
can hold is capped (1_048_576 by default). Any code path that turns
13+
attacker-controlled input into atoms can therefore exhaust the atom table and
14+
crash the entire VM. That is a denial-of-service vulnerability, and in a
15+
web-facing application it is a CVE waiting to happen.
1116
1217
Creating an atom from a string or charlist should be done by using
1318
@@ -33,6 +38,9 @@ defmodule Credo.Check.Warning.UnsafeToAtom do
3338
3439
Jason.decode(str)
3540
41+
For more on atom exhaustion as an attack vector, see:
42+
43+
https://erlef.org/blog/security/atom-exhaustion
3644
"""
3745
]
3846

0 commit comments

Comments
 (0)