If you run Elixir or Erlang in production long enough, you know this Monday morning routine. Dependabot or mix deps.audit turns CI red because a new CVE just landed in hackney, plug, or cowlib. You spend twenty minutes reading the advisory diff, only to find out the bug sits inside a multipart header parser or a SOCKS5 proxy helper that your JSON-only API never touches. Upgrading right away is blocked by a version constraint in another library, so somebody adds an ignore flag and hopes nobody forgets why it was added six months later.

Go solved a big chunk of this problem years ago with govulncheck. Instead of treating go.mod as a flat bag of equally dangerous packages, it walks the call graph and checks whether your code can actually reach the vulnerable function. The BEAM ecosystem didn't have an equivalent tool, even though our advisory feeds already contain the exact symbol data needed to build one.

So I built VulnCheck, an open-source, function-level vulnerability reachability scanner for Elixir, Erlang, and Gleam with zero runtime dependencies. Here is how it works under the hood, why naive call graphs are actively dangerous on the BEAM, three nasty compiler traps I ran into along the way, and what the honest precision/recall numbers look like on real projects.

The Symbol Data Was Already Sitting in the Feeds

For years, lockfile scanners like mix_audit had a fair excuse: older Hex security advisories only published a package name and a SemVer range. Without reading the patch yourself, there was no machine-readable way to know which module or function carried the bug.

That changed once the Erlang Ecosystem Foundation (EEF) became an official CVE Numbering Authority (CNA). Recent CVE 5.1 records for BEAM packages publish exact Module.fun/arity signatures inside programRoutines, along with affected module lists and occasional OTP runtime version bounds:

{ "affected": [ { "packageName": "plug", "packageURL": "pkg:hex/plug", "programRoutines": [ { "name": "'Elixir.Plug.Conn.Query':decode/4" } ], "versions": [ { "version": "0", "lessThan": "1.16.4", "status": "affected" } ] } ] } 

By pairing the OSV.dev Hex archive (for fast package and git-commit range matching) with EEF CNA / MITRE CVE 5.1 records, we know the exact target MFA. The hard part is answering a deceptively simple question: can a compiled BEAM release actually reach 'Elixir.Plug.Conn.Query':decode/4 or 'Elixir.Ash.Actions.Aggregate':run/4 at runtime?

Why Parsing Elixir Source AST Is a Dead End

When I first sketched this out, the obvious temptation was to run Code.string_to_quoted/2 across lib/ and deps/ and collect function calls from source files. That idea falls apart on the very first Phoenix app.

Half of the real call graph in an idiomatic Elixir codebase doesn't exist in .ex files as literal function calls. Macros generate it during compilation: use Phoenix.Router, plug Plug.Parsers, use Phoenix.Controller, use GenServer, Oban.Worker, Ash resources, Ecto schemas. Two lines of router DSL expand into match clauses, pipeline functions, and plug dispatch calls that only exist after compilation.

Fortunately, elixirc, erlc, and gleam build --target erlang all converge on .beam files containing the standard :abstract_code chunk in Erlang Abstract Format (:raw_abstract_v1), assuming debug info wasn't stripped. OTP's built-in :beam_lib reads those chunks straight off disk without loading the target module into the running VM:

{:ok, {module, [ abstract_code: {:raw_abstract_v1, forms}, exports: exports, attributes: attributes ]}} = :beam_lib.chunks(beam_bytes, [:abstract_code, :exports, :attributes]) 

Working at the :raw_abstract_v1 layer buys three things at once:

  1. Every Elixir macro has already been expanded by the compiler, while :file attributes and line annotations still point back to the exact file:line in your source tree.
  2. Polyglot BEAM support comes almost for free. Whether the workspace uses Mix (mix.lock, including umbrellas), Erlang's rebar3 (rebar.lock), or Gleam (manifest.toml), the .beam call instructions inside _build or build/dev/erlang look identical.
  3. Even when a dependency .beam was compiled without debug_info (abstract_code: :no_abstract_code), its :exports and :imports tables are still present in the binary header. VulnCheck can over-approximate outgoing calls from :imports and explicitly flag the incomplete evidence instead of silently guessing.

Why a Naive Static Call Graph Is Unsafe on the BEAM

If you only wire up direct local calls, remote calls (Mod.fun(x)), and captures (&Mod.fun/2), you get a fast analyzer that produces terrible false negatives. For a security tool, noisy warnings are annoying, but telling an engineer that an exploitable CVE is UNREACHABLE is unforgivable.

Unlike Go, BEAM applications don't start at main() and walk down a tree of direct function calls. Control flows through OTP boot descriptors and implicit framework contracts:

  • Application entrypoints live in .app term files ({mod, {'Elixir.MyApp.Application', []}}), alongside the transitive set of started OTP applications in applications.
  • Application.start/2 hands child specs like [{Bandit, plug: MyAppWeb.Endpoint}, MyApp.Worker, {:my_erl_worker, :arg}] to Supervisor.start_link/2. Nothing in your bytecode ever calls MyApp.Worker.handle_call/3 directly; OTP's :gen_server loop invokes it when a message arrives.
  • Network daemons (bandit, cowboy, ranch, thousand_island, grpc) accept bytes on sockets in their own supervision trees, while protocol clients (mint, gun, finch) run frame decoders on incoming server responses as soon as your code opens a connection.
  • Libraries like Tesla, Swoosh, Ecto, and Phoenix.PubSub pick their concrete adapter package from config/config.exs or config/runtime.exs.

To handle this soundly, VulnCheck runs a least-fixpoint entrypoint and behaviour synthesis pass (Entrypoints + Behaviours) over the raw call graph, wiring callbacks for GenServer, :gen_statem (including state_functions mode), :cowboy_rest, Plug, Phoenix, LiveView, Oban.Worker, consolidated protocols (defimpl), and configured adapters.

Here are three real traps that bit me while building and auditing that model.

Trap 1: Phoenix.Controller Hides Every Action Behind apply/3

Open any Phoenix controller and you'll see use Phoenix.Controller followed by normal functions like def index(conn, params). It looks like the router calls ReportController.index/2. It doesn't. use Phoenix.Controller injects an intermediate action/2 dispatcher:

def action(conn, _opts) do apply(__MODULE__, action_name(conn), [conn, conn.params]) end 

To a generic bytecode walker, that line is apply(ReportController, unknown_atom, [conn, params]). Early on, this broke two things at the same time:

  1. Every single vulnerability called from inside a Phoenix controller action got downgraded from a proven REACHABLE trace to POTENTIALLY_REACHABLE (unresolved_dynamic_dispatch). If a team ran mix vulncheck --fail-on reachable in CI, controller vulnerabilities exited 0!
  2. Every dead /2 helper exported by that controller got linked as a speculative target.

Fixing this properly meant teaching the walker and the fixpoint solver to recognize all three ways Plug and Phoenix compile routes across versions: direct Controller.call(conn, :index), Plug.Builder's Controller.call(conn, Controller.init(:index)), and Phoenix 1.7+'s __match_route__/4 4-tuple {metadata, prepare, pipeline, {Controller, :index}}. When every reachable route to a controller passes known exported action atoms (and action/2 itself isn't overridden with custom dynamic apply/3 hooks or bypassed via apply(Controller, :call, ...)), VulnCheck emits proven edges straight to the routed actions. The moment any route passes a dynamic value, it falls back to all /2 exports so soundness is never lost.

Trap 2: Plug.Builder Erases Plug.Parsers.init/1 in Production Builds

A stock Phoenix endpoint plugs Plug.Parsers with [:urlencoded, :multipart, :json], whereas internal JSON APIs usually restrict it to parsers: [:json]. When a multipart CVE drops, a JSON-only service shouldn't get paged for it.

The catch is how Plug.Builder compiles plugs when MIX_ENV=prod (where plug_init_mode defaults to :compile). In dev builds, .beam files contain a runtime call to Plug.Parsers.init(parsers: [:json]). In prod builds, Plug.Builder executes Plug.Parsers.init/1 at compile time and bakes the resulting options tuple directly into Plug.Parsers.call(conn, compiled_opts). There is no Plug.Parsers.init/1 call anywhere in the production bytecode. The analyzer has to inspect literal option terms on both init/1 and precompiled call/2 sites, including custom @behaviour Plug.Parsers modules.

Trap 3: Where Can a fun.(arg) Come From If It Isn't in Any .beam?

In v1.0.1, I tightened how function values (cb.(arg)) are modeled. Because anonymous functions (fn x -> ... end) and captures (&Mod.fun/1) inside .beam modules already add edges at their definition site, invoking a variable cb.(arg) shouldn't force every vulnerability of matching arity across the entire lockfile to stay open. On real apps, that change cut a lot of false noise.

Then a critical soundness audit poked a hole right through that assumption: where can a BEAM process obtain an executable fun that was never constructed inside any analyzed .beam file?

There are two places:

  1. config/config.exs and config/runtime.exs are evaluated .exs scripts, not compiled .beam modules. If someone writes config :my_app, callback: &VulnDep.boom/1 or config :my_app, callback: fn x -> VulnDep.boom(x, :default) end and calls Application.get_env(:my_app, :callback).(arg), .beam-only analysis misses it completely.
  2. :erlang.binary_to_term/1,2 (even with [:safe]!) can deserialize external export funs (&Mod.fun/arity) from untrusted or stored binaries - unlike Plug.Crypto.non_executable_binary_to_term/2, which explicitly rejects executable funs at runtime. Direct Code.eval_string and :erl_eval calls can likewise invoke arbitrary routines without a local apply/3.

In v1.0.2, the static config scanner extracts captures, MFA tuples, Erlang module keys, and calls inside config closures directly into entrypoint roots, while Solver re-enables :function_value escapes whenever binary_to_term, eval, or an unparseable dynamic config is present. Normal apps keep all the precision gains.

Soundness First: Three Verdict Tiers Instead of Binary Guessing

Static analysis on a dynamic VM has hard theoretical limits. Pretending every CVE is a clean boolean choice forces you to either drown developers in false positives or lie about reachability. VulnCheck separates findings into three explicit tiers:

  • REACHABLE - A concrete call chain exists from an application entrypoint (or from a started network daemon's protocol handler / protocol client's response reader) to the vulnerable Module.fun/arity, printed with file:line hops.
  • POTENTIALLY_REACHABLE - The package is part of the production closure and hits a soundness boundary: it runs as an active network daemon with no static trace (active_network_daemon), an unresolved apply(m, f, a) can reach a named module (unresolved_dynamic_dispatch), the advisory itself lacks function-level programRoutines (missing_symbol_granularity), or .beam debug info was stripped (missing_beam_debug_info).
  • UNREACHABLE - Statically excluded under the OTP execution model: function_not_called, module_not_loaded, adapter_not_configured (such as hackney sitting in mix.lock when Tesla uses Tesla.Adapter.Mint), otp_app_not_started, non_prod_dependency (:dev/:test packages, or runtime: false packages never called from prod code), or otp_version_unaffected.

Here is an illustrative terminal run on a Phoenix + Ash + Tesla/Mint service:

VulnCheck 1.0.2 - BEAM Reachability Vulnerability Audit Target: my_fintech_api (mix, Elixir 1.18.2 / OTP 27.2, env: prod) Lockfile: 74 prod packages (19 dev/test excluded) | Scan time: 142 ms (cached) [REACHABLE] CVE-2026-101028 (HIGH | CVSS 7.5) - ash 3.34.2 (fix: 3.34.6) Summary: Ash.count, Ash.exists and Ash.aggregate skip related resources' read policies Target: Ash.Actions.Aggregate.run/4 Trace: 1. MyFintechWeb.ReportController.index/2 (lib/my_fintech_web/controllers/report_controller.ex:41) 2. MyFintech.Ledger.count_filtered_entries/2 (lib/my_fintech/ledger.ex:112) 3. Ash.count/2 (deps/ash/lib/ash.ex:1184) 4. Ash.Actions.Aggregate.run/4 (deps/ash/lib/ash/actions/aggregate.ex:29) [POTENTIALLY REACHABLE] CVE-2026-54892 (MEDIUM | CVSS 6.5) - plug 1.16.2 (fix: 1.16.4) Summary: Quadratic-time nested parameter decoding in Plug.Conn.Query Reason: plug runs inside the HTTP pipeline started by MyFintechWeb.Endpoint (active_network_daemon) Suppressed as UNREACHABLE (6 advisories - pass --show-unreachable for details): * 3 in hackney 1.20.1 (adapter_not_configured: Tesla is configured with Tesla.Adapter.Mint) * 1 in hex_core 0.10.0 (otp_version_unaffected: requires OTP <= 25; running OTP 27.2) * 1 in meck 0.9.2 (non_prod_dependency: meck is only used in :test) * 1 in plug 1.16.2 (function_not_called: Plug.Parsers.MULTIPART.init/1 is never called) 

Zero Runtime Dependencies and Zero New Atoms

One rule I refused to compromise on: VulnCheck ships with zero production dependencies (deps(:prod), do: []). A security scanner shouldn't pull twenty extra Hex packages into your dependency graph.

Elixir 1.18+ and Erlang/OTP 27+ already ship with JSON, :beam_lib, :zlib, :zip, :erl_tar, :crypto, :httpc, and :ssl backed by :public_key.cacerts_get/0 (wrapped with strict TLS hostname verification, archive size/entry caps against zip/tar bombs, and SSRF redirect blocks covering HTTPS downgrades, loopback, 0.0.0.0, IPv4-mapped IPv6, 169.254.169.254, and RFC 1918 / RFC 4193 ranges). Severity scoring includes full CVSS v3.1 and CVSS v4.0 vector implementations from the FIRST specification.

The trickiest low-level constraint on the BEAM is the atom table. Atoms are never garbage-collected, and the VM defaults to a hard ceiling of 1,048,576 atoms. If you parse tens of thousands of OSV JSON entries, arbitrary mix.lock / rebar.lock files, .app descriptors, and mix.exs manifests with :file.consult/1 or default Code.string_to_quoted/2, untrusted strings turn into permanent atoms.

To keep the atom delta strictly at 0 across external inputs:

  • Every Elixir-syntax file (mix.exs, mix.lock, config/*.exs, .vulncheck.exs, .vulncheck.ignore) is parsed via Code.string_to_quoted/2 with a custom static_atoms_encoder that wraps every identifier into {:__lit_atom__, binary_name} without interning atoms. On top of that encoded AST, MixProject statically evaluates multi-clause defp deps(:prod) / defp deps(_) helpers, pipes (|>), Keyword.merge/2, ~w(dev test)a sigils, module attributes, and Mix.env() conditionals without ever executing mix.exs.
  • Erlang term files (.app, rebar.lock) and Gleam manifests (gleam.toml, manifest.toml) use dedicated depth-bounded binary parsers that emit plain binaries and {:atom, binary} tuples.
  • Cached .beam summaries (beam-v4) intern all module names, function names, and file paths into a deduplicated string tuple indexed by integers. Before calling :erlang.binary_to_term(data, [:safe]), the cache reader inspects the 4-byte uncompressed size in the zlib ETF header (<<131, 80, uncompressed_size::32, ...>>) so a corrupted or poisoned cache entry can't inflate gigabytes in C heap memory. An automated test verifies that every cached summary uses zero atoms outside the compile-time atom table of VulnCheck's own modules.

Honest Benchmarks on Real Projects (Including the False Positives)

It's easy to cherry-pick a demo project with three unused HTTP adapters where noise drops by 80%. On umbrella repos and adapter-heavy services, that really happens.

To keep myself honest, the repository includes a reproducible harness (benchmarks/validate_real_world.exs) running against six pinned projects (phoenix_bandit, plug_cowboy_multipart, tesla_mint_hackney, a 3-app Mix umbrella umbrella_three_apps, a pure Erlang rebar3_hackney app, and bandit_tesla_gateway) and a frozen advisory bundle totaling 127 matched findings. Every (project, CVE) pair was manually labeled against the dependency source code at the pinned lockfile version to record whether the vulnerable routine can actually run.

Here are the exact numbers from v1.0.2:

Project Findings TP FP FN TN Precision Recall Noise Reduction
phoenix_bandit 25 18 4 0 3 81.8% 100.0% 12.0%
plug_cowboy_multipart 17 9 8 0 0 52.9% 100.0% 0.0%
tesla_mint_hackney 25 15 4 0 6 78.9% 100.0% 24.0%
umbrella_three_apps 5 1 0 0 4 100.0% 100.0% 80.0%
rebar3_hackney 6 2 3 0 1 40.0% 100.0% 16.7%
bandit_tesla_gateway 49 32 8 0 9 80.0% 100.0% 18.4%
Total 127 77 27 0 23 74.0% 100.0% 18.1%

The number that matters most is FN = 0 (100.0% recall): not a single reachable vulnerability was misclassified as UNREACHABLE. CI runs this harness on every push and fails if FN > 0 or if any project's noise-reduction floor shifts unexpectedly.

Looking at the 27 false positives is just as instructive, because they show the exact ceiling of call-graph analysis without value-flow / symbolic execution:

  1. Bandit.HTTP1.Handler always compiles a protocol-upgrade branch referencing Bandit.WebSocket.Handler in case a plug returns {:upgrade, ...}. Even if your plugs never upgrade to WebSocket, that static call edge exists in Bandit's .beam file.
  2. Plug.Conn.merge_headers/2 iterates over resp_cookies and calls Plug.Conn.Cookies.encode/2. If your API never sets cookies, resp_cookies is always empty at runtime, yet the call instruction sits right there on the response path.
  3. Several older Bandit and Cowboy advisories don't publish function-level programRoutines yet, and since those packages run as active network daemons in the supervision tree, VulnCheck conservatively holds them in POTENTIALLY_REACHABLE.

Documenting those 27 cases openly in docs/VALIDATION.md feels much healthier than cutting soundness corners just to juice a marketing percentage.

Using It Locally and in CI

In an Elixir project, add vulncheck as a build-time dev/test tool and scan your compiled :prod artifacts:

def deps do [ {:vulncheck, "~> 1.0", only: [:dev, :test], runtime: false} ] end 
MIX_ENV=prod mix compile mix vulncheck 

For Erlang (rebar3), Gleam, or minimal CI images, install the standalone escript (there is also a Dockerfile and a composite GitHub Action Voskan/vulncheck@v1.0.2):

mix escript.install hex vulncheck vulncheck --project-dir /path/to/service 

A few workflow details built for real security and platform teams:

  • Output formats cover ANSI terminal, deterministic JSON, Markdown (written automatically to GITHUB_STEP_SUMMARY), GitHub Actions PR annotations and GitLab Code Quality (with monorepo --project-dir path prefixing), SARIF 2.1.0 with full codeFlows for GitHub Code Scanning, CycloneDX 1.6 SBOM, and OpenVEX v0.2.0 (vulnerable_code_not_in_execute_path).
  • Suppressions in .vulncheck.ignore are governed rather than permanent black holes. Every rule needs a reason (plus an optional policy-enforced ISO-8601 expires date; expired rules go live again, and malformed entries fail policy with exit code 1). Pairing --diff origin/main --forbid-new-suppressions on pull requests blocks unreviewed ignore additions.
  • Air-gapped CI runners can scan completely offline: export a verified snapshot once via vulncheck feeds bundle -o feeds.tar.gz and pass --offline --bundle feeds.tar.gz (or import it into the local cache with vulncheck feeds import).

Links & What's Next

VulnCheck is MIT-licensed:

Next on my list is lightweight constant propagation for daemon options (to prune dead WebSocket upgrade and proxy branches when options are statically disabled) and expanding the validation corpus with Gleam, Ecto, Oban, and LiveView apps.

If you run it against a gnarly umbrella repo, a rebar3 service, or a Gleam project, I'd love to hear what it catches - or where you manage to stump the analyzer.