Sharing logs without exposing secrets

A log pasted into a ticket travels far beyond its recipient. Here is how to clean it up, and how to react if a secret has already leaked.

Where secrets hide

Secrets are rarely posted on purpose. They travel with text shared for another reason: an error to analyse, a configuration to compare, a command that worked yesterday. The most common places:

  • Application logs. A request logged with its headers carries the Authorization header or the session cookie; a logged request body carries the password typed into a login form.
  • Stack traces. An exception message often repeats whatever failed: a full connection string, a URL with its credentials, the value of a parameter.
  • Copied HTTP headers. The “Copy as cURL” command in browser developer tools reproduces the request with its cookies and its authorization header, ready to be replayed by anyone who reads it.
  • .env and configuration files, pasted in full to show a single line.
  • Shell histories. A command typed with a token or a password as an argument stays in ~/.bash_history or in the PowerShell history, and resurfaces when terminal output is shared.
  • Screenshots of a console, a dashboard or a file open in the editor, where a key shows up at the edge of what you meant to show.

A ticket travels far

A ticket looks like it is addressed to one person. In practice it is read by the whole team with access to the tool, copied into email notifications, sometimes relayed to a chat channel, exported, backed up, opened to the contractor who takes over support. It stays available for years after the problem is solved.

A forum, a public repository or an issue on an open-source project goes further still: the page is indexed by search engines, archived, copied. Bots scan these sources continuously for keys, and a cloud provider key that has been posted can be exploited very quickly.

Redact before posting

  1. Keep what matters. The twenty lines around the error are often enough, whereas the full log holds thousands, and as many chances of a leak.
  2. Run the text through the redaction tool. In your browser, it replaces keys in known formats and the values of fields named like secrets.
  3. Review it. A pattern-based tool recognises what it knows: a secret in an unusual format, or stored in a field with an innocuous name, needs a human eye. Look in particular at cookies, URL parameters and command-line arguments.
  4. For a screenshot, cover the area with an opaque box: a light blur or pixelation can sometimes be reversed to recover the original text.

Keep secrets out of logs

The safest redaction is the one you never have to do. A few settings greatly reduce what logs contain:

  • Filter headers. Authorization, Cookie, Set-Cookie and API key headers (X-Api-Key…) are logged without their value. ASP.NET Core HTTP logging, for instance, writes in clear only the headers on an allow list and replaces the value of the others.
  • Choose log levels. Request bodies and connection details belong to the Debug or Trace levels, switched on for the length of a diagnosis, while production runs at its usual level.
  • Use a redaction library. pino's redact option in Node.js, the Microsoft.Extensions.Compliance.Redaction package in .NET or a filter on Python's logging module replace sensitive fields before they are written.
  • Log the identifier rather than the value. The key's name, its ID or its first four characters are enough to know which one was used.

Detect secrets in repositories

Source code is the other main leak path: a committed .env file, a key pasted into a test. Platforms offer automatic detection: GitHub secret scanning recognises the formats of many providers, and its push protection blocks a push that contains one; for public repositories, GitHub also alerts partner providers, who can revoke the key. GitLab offers secret detection in its pipelines. On your machine, gitleaks, TruffleHog or detect-secrets run as a pre-commit hook and stop the secret before the first commit.

These tools, like the one in the kit, work with patterns: they cover a lot of ground, and a human review remains their natural complement.

A secret has leaked: revoke, replace, check

As soon as a secret has been posted, treat it as known. Deleting the message is not enough: it may have been read, copied into a notification, cached or indexed in the meantime, and rewriting a repository's history does not reach copies already made. The useful order:

  1. Revoke the key or token with the provider, or change the password: this is what makes the posted value useless. When the provider allows two active keys, create the new one, deploy it and revoke the old one straight away; otherwise, revoke first.
  2. Replace the value everywhere the old one was used, then check that services work. The guide generate and store a secret key describes a prepared rotation that runs without downtime.
  3. Check access in the logs of the service concerned (CloudTrail for AWS, the audit log of GitHub or of the provider): they show whether the key was used between its posting and its revocation.
  4. Clean up the message, the ticket or the repository history afterwards.

Send the full version

The colleague doing the troubleshooting sometimes needs the full text: the real connection string, the token that fails. That is why the redaction tool offers two outputs: “Copy” for the redacted version meant for the ticket, and “Send with onlyU” for the complete version, passed from one tab to another in your browser, without going through a URL or the kit's server. onlyU encrypts it in your browser and creates a link that opens only once, valid for 24 hours, then disappears. It is free, with no sign-up. The ticket keeps the history of the exchange, and the secrets stay out of it.