PhoenixReplay.Redactor behaviour (PhoenixReplay v0.6.2)

Copy Markdown View Source

Behaviour for masking sensitive text in recordings before they are stored.

A PhoenixReplay.Sanitizer runs inside your LiveViews on every event, so it filters by key, which is cheap. Values such as an email address typed into a form, a card number in a log message or a phone number in SQL carry no telling key, and finding them in text takes longer. A redactor finds them when a session is saved, in a background task, so its cost never reaches your users.

A redactor receives one string at a time. redact_term/2 walks maps, lists, tuples and structs, keeping struct types so recorded templates still render, and leaves opaque values such as Date and Decimal as they are.

Configure it with :redact:

# Regexes, matched by PhoenixReplay.Redactor.Patterns
config :phoenix_replay, redact: [~r/\b\d{13,19}\b/]

# Detection with Obscura, an optional dependency
config :phoenix_replay, redact: {PhoenixReplay.Redactor.Obscura, []}

Recordings are redacted when they are saved and when the dashboard opens a session that is still running, so stored recordings and live sessions show the same values. A redactor that fails stops the save rather than storing unredacted data.

Summary

Types

Called with the number of events redacted so far and the total.

t()

A redactor module and its options.

Callbacks

Redacts sensitive values in text.

Functions

Redacts every part of recording that holds recorded values: its URL, params, session, the URL the user came from, the user agent, captured headers and landing, and the data of each event. The viewport and tab id are kept as they are.

Redacts every string within term, recursing into maps, lists, tuples and structs. Map keys are kept as they are.

Types

progress()

@type progress() :: (non_neg_integer(), non_neg_integer() -> any())

Called with the number of events redacted so far and the total.

t()

@type t() :: {module(), keyword()}

A redactor module and its options.

Callbacks

redact(text, opts)

@callback redact(text :: String.t(), opts :: keyword()) ::
  {:ok, String.t()} | {:error, term()}

Redacts sensitive values in text.

Functions

redact_recording(recording, redactor, opts \\ [])

@spec redact_recording(PhoenixReplay.Recording.t(), t() | nil, keyword()) ::
  {:ok, PhoenixReplay.Recording.t()} | {:error, :redaction_failed}

Redacts every part of recording that holds recorded values: its URL, params, session, the URL the user came from, the user agent, captured headers and landing, and the data of each event. The viewport and tab id are kept as they are.

Without a redactor, the recording is returned as it is. A failure is {:error, :redaction_failed}, without the redactor's reason, which may quote the text it could not redact.

Options

  • :progress — a progress/0 function, called after each event

redact_term(text, redactor)

@spec redact_term(term(), t()) :: {:ok, term()} | {:error, term()}

Redacts every string within term, recursing into maps, lists, tuples and structs. Map keys are kept as they are.