Secret Management in Application Security: A Practical Guide

A leaked API key or password works like a key to production. Why secret management belongs in AppSec, where secrets hide, and how to find them in code.

Content

Make Your Applications Secure Today

Sign up for a personalized demo to see how DerScanner can meet your Application Security needs

In the previous article, we described how a single stolen application secret gave attackers a way into hundreds of Microsoft 365 tenants. This article looks at the wider problem: how to manage secrets as part of application security, starting with the ones in your own code.

What counts as a secret

A secret is anything that proves identity or grants access: passwords, API keys, OAuth client secrets, access tokens, private keys, certificates and connection strings. Secret management means knowing where each one lives, keeping it out of code, limiting its rights, rotating it and watching how it is used.

Why a leaked secret is so dangerous

  • It carries full rights. Whoever holds a secret can do everything the secret allows. Systems cannot tell the owner from a thief.
  • It skips MFA. Applications sign in with their own credentials. There is no user and no second factor to stop the sign-in.
  • It is often shared. One key may serve many services, environments or customers. One leak then opens all of them.
  • It lives for a long time. Many secrets are created once and never rotated. A key leaked years ago may still work today.

The rule. Treat every API key, token and app credential like a production password, because that is what it is.

Why secrets are an AppSec problem

Secrets are often seen as an operations task: someone sets up a vault and the job is done. In practice, most secrets are created, used and leaked by application code. A developer pastes a token into a config file to test a connection. A test suite keeps a real database password. A connection string ends up in a build image. Each of these is a vulnerability in the application, just like an injection flaw.

MITRE lists this weakness as CWE-798: Use of Hard-coded Credentials. Once a secret is in a repository, it spreads to every clone, fork, backup and CI runner that copies the code. Deleting it from the latest commit does not remove it from Git history.

Where secrets hide

Where Example How to find it
Source code An API key in a string constant Scan the code with SAST
Config files A password in a settings or properties file Include configuration files in the scan
Tests and samples A real token left in a test or demo script Include test folders in the scan
Git history A key committed once and deleted later Search the full history and rotate anything you find
CI/CD and platforms Deployment tokens and cloud keys in pipeline settings Review pipeline and platform variables
App registrations Client secrets on cloud and SaaS apps Review the credentials on each app and who added them

Secret management in practice

  • Keep secrets out of code. Load them at runtime from a vault or the platform's secret store. Code should hold a reference, never the value.
  • Scan code before it merges. Check every change for hardcoded credentials so a leak is caught before it reaches the main branch.
  • Give each secret the least rights it needs. A key that can read one mailbox is far less dangerous than one that can read all of them.
  • Use one secret per service and environment. When one leaks, you rotate one thing instead of everything.
  • Prefer short-lived credentials. Where the platform supports it, use certificates or workload identity instead of long-lived client secrets.
  • Watch app credentials. Alert when a new secret or certificate is added to an application, or when an app gives itself new roles.
  • Keep a rotation playbook. Know who rotates what, in which order, and how long it takes. Always revoke the old value when you add a new one.

If you depend on a vendor's app

You cannot rotate a vendor's secret yourself. You can limit what it can do. Review which third-party apps have access to your environment and what rights they hold. Remove the apps you no longer use. Check sign-in and audit logs for app activity you do not expect.

Where DerScanner helps

DerScanner's SAST detects hardcoded credentials in your source code and configuration files. Here is how to use it for secrets, step by step.

  1. Scan the code and the configuration files. Turn on configuration files analysis in the scan settings. Passwords and keys often sit in settings files next to the code.
  2. Scan every change. Connect DerScanner to GitLab, GitHub or Bitbucket through a webhook, or run it from GitLab CI, Jenkins, Azure DevOps or TeamCity. Every commit is then checked for new hardcoded secrets.
  3. Check the findings with DerTriage. DerTriage looks at the wider context of each SAST detection and marks it Confirmed or Rejected. The reasoning behind each decision is shown with the vulnerability.
  4. Get a secrets-only report. Export the report with the By secrets classification. It lists only vulnerabilities related to improper storage or leakage of sensitive data in the project's code. The report is available in PDF, HTML, CSV and SARIF.
  5. Track progress between scans. Turn on Compare with Scan in the report to see which findings are new, which remain and which were fixed.
  6. Fix and assign. DerCodeFix suggests a code change for the vulnerable snippet. You can also create a Jira task from a finding. Rotate the secret as well, because it has already been exposed.
  7. Add your own rules. If your teams use their own names for keys and tokens, create a custom rule so DerScanner flags them too.

DerScanner can run on-premises, so your code and the secrets in it stay inside your network.

Find the secrets in your code

Book a demo and see a secrets-only report on your own project. Get a demo

Sources: MITRE CWE-798; DerScanner User Guide, release 13.

Loading blogs...
Get Started

Ready to Reduce Technical Debt and
Improve Security?

Clean code. Fewer risks. Stronger software

dashboard