Secret redaction is the practice of detecting passwords, API keys, tokens and other credentials in logs, traces, error messages and exports, and removing or masking them before the data is stored, shared or sent to another system. A redacted record might show Authorization: Bearer [REDACTED] where the raw record had a live token.
It addresses a quiet, common problem. Systems write down what they see and do, and what they see often includes secrets. A command line with a password in it, an error that prints a connection string, a debug dump of a request, a record of what an AI coding agent read from an environment file: all of these can place a working credential into a log. Logs are then copied to monitoring tools, shared with vendors and kept for years, usually with weaker protection than the vault the secret came from.
This page explains where secrets leak into logs and traces, why that is dangerous, a recent real-world incident, how redaction works, and how to build it into your systems.
Where secrets end up in logs
| Source | How secrets appear |
|---|---|
| Application logs | Request headers, query strings, request bodies or exception messages that include credentials. The weakness is catalogued as CWE-532: Insertion of Sensitive Information into Log File. |
| Command history and shell output | Passwords passed on the command line, or tokens printed by a tool |
| CI/CD build logs | Environment variables echoed during a build, or commands that print a key |
| Infrastructure and cloud logs | Connection strings or tokens in configuration dumps and diagnostic output |
| Database logs | Statements with literal passwords or personal data in query text. See database audit logging. |
| Error trackers and APM tools | Stack traces and captured variables that hold secrets |
| AI agent traces | A record of what an agent read and ran, which can include secrets from environment files, configuration or terminals |
| Support tickets and chat | Pasted credentials and screenshots |
The OWASP Logging Cheat Sheet lists data that should not be logged directly, including access tokens, passwords and encryption keys.
Why it is dangerous
- Logs spread widely. A secret that lives in a vault is protected. Once it is in a log, it is copied to aggregation systems, backups, dashboards and shared exports.
- Logs are read by many people. Developers, support staff and vendors may have access to logs that nobody would allow to see the original secret.
- They are kept for a long time. Retention policies meant for audit mean the credential can sit there for years.
- They are shared with third parties. Observability vendors, analytics providers and AI vendors may receive log data.
- Rotation rarely reaches them. Even after a secret is rotated, old copies may show up in an archive. If the secret was not rotated, the log keeps it alive.
- Attackers look there. Once inside, finding credentials in logs is a standard step toward lateral movement.
A recent example: agent traces at Cursor
In November 2026, Cursor published an account of a security incident that began at one of its AI vendors, Fireworks AI. According to Cursor, an attacker obtained an access key that Cursor had issued to Fireworks, and used it to copy a read-only storage bucket. The bucket held limited coding-agent traces, mostly from 2025, from sessions where users had not enabled Privacy Mode. A small number of those traces contained credentials that had not been redacted. Starting from those credentials, the attacker reached some of Cursor’s internal software-as-a-service tools, and later placed a malicious copy of the Claude Code extension on its marketplace for about 11 hours. Cursor says fewer than 0.01% of customers had API credentials exposed.
The lesson is general. A trace is a faithful record of what an agent saw, so it holds whatever secrets the agent touched. When such records are shared, the secrets go with them. We cover the full incident in A vendor’s exposed key put a fake Claude Code extension in Cursor’s marketplace.
How redaction works
Detection methods
- Pattern matching. Many credentials have recognizable formats, such as a fixed prefix and length. Cloud access keys, source control tokens and AI provider keys can be matched with regular expressions.
- Keyword and field-based rules. Fields named
password,secret,token,authorizationorapi_keyare masked regardless of value. - Entropy analysis. Long, random-looking strings are more likely to be secrets than ordinary text. This catches unknown formats and also produces false positives.
- Verification. Some tools test whether a detected secret actually works, which reduces noise. Do this carefully, so the check does not itself create risk.
- Structured logging with a deny list. If logs are structured (for example JSON), sensitive fields can be dropped by name before output.
What to do with a match
| Action | Result | Use when |
|---|---|---|
| Drop the field | The value is not recorded | You never need it |
Mask (****) | Shows that something was there | Debugging needs to know a value existed |
| Partially mask (last four characters) | Helps matching and support | Identifiers such as card numbers |
| Hash or tokenize | Allows correlation without exposing the value | You need to join records on the value |
| Block and alert | Stops the data from leaving | The destination is untrusted |
Redaction should be irreversible in the stored record. Keeping the original somewhere “just in case” defeats the purpose.
Where to apply redaction
Put it as close to the source as you can, and add layers.
- At the source. Fix the code that logs secrets. Use logging libraries with built-in filters, and do not log whole request objects.
- At collection. Add redaction rules in the log shipper or agent, so data is cleaned before it leaves the host.
- At the pipeline. Apply rules in the central log pipeline or telemetry processor.
- At export and sharing. Scan anything you send to a vendor, ticket or partner.
- At rest. Periodically scan stored logs and archives for secrets that got through.
A layered approach matters because no single rule catches everything.
Practical steps
Step 1: Find what you already have
Scan existing logs, traces and exports for secrets. Open-source tools can scan files and directories, not only repositories:
# Scan a directory of exported logs without git history
gitleaks detect --no-git --source ./exported-logs --report-path leaks.json
# Scan files and keep only secrets that actually authenticate
trufflehog filesystem ./exported-logs --only-verified
Treat every hit as a live credential until proven otherwise, and rotate it. See secret rotation.
Step 2: Fix the sources
Search your code for places that log entire objects, headers or request bodies. A quick starting point:
# Look for logging calls that might include credentials
grep -rnE "log(ger)?\.(info|debug|error|warn).*(password|secret|token|authorization|api[_-]?key)" src/
Replace them with logging that omits or masks the sensitive fields. Run static analysis that flags this weakness. See static source code analysis.
Step 3: Add redaction in the pipeline
Most log and telemetry pipelines support processing rules. A generic example of the idea, written as pseudo-configuration:
# Illustrative only: syntax differs by tool
processors:
- name: redact-secrets
match_fields: ["password", "secret", "token", "authorization", "api_key"]
action: mask
- name: redact-patterns
patterns:
- "AKIA[0-9A-Z]{16}" # AWS access key ID format
- "sk-[A-Za-z0-9]{20,}" # common AI provider key prefix
- "ghp_[A-Za-z0-9]{36}" # GitHub personal access token format
action: replace
replacement: "[REDACTED]"
Check the real syntax for your tool, and test the rules against sample data. Pattern lists need maintenance as formats change.
Step 4: Protect what you share with third parties
Before logs, traces or datasets leave your environment, scan and redact them. Apply the same standard to vendors that train models or analyze data on your behalf. Ask each vendor how they redact secrets, how long they keep data, what keys they hold for your storage, and how quickly they will tell you about exposure. See third-party risk management and our vendor security questions.
Step 5: Limit who can read logs and how long they live
Treat logs as sensitive data. Restrict access, keep retention to what policy requires, and store them away from the systems they describe. See database audit logging for protecting audit records.
Step 6: Make secrets worth less when they leak
Redaction reduces leaks, and it will never be perfect. Limit the damage of the ones that get through:
- Prefer short-lived credentials that expire in minutes or hours, so a secret found in an old log no longer works.
- Scope credentials narrowly. See least privilege.
- Remove standing access. See zero standing privilege.
- Restrict where credentials can be used from.
AI agents and redaction
AI coding agents create a new source of exposed secrets. They read files, run commands and inspect environments as part of their work, and their sessions are often recorded for debugging or model improvement. Three practices help:
- Do not give agents long-lived secrets. Provide a credential created for the task that disappears afterward. See AI agent guardrails.
- Block secrets before they leave the machine. Inspect commands, files and outbound data on the developer’s host. See what is a coding agent firewall and data loss prevention for AI coding agents.
- Enable privacy modes and retention limits in the tools your developers use, and check what is recorded.
How Cloudanix helps
Cloudanix works at both ends: stopping secrets from entering logs and repositories, and reducing the value of the ones that leak.
- Catching secrets early. Code Security scans pull requests and full git history for hardcoded credentials and can fail a pull request that introduces one. See secret-aware PR quality gates and the secrets detection use case.
- Stopping them at the developer’s machine. The Coding Agent Firewall adds on-host data loss prevention, so secrets and personal data are blocked before an AI agent sends them out, including secrets an agent writes into commands and files.
- Credentials that expire. Coding Agent JIT uses an MCP server to create, scope and destroy credentials for agents such as Claude Code, Cursor and Kiro, with a human in the loop for sensitive requests. Agentic JIT does the same for pipelines and services. A credential that has already expired is worth little in an old trace.
- Knowing which identities exist. Non-human identity visibility and CIEM list keys and service accounts across your clouds and what each can reach, so you know what to rotate after a leak.
The boundary: Cloudanix does not redact the logs of your applications or observability tools. That redaction belongs in your logging libraries and pipelines. It cannot recover a secret that has already been shared with a vendor, which needs to be rotated.
Further reading
- CWE-532: Insertion of Sensitive Information into Log File
- OWASP Logging Cheat Sheet
- OWASP Secrets Management Cheat Sheet
- Cursor: An update on our recent security incident
Frequently asked questions
What is secret redaction?
It is detecting and removing or masking passwords, keys and tokens in logs, traces and exports before they are stored or shared.
Why do secrets end up in logs?
Systems record what they process. Command lines, request headers, error messages, debug dumps and AI agent sessions can all contain credentials, and logging code often records them without anyone intending it.
Is masking enough, or should I remove the value?
If you never need the value, drop it. Masking is useful when debugging needs to know a value was present. Either way, the stored record should not allow recovery of the original.
What should I do if I find a secret in a log?
Treat it as compromised. Rotate it, review access logs for its use from the earliest plausible date, remove it from the log and its copies, and fix the code or pipeline that put it there.
How do AI agent traces change the picture?
Traces record what an agent read and did, so they include secrets from files and terminals the agent touched. Sharing traces with a vendor shares those secrets, as the Cursor incident showed. Redact before sharing, and give agents short-lived credentials.