Free Resource · guide

Why Should You Never Hardcode API Keys?

Because code travels and secrets shouldn't. A key pasted into source code gets copied into every repo clone, every backup, every laptop, and every AI tool that reads the file, and it stays valid long after everyone forgets it's there. The fix is layered: keep secrets out of code entirely (environment variables at minimum, a vault like Azure Key Vault properly), grant applications identities instead of passwords where the platform allows it, and rotate any key that has ever touched a repo. Done right, a stolen copy of your code contains nothing worth stealing.

Every business that writes or commissions software eventually accumulates API keys: the email platform, the payment processor, the cloud storage account, the CRM integration. And the fastest way to make any integration work is to paste the key straight into the code. It works, it ships, and it quietly becomes the most dangerous line in the file.

We covered this in one of our AI workshops while showing how our own automation platform handles credentials, and it’s worth writing down, because the pattern applies to any business with custom code, scripts, or integrations.

What’s actually wrong with a key in the code?

Code is the most copied artifact in your company. It lives in version control with full history, on every developer’s laptop, in backups, in file shares, and now in every AI tool that reads a file to help someone work. A key pasted into code is replicated into all of those places, and it stays valid in all of them until someone rotates it — which nobody does, because nobody remembers it’s there.

That’s the asymmetry: the key was added in one place, but it now exists in dozens, and revoking access means finding a credential nobody has thought about in years. When a laptop is stolen, a repo is accidentally made public, or an ex-employee’s copy of the code walks out the door, the key goes with it.

Where should keys live instead?

Two tiers, and most businesses should use both:

Environment variables are the minimum: the key lives in the platform’s configuration (an Azure App Service setting, a deployment variable), not in the code. The code asks for it by name at runtime. Anyone with the code has the name, not the value.

A secrets vault is the proper answer for anything beyond a single app. In our own platform, every external service credential lives in Azure Key Vault; when a workflow needs to reach a Microsoft 365 tenant or an outside API, it fetches exactly the key it needs at runtime. One place to store, audit, rotate, and revoke — and looking at the code tells you nothing.

What’s better than protecting the secret? Not having one.

The step most businesses haven’t heard of: for connections inside a cloud platform, you can often eliminate the password entirely. In Azure this is a managed identity: the web app itself is granted an identity, that identity is granted access to the database, blob storage, or vault, and the connection string contains no password at all.

As Greg put it in the workshop: “if the code was compromised, there’s nothing to see.” That’s the end state to aim for — a codebase where a full copy in an attacker’s hands contains no credentials, because the trust lives in the platform, not in a string.

What should a business owner actually do?

You don’t need to read code to manage this risk. Ask whoever builds or maintains your software three questions:

  1. “Where do our API keys and connection strings live?” The answer should name a vault or platform configuration, not “in the app.”
  2. “Has a key ever been committed to a repo?” If yes, or if nobody knows, rotate those keys now. Deleting the line doesn’t remove it from history.
  3. “Which connections could be passwordless?” Anything app-to-database or app-to-storage inside Azure usually can be, and it’s typically a configuration task, not a rewrite.

Credential handling like this is one of the controls cyber insurance applications and client security questionnaires increasingly probe, alongside MFA and backups. It’s also one of the checks in our cybersecurity risk assessment — embedded credentials turn up in almost every environment that has ever commissioned custom software.

Braintek has built and secured software for Houston and Dallas-Fort Worth businesses since 2002, and everything we build runs on vaulted or passwordless credentials by default. If your business runs on custom code and nobody can answer where the keys live, our cybersecurity services team can find out, and the form below is the place to start. Internal apps deserve the same treatment on the login side too — see why your internal apps should use Microsoft 365 single sign-on.

Wondering what's hardcoded in your business right now?

Custom scripts, integrations, and internal apps accumulate embedded credentials over the years, and nobody inventories them until one leaks. Tell us what you run and we'll help you find out where your keys actually live.

By submitting, you agree to be contacted by Braintek about your inquiry.

FAQs

What does "hardcoding" an API key actually mean?

Pasting the key, password, or connection string directly into source code, a config file that ships with the code, or a script. It works instantly, which is exactly why it's common. The problem is that source code is the most copied artifact in your business: version control history, developer laptops, backups, file shares, and AI coding tools all end up holding a copy of whatever was pasted in.

We're a small business, who would even find our keys?

Automated scanners, not people. Bots continuously scan public code repositories and exposed servers for key patterns, and stolen keys are exploited within minutes of exposure, not weeks. Attackers don't care whose key it is; a working key to an email tenant, a payment API, or a cloud account is valuable regardless of company size.

Where should secrets live instead?

In order of preference: a managed secrets vault (Azure Key Vault for Microsoft-stack businesses), then platform environment variables (Azure App Service settings, deployment-time variables), and never in the repo. The application asks the vault for the key at runtime, which means the key can be changed, audited, and revoked in one place without touching code.

What is a passwordless or managed-identity connection?

The platform grants your application its own identity, and you grant that identity access to the database, storage, or vault. The connection string contains no password at all, so there is nothing to steal from the code. In Azure this is a managed identity with Entra authentication; it's our default for anything we build.

We already committed a key to a repo once. Is deleting it enough?

No. Version control keeps history, so the key is still in the repo even after the file is cleaned. Treat any key that has ever been committed as compromised: rotate it at the provider, then move the replacement into a vault or environment variable so it can't happen again.

Does this apply to AI tools reading our code?

Yes, and it's a newer reason the old advice matters more. AI coding assistants read your files to help you; a key sitting in code is a key sitting in every context those tools process. Secrets kept in a vault or environment variables never appear in the code the AI reads, so there's nothing to leak.

Ready for IT that just works?

Book a no-pressure discovery call. We'll review your setup and show you exactly where you stand.