FeoxDB.CredoChecks.NoUnsafeAtomConversion (feox_db v0.2.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Flags calls that convert arbitrary external input into atoms or terms without a safety net.

FeOxDB is a key-value store that regularly handles keys and values coming straight from client input (over the wire, from disk, etc). Converting such input directly into atoms or Erlang terms is dangerous:

  • String.to_atom/1 creates a new atom for every distinct input it sees. Since atoms are never garbage collected, an attacker who controls the input can exhaust the atom table and crash the whole VM. String.to_existing_atom/1 should be used instead, which raises instead of creating new atoms.
  • :erlang.binary_to_term/1 (without the [:safe] option) can construct arbitrary terms, including atoms (same atom-table risk as above) and function/pid/reference values crafted by a malicious payload. :erlang.binary_to_term/2 with the :safe option should be used instead.

This check exists purely as a regression guard: this codebase currently avoids both patterns, but nothing previously stopped a future change from reintroducing them.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.