Sobelow.Misc.BinToTerm (Sobelow v0.19.0)
View SourceInsecure use of binary_to_term
Decoding untrusted Erlang terms without :safe can create atoms and
exhaust VM resources. The :safe option prevents new atoms, but still
permits executable terms. Decoding a function does not itself execute it;
later application code may invoke it, including indirectly via protocols.
Dynamic input to :erlang.binary_to_term/1,2 is reported at high confidence,
or medium when its options explicitly include :safe.
Plug.Crypto.non_executable_binary_to_term/1,2 rejects executable terms,
but is still reported at high confidence unless :safe is also present.
Computed options are not assumed safe. Confidence here reflects decoder
protections; this check does not establish whether input is trusted.
Prefer Plug.Crypto.non_executable_binary_to_term(data, [:safe]) for
untrusted ETF input, and validate the resulting types and structure.
That combination is omitted by this check, but omission is not an assurance
of bounded resource use. ETF supports compressed terms: neither :safe nor
rejection of executable terms imposes a decompression or decoded-memory
budget. Even uncompressed terms can allocate more memory than their encoded
representation. A limit on encoded bytes alone may therefore be insufficient.
Validate types and structure, but remember that validation after decoding cannot prevent allocations already made by the decoder. Bound input, concurrency and execution resources independently; for hostile inputs, consider an isolated decoding worker with externally enforced resource limits. No decoder option described here provides a hard cumulative resource budget, and subsequent processing of the decoded term needs its own limits. Confidence reflects decoder protections, not proof of resource safety.
binary_to_term checks can be ignored with the following command:
$ mix sobelow -i Misc.BinToTerm