<?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: affan</title>
    <description>The latest articles on DEV Community by affan (@affansaas).</description>
    <link>https://dev.to/affansaas</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3821155%2Fad1315d3-be0d-4461-b765-7d63851caca6.png</url>
      <title>DEV Community: affan</title>
      <link>https://dev.to/affansaas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/affansaas"/>
    <language>en</language>
    <item>
      <title>Why .env Files Are Not Enough to Secure Your API Keys</title>
      <dc:creator>affan</dc:creator>
      <pubDate>Mon, 27 Apr 2026 19:26:34 +0000</pubDate>
      <link>https://dev.to/affansaas/why-env-files-are-not-enough-to-secure-your-api-keys-54k9</link>
      <guid>https://dev.to/affansaas/why-env-files-are-not-enough-to-secure-your-api-keys-54k9</guid>
      <description>&lt;p&gt;Every developer knows the drill.&lt;/p&gt;

&lt;p&gt;Create a .env file. Add your keys. Add .env to .gitignore. Done, you're secure.&lt;/p&gt;

&lt;p&gt;Except you're not. Not really.&lt;br&gt;
.env files are a good first step but they're nowhere near enough on their own. And the false sense of security they create is actually part of the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What .env Files Actually Do
&lt;/h2&gt;

&lt;p&gt;A .env file is just a plain text file that stores key value pairs. When your app starts up it reads those values and makes them available as environment variables in your code.&lt;/p&gt;

&lt;p&gt;That's it. There's no encryption. No access control. No audit trail. No expiry. It's a text file sitting on your filesystem.&lt;br&gt;
The only protection a .env file gives you is keeping your keys out of your source code. That's valuable. But it's one layer of protection in a world where you need several.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Ways .env Files Fail You&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Someone accidentally commits it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the most common one. You're moving fast, you do a git add . and suddenly your .env file is in version control. Even if you catch it and remove it in the next commit, the key is now in your git history forever. Anyone who clones the repo has it.&lt;/p&gt;

&lt;p&gt;GitHub has bots scanning for this constantly. Your key can be grabbed within seconds of being pushed to a public repo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your machine gets compromised&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If someone gets access to your laptop, your VM, or your development server, every .env file on that machine is immediately readable. Plain text, no encryption, no password required.&lt;/p&gt;

&lt;p&gt;One phishing attack, one malicious npm package, one insecure public wifi session. That's all it takes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sharing keys across a team becomes a mess&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How do you share .env files with teammates? Most developers end up sending them over Slack, email, or storing them in a shared Notion doc. Now your keys are living in places that were never designed to store secrets.&lt;br&gt;
Every person you share the file with is a new potential exposure point. And when someone leaves the team, do you actually rotate every key they had access to? Almost nobody does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No visibility into who has what&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With .env files scattered across developer machines, staging servers, and CI environments, you have no central view of where your keys live. You can't see who has access. You can't audit usage. You can't tell if a key has been leaked until something breaks or you get an unexpected bill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keys live forever&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;.env files never remind you to rotate keys. Most developers set up their .env once and never touch it again. That key might be years old with no record of when it was created or who has seen it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Developers Do That Makes It Worse
&lt;/h2&gt;

&lt;p&gt;Using the same key in development and production is extremely common. It feels convenient until your dev environment gets compromised and takes down production with it.&lt;/p&gt;

&lt;p&gt;Keeping a master .env file in a shared folder or cloud storage so the team can access it. Dropbox, Google Drive, iCloud. None of these are built for secrets management and all of them have had breaches.&lt;/p&gt;

&lt;p&gt;Hardcoding keys directly when .env feels like too much friction. Especially in scripts, quick tools, and one-off projects that end up running in production forever.&lt;/p&gt;

&lt;p&gt;Not having any process for what to do when a key gets exposed. So when it happens you're scrambling, trying to remember where every key is used while the clock is ticking.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Actually Need
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Encryption at rest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your keys should be encrypted when stored, not sitting in plain text. If someone gets access to the storage, they should see encrypted data that's useless without the decryption key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should be able to control exactly who can see which keys. New developer joins the team? You grant them access to only what they need. Someone leaves? You revoke their access immediately without having to rotate every key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audit trail&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should know when a key was created, when it was last accessed, and by whom. This visibility is what lets you respond quickly when something goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One central place&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every key your team uses should live in one organized place. Not scattered across machines, Slack messages, and Notion docs. Centralized storage means you can actually manage your keys instead of just hoping nothing goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key rotation reminders&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should be reminded to rotate keys regularly, not just when you remember or when something breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Right Way to Think About .env Files
&lt;/h2&gt;

&lt;p&gt;Don't stop using .env files. They're still useful for local development. But treat them as a convenience layer, not a security solution.&lt;br&gt;
Your actual security comes from what's behind the .env file. Where did those values come from? Who has access to them? How are they shared and managed?&lt;/p&gt;

&lt;p&gt;.env is the last mile, not the whole journey.&lt;br&gt;
A proper secrets manager handles the storage, encryption, access control, and sharing. Your .env file just pulls the values from there into your local environment.&lt;/p&gt;

&lt;p&gt;This is exactly the problem I kept running into across multiple projects, keys scattered everywhere with no real control over who had access to what. That's why I built Keydock, a zero knowledge API key manager that encrypts your keys client side before they ever hit a server.&lt;br&gt;
You get one organized secure place for all your keys, with access control and the ability to share with teammates without ever exposing the raw values.&lt;/p&gt;

&lt;p&gt;Try it free at keydock.cloud&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>devtools</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why Developers Are Bad at Securing Their Own API Keys</title>
      <dc:creator>affan</dc:creator>
      <pubDate>Sun, 15 Mar 2026 17:06:13 +0000</pubDate>
      <link>https://dev.to/affansaas/why-developers-are-bad-at-securing-their-own-api-keys-3bim</link>
      <guid>https://dev.to/affansaas/why-developers-are-bad-at-securing-their-own-api-keys-3bim</guid>
      <description>&lt;p&gt;We spend hours making our apps secure for users.&lt;/p&gt;

&lt;p&gt;HTTPS everywhere. Encrypted databases. Two factor auth. Rate limiting.&lt;/p&gt;

&lt;p&gt;Then we store our own API keys in a Notion doc shared with the whole team.&lt;/p&gt;

&lt;p&gt;The irony is real and it costs developers and companies thousands of dollars every year in breaches, leaked infrastructure, and unauthorized charges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Happens
&lt;/h2&gt;

&lt;p&gt;When you're building fast, security shortcuts feel harmless. You tell yourself:&lt;/p&gt;

&lt;p&gt;"I'll fix this later"&lt;/p&gt;

&lt;p&gt;"It's just a dev key"&lt;/p&gt;

&lt;p&gt;"Nobody will find this Notion link"&lt;br&gt;
But later never comes. And dev keys often have the same permissions as &lt;br&gt;
prod keys. That's the real problem.&lt;br&gt;
The truth is most developers treat API keys as an afterthought. You're focused on shipping features, fixing bugs, hitting deadlines. Security feels like a separate concern you'll deal with eventually. But API keys are not an eventually problem. They're a right now problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Cost of a Leaked API Key
&lt;/h2&gt;

&lt;p&gt;Before we get into mistakes, let's talk about what actually happens when a key gets exposed.&lt;/p&gt;

&lt;p&gt;AWS keys found by bots on GitHub have resulted in bills of $50,000 or more within hours. These bots are automated and run 24/7 scanning every public commit for patterns that look like API keys.&lt;/p&gt;

&lt;p&gt;Stripe keys can be used to issue fraudulent refunds or pull customer data. OpenAI keys get used to run expensive prompts at your expense. Twilio keys get used to send spam at scale billed to your account.&lt;/p&gt;

&lt;p&gt;The damage is not just financial. If customer data is accessed through an exposed key you're looking at potential GDPR violations, angry users, and &lt;br&gt;
reputation damage that's hard to recover from.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Most Common Mistakes Developers Make
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;API keys in .env files committed to GitHub&lt;br&gt;
This is the single most common mistake. You set up your project, create a .env file, add your keys, and forget to add .env to your .gitignore. One push and it's public. Even if you delete the file in the next commit, the key is still in your git history forever.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keys shared over Slack and never rotated&lt;br&gt;
Your teammate needs the Stripe key. You paste it in Slack. Now that key lives in your Slack history accessible to anyone in that channel, any admin, and any third party app connected to your Slack workspace. And it never gets rotated so it stays exposed indefinitely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Same key used across dev and production&lt;br&gt;
This one feels convenient until it isn't. If your dev environment gets breached, your production app is compromised too. Always use separate keys for each environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No record of which keys exist or where they are&lt;br&gt;
Ask yourself right now: how many API keys does your project use? Where is each one stored? When was each one last rotated? Most developers can't answer these questions and that's a serious risk.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keys never rotated after a team member leaves&lt;br&gt;
When someone leaves your team they take their memory of where keys are stored. If they still have access to those keys anywhere, you have a security gap until you rotate everything.&lt;br&gt;
What Actually Helps&lt;br&gt;
Start treating your API keys like passwords. You would never store passwords in a Notion doc. You would never share passwords over Slack. You would never use the same password everywhere.&lt;br&gt;
Same rules apply to API keys.&lt;br&gt;
Use environment variables everywhere. No keys in code, no keys in config files that get committed. Every key lives in environment variables set at the deployment level.&lt;br&gt;
Add .env to .gitignore before you write a single key. Do this first thing when you set up a project, not after.&lt;br&gt;
Create separate keys for dev, staging, and production. Every environment should have its own set of keys with only the permissions that environment &lt;br&gt;
actually needs.&lt;br&gt;
Keep all your keys in one organized secure place. This is the part most developers skip and it's the most important habit to build. When you know exactly where every key lives you can rotate them quickly, audit access, and respond fast if something gets exposed.&lt;br&gt;
Rotate keys regularly and immediately after any team changes. Treat key rotation like changing passwords. Do it on a schedule and always do it when someone leaves.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I got tired of managing keys across scattered places so I built Keydock, a simple secure vault for all your API keys with zero knowledge encryption so even the server can't read your keys.&lt;br&gt;
Try it free at keydock.cloud&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>devtools</category>
      <category>programming</category>
    </item>
    <item>
      <title>API Key Security Best Practices Every Developer Should Know.</title>
      <dc:creator>affan</dc:creator>
      <pubDate>Thu, 12 Mar 2026 23:09:55 +0000</pubDate>
      <link>https://dev.to/affansaas/api-key-security-best-practices-every-developer-should-know-5262</link>
      <guid>https://dev.to/affansaas/api-key-security-best-practices-every-developer-should-know-5262</guid>
      <description>&lt;p&gt;You probably have API keys scattered everywhere right now.&lt;br&gt;
.env files. Notion docs. Slack messages. Maybe even a sticky note &lt;br&gt;
somewhere.&lt;/p&gt;

&lt;p&gt;And honestly most developers do. It happens gradually. One project becomes two becomes ten and suddenly you have OpenAI keys, Stripe keys, AWS keys, Twilio keys, and GitHub tokens living in six different places with no clear ownership or rotation schedule.&lt;/p&gt;

&lt;h2&gt;
  
  
  One mistake can expose your entire app to the world. Here's what you should actually be doing and why each practice matters.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Never Commit API Keys to GitHub&lt;br&gt;
This is the most common mistake and the one with the fastest consequences.&lt;br&gt;
GitHub has automated bots that scan every public commit for patterns that look like API keys. They run 24/7. By the time you notice you pushed a key, someone has already grabbed it. AWS keys have led to bills of $50,000 or more within a single day this way.&lt;br&gt;
How to fix it: Add .env to your .gitignore before you create it. Not after, before. Make this the first thing you do when setting up any project. Also consider using a tool like git-secrets that blocks commits containing credential patterns.&lt;br&gt;
Even if you're working on a private repo, get into this habit. Private repos can become public, get forked, or have their access compromised.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Never Hardcode Keys in Your Codebase&lt;br&gt;
This one seems obvious but happens constantly, especially when you're moving fast and just want to test something quickly.&lt;br&gt;
The problem is hardcoded keys end up in version history forever even after you delete them. Anyone with access to your repo can run git log and find the key. Anyone who ever cloned the repo has it locally.&lt;br&gt;
How to fix it: Always use environment variables. Every language and framework has a way to read from environment variables. There is no situation where hardcoding a key is the right move.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Separate Dev and Production Keys&lt;br&gt;
Your development keys and production keys should never be the same string.&lt;br&gt;
If your dev environment gets compromised, maybe through a dependency vulnerability or a misconfigured server, your production app stays completely safe if you're using separate keys. If they're the same key, one breach means everything is exposed.&lt;br&gt;
How to fix it: Create separate API keys for each environment in every service you use. Most services let you create multiple keys with different permission levels. Take 5 minutes to set this up properly from the start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the Principle of Least Privilege&lt;br&gt;
Every API key should only have the permissions it actually needs. Nothing more.&lt;br&gt;
If your key only needs read access to a service, don't create it with write access too. If your key only needs to access one specific resource, don't give it access to everything.&lt;br&gt;
This limits the blast radius if a key gets exposed. An attacker with a read-only key can see data but can't delete it, write to it, or escalate their access.&lt;br&gt;
How to fix it: When creating API keys, go through the permission settings carefully. It takes an extra few minutes but dramatically reduces your risk exposure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rotate Your Keys Regularly&lt;br&gt;
Keys are like passwords. The longer they stay unchanged the more risk you carry, even if you've never had a breach.&lt;br&gt;
You don't know who has seen your key over time. Old team members, contractors, third party tools, services you integrated and then stopped using. Regular rotation cleans all of that up.&lt;br&gt;
How to fix it: Rotate keys every 90 days as a baseline. Rotate immediately after any of these events: an employee or contractor leaves, a key gets accidentally exposed anywhere, you stop using an integration, or you suspect any kind of breach.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Know Where Every Key Lives&lt;br&gt;
If someone asked you right now to list every API key your project uses and where each one is stored, how long would it take you to answer?&lt;br&gt;
If it's more than a few seconds you have a visibility problem. You can't protect what you can't see. You can't rotate what you can't find. You can't revoke access to what you don't know exists.&lt;br&gt;
How to fix it: Keep all your keys in one organized secure place. A proper secrets manager gives you a single source of truth for every key, who has access to it, when it was last rotated, and which service it belongs to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have a Response Plan for Exposed Keys&lt;br&gt;
Most developers wait until a key gets exposed to figure out what to do. By then it's too late.&lt;br&gt;
Know in advance: which keys are most critical, how to revoke and regenerate each one, and who needs to be notified if a key is compromised.&lt;br&gt;
How to fix it: Take 30 minutes to document your key rotation process for each service you use. Store that documentation somewhere accessible so you can act fast when you need to.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I learned most of this the hard way across multiple projects with dozens of API keys scattered everywhere. That's why I built Keydock, a simple secure vault to store and manage all your API keys with zero knowledge AES-256-GCM encryption.&lt;/p&gt;

&lt;p&gt;Try it free at keydock.cloud&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>devtools</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
