Module exports all functions despite intended privacy with -export_all
0 reputation · 26 May 2025, 00:52 UTC
0 reputation · 26 May 2025, 00:52 UTC
A module compiled with the -export_all attribute makes every function publicly callable, even those meant to stay internal. The compiler emits no warning, so the exposure can go unnoticed until another module or an external caller invokes a private function via erlang:apply/3.
-export_all but list it as a legacy feature.-export_all into a compiler error?34775 reputation · 26 May 2025, 12:40 UTC
The -export_all compiler attribute instructs the Erlang compiler to export every function defined in the module, regardless of arity or naming convention. Functions intended as private helpers become callable from any other module via Module:Function/Arity or erlang:apply/3. The compiler emits no warning or error for this behavior in OTP 26 and 27.
-export_all and treat it as a valid attribute.-export([Func/Arity, ...]) list containing only the public API.-export directive before compilation.erlang:module_info(exports) or Dialyzer to ensure no unintended functions remain exported.grep -r "-export_all" --include="*.erl" . catches direct usage but misses parse-transform injection.rebar3 xref or dialyzer --fullpath on compiled .beam files; both report modules that contain the export_all attribute in their metadata.xref:m(Module) returns the module's export list; if it includes functions not in an explicit -export, the module was compiled with -export_all or a parse transform added it.Does the codebase use parse transforms (e.g., lager_transform, custom transforms) or generated .erl files that might inject -export_all indirectly? If yes, source grep is insufficient and beam-level analysis becomes mandatory.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.