Reqord.Redactor (reqord v0.4.0)

View Source

Handles redaction of sensitive data from HTTP requests and responses.

This module provides VCR-style filtering to ensure that secrets, API keys, tokens, and other sensitive information are never stored in cassette files.

Configuration

Configure sensitive data filters in your application config:

config :reqord, :filters, [
  {"<API_KEY>", fn -> System.get_env("API_KEY") end},
  {"<TOKEN>", fn -> Application.get_env(:my_app, :api_token) end}
]

Built-in Redaction

Even without explicit configuration, common auth patterns are automatically redacted:

  • Authorization headers
  • Common auth query parameters (token, api_key, etc.)
  • Bearer tokens in response bodies
  • Long alphanumeric strings that look like secrets

Summary

Functions

Redacts sensitive information from request headers.

Redacts sensitive information from response bodies.

Redacts sensitive information from URLs by removing auth query parameters.

Functions

redact_headers(headers)

@spec redact_headers(list() | map()) :: map()

Redacts sensitive information from request headers.

Examples

iex> Reqord.Redactor.redact_headers([{"authorization", "Bearer secret123"}])
%{"authorization" => "<REDACTED>"}

iex> Reqord.Redactor.redact_headers([{"content-type", "application/json"}])
%{"content-type" => "application/json"}

redact_response_body(body)

@spec redact_response_body(binary()) :: binary()

Redacts sensitive information from response bodies.

This handles JSON responses, Bearer tokens, API keys, and other patterns that might contain secrets.

Examples

iex> Reqord.Redactor.redact_response_body(~s({"access_token": "secret123"}))
~s({"access_token": "<REDACTED>"})

redact_url(url)

@spec redact_url(String.t()) :: String.t()

Redacts sensitive information from URLs by removing auth query parameters.

Examples

iex> Reqord.Redactor.redact_url("https://api.com/users?token=secret&name=john")
"https://api.com/users?name=john&token=<REDACTED>"