# Sensitive data in stacktrace

**URL:** <https://forum.elixirforum.com/t/sensitive-data-in-stacktrace/19464>\
**Category:** Questions\
**Tags:** stacktrace\
**Created:** [January 17, 2019, 11:09am UTC](https://forum.elixirforum.com/t/sensitive-data-in-stacktrace/19464 "2019-01-17T11:09:00Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![chocolatedonut](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/50afbb/32.png) [@chocolatedonut](https://forum.elixirforum.com/u/chocolatedonut)\
**Post date:** [September 15, 2022, 8:57am UTC](https://forum.elixirforum.com/t/sensitive-data-in-stacktrace/19464/5 "2022-09-15T08:57:52Z")

</div>

Despite all the helpful tips, I still am not able to hide password of the following `:gen_statem`-based RabbitMQ consumer:

```elixir
defmodule Rabbit.Consumer do
  @derive {Inspect, only: [:channel]}
  defstruct [:config, :channel]
end

```

**I’d like that the `:config` field (above), which includes the password, be hidden in all these cases:**

1. `:sys.get_state Rabbit.Consumer`
2. when `Rabbit.Consumer` outright crashes and produces such stacktrace (observe `password` in plain sight)

```elixir
[error] CRASH REPORT Process 'Rabbit.Consumer' with 0 neighbours exited with reason: 
  no such process or port in call to 
  gen_server:call(<0.1026.0>, {call,{'basic.ack',1,false},none,<0.1012.0>}, 15000) 
  in gen_server:call/3 line 382

[error] Supervisor 'Rabbit.Application' had child 'Rabbit.Consumer' started with
 'Rabbit.Consumer':start_link([
   {host,<<"localhost">>},
   {username,<<"admin">>},
   {password,<<"admin">>},
   {virtual_host,<<"/">>},
   ...]) 
   at <0.3177.0> exit with reason 
   {shutdown,{gen_server,call,[<0.3196.0>,
     {call,{'queue.declare',0,nil,false,true,false,false,false,[]},none,<0.3177.0>},15000]}} 
   in context child_terminated

```

## What I tried already

### `format_status`

I added `:gen_statem` `c:format_status/2` and also OTP 25 [c:format\_status/1](https://www.erlang.org/doc/man/gen_statem.html#Module:format_status-1):

```elixir
def format_status(s) do # format_status/1 in OTP 25
  Map.drop s.data, [:config]
end

```

This did help as `:sys.get_status` didn’t print the sensitive `:config` anymore. **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 a `rescue` and pruned args from `System.stacktrace()` (using the suggested `Plug.Crypto.prune_args_from_stacktrace/1`). **But,** this doesn’t help when `:gen_statem`/`Rabbit.Consumer` itself crashes. How can one `prune_args_from_stacktrace` of the process itself (be it GenServer, :gen\_statem, etc.)?

### `Process.flag(:sensitive, true)`

```elixir
def init(opts) do
  Process.flag(:sensitive, true)
  # etc.

```

Neither of the cases **1.** or **2.** above were solved.

[Docs for the `:sensitive` flag](https://www.erlang.org/doc/man/erlang.html#process_flag-2) say

> Sets or clears flag sensitive for the current process. When a process has been marked as sensitive by calling process\_flag(sensitive, true), features in the runtime system that can be used for examining the data or inner working of the process are silently disabled.
> 
> Features that are disabled include (but are not limited to) the following:
> 
> - Tracing. Trace flags can still be set for the process, but no trace messages of any kind are generated. (If flag sensitive is turned off, trace messages are again generated if any trace flags are set.)
> 
> - Sequential tracing. The sequential trace token is propagated as usual, but no sequential trace messages are generated.
> 
> process\_info/1,2 cannot be used to read out the message queue or the process dictionary (both are returned as empty lists).
> 
> Stack back-traces cannot be displayed for the process.
> 
> In crash dumps, the stack, messages, and the process dictionary are omitted.
> 
> If {save\_calls,N} has been set for the process, no function calls are saved to the call saving list. (The call saving list is not cleared. Also, send, receive, and time-out events are still added to the list.)

The following bolded part from above

> “Features that are disabled include ( **but are not limited to** )”.

made me hopeful that state will also be included (among disabled features).

So, I saw the following on [erlef.github.io](https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/sensitive_data.html):

> “Process state […] cannot be introspected”

Alas, this doesn’t seem to be true - `:sys.get_state Rabbit.Consumer` still shows the password.

Here’s this section verbatim:

> Finally, a process can be marked as ‘sensitive’, using erlang:process\_flag/2. This has the following effect:
> 
> - Message queue contents cannot be introspected, and is not written to a crash dump
> - Process dictionary cannot be introspected, and is not written to a crash dump
> - Process state of a gen\_server, gen\_event or gen\_statem process cannot be introspected, and is not written to a crash dump
> - Process heap and stack are not written to a crash dump
> - The process cannot be traced

---

_[View the full topic](https://forum.elixirforum.com/t/sensitive-data-in-stacktrace/19464)._
