Skip to content

Mask environment-sourced secrets in dry-run and error output - #44

Merged
archlemon merged 2 commits into
mainfrom
fix/mask-env-secrets
Nov 14, 2026
Merged

archlemon merged 2 commits into
mainfrom
fix/mask-env-secrets

Conversation

@archlemon

Copy link
Copy Markdown
Member

Fixes #33.

Follows the README convention that secrets live in the environment: config.Load records each ${VAR} it substituted from the environment (Config.EnvValues; defaults aren't recorded), and the CLI masks those values back to ${VAR} in --dry-run output and per-channel errors.

[dry-run] channel "hook":
  POST http://127.0.0.1:1/hooks/${TOK}?api_key=REDACTED
  body: {"token": "${TOK}"}
[dry-run] channel "cmd":
  exec /bin/sh -c echo got $0; exit 1 ${TOK} (stdin: 2 bytes)
channel "hook": http request: Post "http://127.0.0.1:1/hooks/${TOK}?api_key=${TOK}": dial tcp ...: connection refused
channel "cmd": exec /bin/sh: exit status 1: got ${TOK}
  • strings.NewReplacer with values sorted longest-first, so a secret containing another is masked whole. Values under 4 bytes are skipped to avoid masking common substrings.
  • Name-based REDACTED heuristic kept for literals written in the config.
  • expandEnv/expandString folded into a small expander type that tracks missing and used variables.
  • README describes exactly what is masked.

Tests: masker ordering + short values; end-to-end dry-run and real-send errors for an http URL path and exec args contain no secret.

--dry-run promised redacted secrets but only masked header/query/form
fields with credential-looking names. Webhook tokens in URL paths, exec
args and JSON bodies printed verbatim, and connection errors printed the
full URL to stderr (kept by cron/CI logs).

Config loading now records every value substituted from the
environment, and the CLI replaces each occurrence (4+ bytes, longest
first) with its ${VAR} reference in dry-run descriptions and per-channel
error messages. The name heuristic stays for literal values.

Fixes #33
@archlemon archlemon added bug Something isn't working security Security-relevant fix or hardening labels Nov 14, 2026
@archlemon
archlemon merged commit 402eb09 into main Nov 14, 2026
2 checks passed
@archlemon
archlemon deleted the fix/mask-env-secrets branch November 14, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security-relevant fix or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secrets from env leak in --dry-run and error output

1 participant