<?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: OLI</title>
    <description>The latest articles on DEV Community by OLI (@olicastle).</description>
    <link>https://dev.to/olicastle</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%2F4039754%2Fb8020dc9-2c2e-474c-ba49-999d78ead895.png</url>
      <title>DEV Community: OLI</title>
      <link>https://dev.to/olicastle</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/olicastle"/>
    <language>en</language>
    <item>
      <title>Your AI Coding Agent Is Reading Your .env Right Now</title>
      <dc:creator>OLI</dc:creator>
      <pubDate>Tue, 21 Jul 2026 10:33:04 +0000</pubDate>
      <link>https://dev.to/olicastle/your-ai-coding-agent-is-reading-your-env-right-now-3909</link>
      <guid>https://dev.to/olicastle/your-ai-coding-agent-is-reading-your-env-right-now-3909</guid>
      <description>&lt;h1&gt;
  
  
  Your AI Coding Agent Is Reading Your .env Right Now
&lt;/h1&gt;

&lt;p&gt;You opened Claude Code in your project directory this morning. Or Cursor. Or you let&lt;br&gt;
Copilot index the workspace. The agent did what agents do: it read the files to build&lt;br&gt;
context.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;.env&lt;/code&gt; was one of them.&lt;/p&gt;

&lt;p&gt;Nobody typed a command to make that happen. There was no prompt, no confirmation&lt;br&gt;
dialog, no line in a changelog. It's simply how these tools work — and it's the reason&lt;br&gt;
a threat model that didn't exist three years ago now applies to almost every developer&lt;br&gt;
machine.&lt;/p&gt;
&lt;h2&gt;
  
  
  The old threat model was about publishing
&lt;/h2&gt;

&lt;p&gt;We built good habits around secret leakage. &lt;code&gt;.env&lt;/code&gt; goes in &lt;code&gt;.gitignore&lt;/code&gt;. Don't paste&lt;br&gt;
keys in Slack. Rotate anything that touches a public repo. GitHub reported&lt;br&gt;
&lt;a href="https://github.blog/security/application-security/next-evolution-github-advanced-security/" rel="noopener noreferrer"&gt;over 39 million secrets leaked across the platform in 2024&lt;/a&gt;,&lt;br&gt;
and the tooling&lt;br&gt;
grew up in response: push protection, secret scanning, pre-commit hooks.&lt;/p&gt;

&lt;p&gt;Every one of those defences guards the same door: &lt;strong&gt;the moment a secret leaves your&lt;br&gt;
machine because you published something.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And they aren't keeping up. GitGuardian's&lt;br&gt;
&lt;a href="https://blog.gitguardian.com/the-state-of-secrets-sprawl-2026/" rel="noopener noreferrer"&gt;State of Secrets Sprawl 2026&lt;/a&gt;&lt;br&gt;
counted 28.65 million new hardcoded secrets in public GitHub commits during 2025 — a 34%&lt;br&gt;
jump, the largest single-year increase they've recorded. Worse, 64% of the credentials&lt;br&gt;
they confirmed valid back in 2022 were &lt;em&gt;still&lt;/em&gt; valid in January 2026. Four years in&lt;br&gt;
public code, never rotated.&lt;/p&gt;

&lt;p&gt;An AI agent doesn't use that door. It reads the file in place, on your disk, with your&lt;br&gt;
permissions, and moves the contents into a context window that may live on someone&lt;br&gt;
else's infrastructure. From there the key can surface in a log line, a chat transcript,&lt;br&gt;
a shared session, or a support ticket. &lt;code&gt;.gitignore&lt;/code&gt; has no opinion on any of that.&lt;/p&gt;

&lt;p&gt;The same report puts numbers on this: 24,008 secrets were exposed in MCP configuration&lt;br&gt;
files on public GitHub in 2025 — a leak surface that didn't exist two years ago. And&lt;br&gt;
roughly 28% of all incidents now originate in collaboration and productivity tools&lt;br&gt;
rather than repositories, where credentials sit exposed to automations and AI agents.&lt;/p&gt;
&lt;h2&gt;
  
  
  Computer-use agents make it worse
&lt;/h2&gt;

&lt;p&gt;A coding agent reads files. A computer-use agent — Claude's computer use, OpenAI's&lt;br&gt;
Operator, any assistant that drives a desktop — takes &lt;strong&gt;continuous screenshots&lt;/strong&gt; and&lt;br&gt;
ships them to a provider.&lt;/p&gt;

&lt;p&gt;Now the attack surface isn't your &lt;code&gt;.env&lt;/code&gt;. It's everything currently visible: the key in&lt;br&gt;
your open editor tab, the &lt;code&gt;export&lt;/code&gt; line still sitting in your terminal scrollback, the&lt;br&gt;
provider dashboard you left open in a browser tab with the key revealed.&lt;/p&gt;

&lt;p&gt;You can't &lt;code&gt;.gitignore&lt;/code&gt; a screenshot.&lt;/p&gt;
&lt;h2&gt;
  
  
  What actually helps: stop putting the value in the file
&lt;/h2&gt;

&lt;p&gt;The fix isn't a better ignore rule. It's removing the plaintext secret from the place&lt;br&gt;
the agent looks.&lt;/p&gt;

&lt;p&gt;The pattern is not new — Doppler (&lt;code&gt;doppler run&lt;/code&gt;), Infisical (&lt;code&gt;infisical run&lt;/code&gt;) and&lt;br&gt;
1Password (&lt;code&gt;op run&lt;/code&gt;) all do a version of it. Your config file holds a &lt;strong&gt;reference&lt;/strong&gt;, and&lt;br&gt;
the real value is injected into the process environment at launch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# before — the secret is the file
ELEVENLABS_API_KEY=sk_a1b2c3d4e5f6g7h8i9j0

# after — the file holds a pointer, not a secret
ELEVENLABS_API_KEY=apidrop://elevenlabs-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apidrop run &lt;span class="nt"&gt;--&lt;/span&gt; python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your code still reads &lt;code&gt;os.environ["ELEVENLABS_API_KEY"]&lt;/code&gt;. It never learns the reference&lt;br&gt;
existed. But an agent reading the file finds a harmless string — one you could screenshot,&lt;br&gt;
commit, or stream on Twitch without consequence.&lt;/p&gt;

&lt;p&gt;This applies to anything in a &lt;code&gt;.env&lt;/code&gt;, not just API keys. Database URLs with embedded&lt;br&gt;
passwords, SMTP credentials, webhook URLs, JWT signing secrets, bot tokens.&lt;/p&gt;
&lt;h2&gt;
  
  
  Testing it against an agent
&lt;/h2&gt;

&lt;p&gt;Claims like this deserve evidence, so here's the setup: a fresh clone, a vault holding a&lt;br&gt;
recognisable test key (&lt;code&gt;sk-REALSECRET-abc123xyz789&lt;/code&gt;), and a &lt;code&gt;.env&lt;/code&gt; containing only a&lt;br&gt;
reference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent reads project files:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; .env
&lt;span class="c"&gt;# → ELEVENLABS_API_KEY=apidrop://elevenlabs-1&lt;/span&gt;

&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"sk-REALSECRET"&lt;/span&gt; ./project ~/.apidrop
&lt;span class="c"&gt;# → no match in plaintext anywhere outside the encrypted vault&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The agent runs the code the normal way:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ELEVENLABS_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;# → None
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without the resolver, the reference is never resolved. The variable is simply empty.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent tries the resolver without the master password:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apidrop run &lt;span class="nt"&gt;--&lt;/span&gt; python3 agent_script.py
&lt;span class="c"&gt;# → wrong master password or corrupted file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The agent has the master password:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APIDROP_PASSPHRASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"testpass123"&lt;/span&gt; apidrop run &lt;span class="nt"&gt;--&lt;/span&gt; python3 agent_script.py
&lt;span class="c"&gt;# → sk-REALSECRET-abc123xyz789&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last one is not a bug, and pretending otherwise would be dishonest. A program has&lt;br&gt;
to receive the key at runtime or it can't call the API. If you hand something the&lt;br&gt;
password, you've granted access on purpose.&lt;/p&gt;

&lt;p&gt;Which is exactly the point: &lt;strong&gt;the pattern separates read access from secret access.&lt;/strong&gt; An&lt;br&gt;
agent can review your entire repository, explain your architecture, refactor your&lt;br&gt;
modules — without that access implicitly including your credentials. Those used to be&lt;br&gt;
the same permission. They no longer have to be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this doesn't apply
&lt;/h2&gt;

&lt;p&gt;Worth being clear about the boundary, because it's easy to oversell.&lt;/p&gt;

&lt;p&gt;This is a &lt;strong&gt;local developer machine&lt;/strong&gt; technique. It works because a human is present to&lt;br&gt;
type a master password. On a deployed server nobody is, and setting the passphrase as an&lt;br&gt;
environment variable there just trades one secret for another — a worse one, since a&lt;br&gt;
single value now unlocks everything. For deployed workloads, use your platform's secret&lt;br&gt;
management: Vercel environment variables, Docker secrets, AWS Secrets Manager, whatever&lt;br&gt;
your host provides.&lt;/p&gt;

&lt;p&gt;It's also not a sandbox. It doesn't constrain what an agent can do once authorised. It&lt;br&gt;
closes the accidental path, not the deliberate one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The practical takeaway
&lt;/h2&gt;

&lt;p&gt;You don't need a specific tool to act on this. The question worth asking today is&lt;br&gt;
simply: &lt;em&gt;if an agent read every file in my project right now, what would it learn that I&lt;br&gt;
wouldn't put in a public gist?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If the answer includes a working credential, the fix is the same regardless of which&lt;br&gt;
tool you pick — get the value out of the file and inject it at runtime.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://github.com/Letaiwork4u/api-drop" rel="noopener noreferrer"&gt;API Drop&lt;/a&gt; because I wanted that&lt;br&gt;
locally: no cloud, no account, no subscription, encrypted vault on my own disk&lt;br&gt;
(PBKDF2-HMAC-SHA256 at 390,000 iterations, Fernet/AES), injection via a child process&lt;br&gt;
rather than a system hook. It's MIT-licensed and runs on Windows, macOS and Linux.&lt;/p&gt;

&lt;p&gt;But the pattern matters more than the implementation. Doppler and Infisical do this well&lt;br&gt;
if you want team sync and don't mind a cloud account. Use whichever fits — just stop&lt;br&gt;
leaving the plaintext where your tools can read it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Found a hole in the reasoning? I'd genuinely like to hear it — the threat model here is&lt;br&gt;
new enough that it deserves scrutiny.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
