Skip to content

fix: redact private keys from logged command errors#4602

Open
weibeu wants to merge 1 commit into
Dokploy:canaryfrom
weibeu:fix/redact-secrets-in-logs
Open

fix: redact private keys from logged command errors#4602
weibeu wants to merge 1 commit into
Dokploy:canaryfrom
weibeu:fix/redact-secrets-in-logs

Conversation

@weibeu

@weibeu weibeu commented Jun 9, 2026

Copy link
Copy Markdown

What is this PR about?

Private keys can end up in the logs. When Dokploy clones a repository over SSH it writes the SSH key to /tmp/id_rsa via echo "<key>", and when it provisions a TLS certificate on a remote server it pipes the base64 key to base64 -d — both inside shell command strings. On failure the resulting ExecError carries the full command (plus stdout/stderr and the wrapped original error) and is logged via console.log(error), so the key lands in docker service logs in plain text and propagates to any forwarded log store.

This redacts private-key material at the single point every log path funnels through — ExecError. A small redactSecrets helper strips PEM private-key blocks and echo "<base64>" | base64 -d payloads from the command, stdout, stderr, message and any wrapped original error, so no caller or console.log(error) sink can leak them.

Reading these logs already requires host/root access, so this is a secret-hygiene / defense-in-depth fix (CWE-532), not a remotely exploitable issue. It follows the same direction as #4579, which kept the registry password out of the login command.

Affected sources for reference: utils/providers/git.ts (SSH key) and services/certificate.ts (TLS key); the redaction lives in utils/process/ExecError.ts so it also covers any future secret-bearing command.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. Added a vitest unit test (__test__/process/redact-secrets.test.ts) and verified the redaction against real command output captured from docker service logs. The change is confined to log-string redaction and does not alter any deploy path.

Issues related (if applicable)

closes #4600

@weibeu weibeu requested a review from Siumauricio as a code owner June 9, 2026 13:14
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84f21b183f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +21 to +22
const candidate = error as T & { cmd?: string };
candidate.message = redactSecrets(candidate.message);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Redact exec error output properties

When a local execAsync command fails after writing a secret to stdout or stderr, the promisified child_process.exec error passed as originalError carries enumerable stdout and stderr properties. ExecError now redacts its own top-level output fields, but console.log(new ExecError(...)) will still print originalError.stdout/stderr, so a failed command that emits a PEM or base64 key before exiting can still leak the same secret this change is trying to remove.

Useful? React with 👍 / 👎.

SSH keys (SSH clone) and base64-encoded TLS keys (remote certificate
provisioning) are interpolated into the shell commands Dokploy runs.
When a command fails, its ExecError — which carries the full command —
is logged, leaking the key to the service logs in plain text.

Redact PEM private-key blocks and `echo "<base64>" | base64 -d` payloads
on ExecError (command, stdout, stderr, message and any wrapped original
error) so no log path can surface them.
@weibeu weibeu force-pushed the fix/redact-secrets-in-logs branch from 84f21b1 to ff457b4 Compare June 9, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secrets (SSH deploy key, TLS certificate private key) interpolated into shell commands and logged unredacted (CWE-532)

1 participant