<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Doruk</title>
    <description>The latest articles on DEV Community by Doruk (@dorywoof).</description>
    <link>https://dev.to/dorywoof</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4255428%2F8b9686c4-4fb7-4576-ba01-6f9c96ef1cae.jpg</url>
      <title>DEV Community: Doruk</title>
      <link>https://dev.to/dorywoof</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dorywoof"/>
    <language>en</language>
    <item>
      <title>Scrubbing secrets from AI agent logs is harder than it looks</title>
      <dc:creator>Doruk</dc:creator>
      <pubDate>Fri, 20 Nov 2026 10:07:05 +0000</pubDate>
      <link>https://dev.to/dorywoof/scrubbing-secrets-from-ai-agent-logs-is-harder-than-it-looks-1e62</link>
      <guid>https://dev.to/dorywoof/scrubbing-secrets-from-ai-agent-logs-is-harder-than-it-looks-1e62</guid>
      <description>&lt;p&gt;AI coding agents write everything down. Claude Code, Codex, Gemini CLI and friends keep a full log of every session: your prompts, the agent's reasoning, every command it ran and every byte of output it read.&lt;/p&gt;

&lt;p&gt;That log is great for showing people what an agent did. It is also full of secrets. The agent ran cat .env. It printed a config. It made a request with your token in a header, then dumped the response with xxd to debug it.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://github.com/dorywoof/agentreplayer" rel="noopener noreferrer"&gt;agentreplayer&lt;/a&gt;, a CLI that turns those logs into a replay page you can share. So I needed redaction that actually works before anything leaves the machine. Here is what I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 1: known formats
&lt;/h2&gt;

&lt;p&gt;The easy part. Many tokens have recognizable shapes. GitHub tokens start with ghp_, AWS keys with AKIA, JWTs with eyJ and have three dot-separated parts, and so on. Add env-style assignments like DATABASE_PASSWORD=... and you have what most secret scrubbers do.&lt;/p&gt;

&lt;p&gt;It is not enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 2: the secret comes back without its label
&lt;/h2&gt;

&lt;p&gt;The agent reads .env and sees API_KEY=abc123... The pattern catches that. Ten minutes later the agent runs a script, and the key shows up bare in an error message. No API_KEY= in front, nothing for a pattern to grab.&lt;/p&gt;

&lt;p&gt;The fix is two passes. Pass one walks the whole session and collects every secret value any pattern found. Pass two scrubs those exact values everywhere they appear, labeled or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 3: base64 has three faces
&lt;/h2&gt;

&lt;p&gt;Now the secret is inside an Authorization: Basic header. That is base64 of user:secret. Easy, right? Just search for the base64 of the secret.&lt;/p&gt;

&lt;p&gt;It doesn't match. base64 works on 3-byte blocks, and each block turns into 4 characters. If the secret starts at the first byte of a block, you get one encoding. If it starts at the second or third byte, because user: came before it, the characters are completely different. &lt;strong&gt;The same secret has three different base64 forms depending on where it starts.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So for each of the three positions, I encode the secret with 0, 1 or 2 filler bytes in front, then keep only the middle part: the characters the secret alone decides. If any of those three fragments shows up inside a base64 run, the whole run goes. The URL-safe variant (- and _ instead of + and /) is checked too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 4: hex, and the hexdump problem
&lt;/h2&gt;

&lt;p&gt;A reader asked me on X whether this also catches hex, like a secret inside a hexdump of a request body. It didn't. Now it does.&lt;/p&gt;

&lt;p&gt;Plain hex is the easy case: one byte is always two characters, so there is no alignment problem. Search for the lowercase and uppercase hex of the secret and you're done.&lt;/p&gt;

&lt;p&gt;But real hex in agent logs usually comes from a tool like xxd. Each line starts with an offset, then the bytes in groups, then an ASCII column on the right. A 20-character secret easily ends up split across two lines, with spaces, a line break, the ASCII column and the next offset in the middle of it. A plain search finds nothing.&lt;/p&gt;

&lt;p&gt;So the matcher builds a pattern from the secret's bytes and allows a "gap" between any two of them: nothing, a space or comma, a \x or 0x prefix, or a line break with the dump's ASCII column before it and the next offset after it. Logs are often stored as JSON, so the line break can also be a literal backslash-n. That covers xxd, xxd -p, hexdump -C, escaped strings like \x5a\x71 and C arrays like { 0x5a, 0x71 }.&lt;/p&gt;

&lt;p&gt;Two lessons from writing it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Don't require word boundaries.&lt;/strong&gt; I started with "no hex digit right before or after the match". But xxd -p prints one long hex run, and the secret sits in the middle of it, so that check blocked every match.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch your optional escapes.&lt;/strong&gt; To match an escaped Windows line ending, I wrote "backslash, r, question mark, backslash, n". But the question mark only makes the r optional, not the backslash in front of it. So a plain escaped newline never matched. The test for JSON-escaped dumps caught it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it still doesn't catch
&lt;/h2&gt;

&lt;p&gt;I would rather say this plainly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A secret that &lt;strong&gt;only ever&lt;/strong&gt; appears encoded, and never in plain text anywhere in the session, isn't learned in pass one, so its encoded forms aren't searched for.&lt;/li&gt;
&lt;li&gt;In a hexdump, the ASCII column on the right can still show readable fragments of a secret that was split across lines. The hex side is removed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you know an encoding agents produce that slips through this, I'd love to hear it. That's how the hex support happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;Everything runs locally. Nothing is uploaded. Run npx agentreplayer and it replays your latest Claude Code, Codex, Gemini CLI, OpenCode, Cline or Aider session as one self-contained HTML file. The footer tells you what was redacted.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/dorywoof/agentreplayer" rel="noopener noreferrer"&gt;github.com/dorywoof/agentreplayer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>opensource</category>
      <category>claude</category>
    </item>
  </channel>
</rss>
