Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

Escape secrets before you mask them in logs

Masking secrets is string replacement on untrusted input: escape the values, drop empty ones, mask structured log events before formatting, and check every field, not just the message.

01 · Before and afterThe pattern

TypeScript
const escape = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
function maskingLog(next: Handler, secrets: string[]): Handler {
  const vals = secrets.filter(Boolean).map(escape);
  if (!vals.length) return next;
  const re = new RegExp(vals.join('|'), 'g');           // built once
  return { event: e => next.event({ ...e,
    text: e.text?.replace(re, '********'), detail: e.detail?.replace(re, '********') }) };
}

02 · Run it on your appThe check

If one of your secrets contains a $ or a ., is it still masked in every log line and every structured log field?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.