tim2CF
Let’s say we have a module like
defmodule Foo do
@salt Application.get_env(:foo, :salt, [])
def hash(password) do
try do
{:ok, md5(password, @salt)}
rescue
e -> {:error, {e, __STACKTRACE__}}
end
end
defp md5(password, salt = [_ | _]) do
Enum.reduce(salt, password, &:erlang.md5(&2<>&1))
end
end
And when we call &hash/1 function it returns error
iex(19)> Foo.hash "123"
{:error,
{%FunctionClauseError{
args: nil,
arity: 2,
clauses: nil,
function: :md5,
kind: nil,
module: Foo
},
[
{Foo, :md5, ["123", []], [file: 'iex', line: 27]},
{Foo, :hash, 1, [file: 'iex', line: 22]},
{:erl_eval, :do_apply, 6, [file: 'erl_eval.erl', line: 677]},
{:elixir, :eval_forms, 4, [file: 'src/elixir.erl', line: 265]},
{IEx.Evaluator, :handle_eval, 5, [file: 'lib/iex/evaluator.ex', line: 249]},
{IEx.Evaluator, :do_eval, 3, [file: 'lib/iex/evaluator.ex', line: 229]},
{IEx.Evaluator, :eval, 3, [file: 'lib/iex/evaluator.ex', line: 207]},
{IEx.Evaluator, :loop, 1, [file: 'lib/iex/evaluator.ex', line: 94]}
]}}
And we want to put this stacktrace to Logger (let’s say for easier debugging)
But we see, what stacktrace can contain sensitive data (in example is password = “123”)
Of course we can remove all arguments from stacktrace manually, but in most cases arguments are useful
Maybe there is already implemented solution to remove some arguments of some functions from stacktrace by marking them in module definition somehow?
It would be nice to say somehow that n-th argument of foo function in module Bar is sensitive and should be excluded from stacktrace
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sfusato
There is ‘Custom struct inspections’ that was just released with Elixir 1.8:
https://github.com/elixir-lang/elixir/blob/v1.8/CHANGELOG.md
Maybe return just the tail of the stack trace and at an upper-level inspect your struct with the returned stack trace. This would obfuscate the password field or whatever you set to hide from your struct.
josevalim
Here is what Plug.Crypto does regarding the stacktrace: plug_crypto/lib/plug/crypto/key_generator.ex at 76a595f26529cd550f32166c3288358e1785fb1f · elixir-plug/plug_crypto · GitHub
zazaian
@sfusato’s response is very good, though it seems that in some instances you’d want to expressly name the excluded struct parameters, rather than list all of the unexcluded ones.
The Inspect protocol actually allows you to name the struct attributes that are excluded from inspection, which is cleaner for circumstances in which most of a struct’s attributes are not private or secret. Here’s an example:
If you had a myriad of secret attributes within a single struct though, using
onlyis probably cleaner and safer, as adding additional secret attributes would not require you to also add them for exclusion:Please note that the
@derivecall does have to be declared above thedefstructkeyword as indicated in theInspectdocs, as shown above.chocolatedonut
Despite all the helpful tips, I still am not able to hide password of the following
:gen_statem-based RabbitMQ consumer:I’d like that the
:configfield (above), which includes the password, be hidden in all these cases::sys.get_state Rabbit.ConsumerRabbit.Consumeroutright crashes and produces such stacktrace (observepasswordin plain sight)What I tried already
format_statusI added
:gen_statemc:format_status/2and also OTP 25 c:format_status/1:This did help as
:sys.get_statusdidn’t print the sensitive:configanymore. But, it didn’t help with neither of the cases 1. or 2. above.Prune args from stacktrace
I wrapped
Rabbit.Consumer’s call to a different process with arescueand pruned args fromSystem.stacktrace()(using the suggestedPlug.Crypto.prune_args_from_stacktrace/1). But, this doesn’t help when:gen_statem/Rabbit.Consumeritself crashes. How can oneprune_args_from_stacktraceof the process itself (be it GenServer, :gen_statem, etc.)?Process.flag(:sensitive, true)Neither of the cases 1. or 2. above were solved.
Docs for the
:sensitiveflag sayThe following bolded part from above
made me hopeful that state will also be included (among disabled features).
So, I saw the following on erlef.github.io:
Alas, this doesn’t seem to be true -
:sys.get_state Rabbit.Consumerstill shows the password.Here’s this section verbatim: