Secrets Management

Secrets management is the full lifecycle of machine credentials (API keys, cloud keys, tokens, signing and encryption keys, passwords): keeping them out of code and artifacts, storing and issuing them safely, detecting leaks, and revoking them fast. Attackers increasingly log in with a leaked secret rather than exploit a vulnerability.

What it is

The discipline covers every place a credential is created, copied, stored, used and invalidated. A secret is a bearer capability, so every copy works as well as the original. Exposure is therefore the number of copies multiplied by how long each one stays valid. Appsec owns both sides of that: preventing copies (code, bundles, images, CI, endpoints) and shortening validity (federation, dynamic credentials, revocation).

Why it matters, by the numbers:

  • Sprawl. GitGuardian counted 28.65M new hardcoded secrets in public GitHub commits in 2025 (+34% YoY). That includes 1.28M AI-service secrets (+81%). 32.2% of internal repos hold a secret, against 5.6% of public ones. 28% of incidents never touch code at all: they sit in Slack, Jira and Confluence (GitGuardian 2026, THN 9 takeaways). Finance-linked public repos run at 6.9%: 48,819 secrets, 446 of 2,639 sensitive ones valid at first detection (GitGuardian, finance vs ARTEX). GitHub reported 39M secret leaks in 2024 (GitHub blog).
  • The web itself. A dynamic crawl of 10M rendered sites found 1,748 valid keys for 14 providers, including AWS, Stripe, OpenAI, SendGrid and Twilio. 62% of JavaScript exposures existed only in compiled bundles and 16% arrived through third-party inclusions, so repo-based static scanning misses them. Keys stayed public for an average of 12 months, and disclosure got about half of them removed (Keys on Doormats, CCS 2026).
  • Speed. Leaked AWS keys get used within about 5 minutes of a public push (Unit 42 EleKtra-Leak, Tachyon canary). AI agents went from a GitHub search to exfiltrating Azure Key Vault data in five minutes (Microsoft).
  • Persistence. 64% of secrets valid in 2022 were still valid in January 2026. 81% of the live keys Truffle disclosed still worked six months later (GitGuardian report, Truffle revocation program).

Core concepts

  • Copy inventory, not “the secret”. One leaked production key in GitGuardian’s walk-through had 13 copies: a hardcoded fallback, a config file, a stale pipeline variable that overrode the vault, a Jira ticket. The team knew about one of them (Credential Rotation and Revocation).
  • Leak surfaces. Source and client artifacts (Hardcoded Secrets), history and its mirrors (Secrets in Git History), laptops and CI runners (Developer Workstation Secrets), plus runtime credential providers reachable after code execution or SSRF (Cloud Metadata Service Exploitation, IMDSv2).
  • Deleted ≠ revoked. Git is append-only. Force-pushed “oops commits” remain retrievable and show up in GH Archive. Only invalidation ends a leak (Secrets in Git History).
  • Client-shipped means public. Anything inside a JS bundle, NEXT_PUBLIC_*, an APK/IPA or firmware is readable by every user. Obfuscation and encoding only slow a reader down (Hardcoded Secrets, JavaScript Analysis).
  • Signing keys are auth bypasses. A leaked JWT, HMAC, cookie or SECRET_KEY value lets an attacker forge sessions (JWT Secret Cracking, Session Management). That includes keys published by mistake: a JWKS carrying d/p/q or an oct key’s k hands out the signing key (Avada Labs; Hardcoded Secrets).
  • Prompts are a leak surface. Secrets in LLM prompts travel to every inference hop; “Zero Data Retention” binds only the first. Dragos’s canary study caught three breached providers and keys tested within hours (THN; Leaked Cloud Credentials).
  • “Who can decrypt?” is the perimeter. A vault moves the question from where the value lives to which identities can read or decrypt it (Vaults and Secret Stores).
  • Secretless, but not trustless. Federation removes the static key, so the trust policy and the role’s blast radius become the asset to protect (Workload Identity Federation).
  • Time-to-revoke = confirmed_invalidation_ts - validation_ts. This is the metric that matters. MTTR can close on a ticket while the key still works.
  • Verified vs critical. Live verification makes findings actionable, but 46% of critical secrets are missed by validation-only prioritization (Secret Scanning).

How to approach it

  1. Inventory every copy. Cover repos and full history, CI variables, container images, built bundles, collaboration tools, endpoints and runners. For service accounts, run SCALER: Scale → Classify → Assign owner → Lifecycle → Enforce → Rotate (Credential Rotation and Revocation).
  2. Scan in layers. Pre-commit → push protection → CI → org-wide and public monitoring → artifacts, collaboration tools and endpoints. Use more than one engine (Secret Scanning).
  3. Scan what you ship, not only what you commit. Rendered pages, compiled bundles and third-party scripts carry keys that never appear in repo scans (Keys on Doormats). Storybook CVE-2025-68429 bundled .env values into published static builds (Hardcoded Secrets).
  4. Remove static secrets. Use OIDC, IRSA/Pod Identity or IAM Roles Anywhere for anything that talks to a cloud or SaaS with federation support. Follow AWS SEC02-BP03’s order: remove, replace with short-term credentials, then store and rotate only what is left (Workload Identity Federation).
  5. Vault the remainder. Give least-privilege read and decrypt access per secret, audit every access, prefer dynamic or leased credentials, and deliver them by mounted file or sidecar rather than environment variables (Vaults and Secret Stores).
  6. Review decrypt paths. Ask whether any CI identity, build system, agent tool or co-tenant process can resolve production secrets to plaintext. Railway and AgentCore both failed on this question.
  7. Rehearse the runbook. Validate → scope → revoke in blast-radius order → confirm the old value fails → review logs from the exposure time → only then clean history (Credential Rotation and Revocation).
  8. Propagate fixes to clones. Rotating production does not fix the training, staging and RC environments cloned from the same template. An airline rotated a default Keycloak admin password on production, but its training instance still accepted admin:admin123 18 days later (Keycloak write-up).

Key techniques

Finding leaked secrets (offense and assessment)

  • Bundles and client code. Grep built JS for provider prefixes. Check Next.js and Vite env-prefix mistakes, and run the TruffleHog Chrome extension for keys and exposed .git/.env (JavaScript Analysis, Hardcoded Secrets).
  • Mobile binaries. Decompile and grep strings. AI-assisted review of decompiled code found customer-database passwords in hotel and restaurant apps (Android App Security, iOS App Security).
  • History and oops commits. Run gitleaks git . --log-opts="--all" and trufflehog git file://. --results=verified. Truffle’s Force Push Scanner mines GH Archive for dangling commits (Secrets in Git History).
  • Search and dorks. GitHub code search and dorks such as /AIza[0-9A-Za-z_-]{35}/ path:/.env, plus web-exposed .env files (Google Dorking, Content Discovery). Attackers now automate this with agents that combine an org name with secret keywords (Microsoft).
  • Diagnostic endpoints. Spring Boot Actuator /env and /configprops return env-injected keys in clear once value masking (show-values) or endpoint security is turned off (Bytebantz; Secrets in Logs and Build Artifacts).
  • JWKS audits. Fetch /.well-known/jwks.json or jwks_uri and flag private parameters, symmetric keys, missing/duplicate kid and RSA < 2048 (Avada Labs).
  • Stealer-log exposure. Infostealer datasets now hold corporate AI-service logins (ChatGPT, Claude, Gemini, Copilot, Cursor); Brandefense’s free check searches one source by domain, so a negative result proves nothing (Lerner; Developer Workstation Secrets).
  • Proxied traffic. The TruffleHog Burp extension verifies more than 800 secret types in proxied traffic. Hirdman Radar shows, per host, how many leaked records (infostealer logs, breach credentials) mention it, and ranks mail, VPN and SSO hosts first (Burp Suite Extensions, hirdman-radar).
  • Forgotten environments. Wayback CDX recon (web.archive.org/cdx/search/cdx?url=*.example.com/*) surfaced cloned hosts that wildcard certificates hid from CT logs (Subdomain Enumeration, Keycloak write-up).
  • Secrets via another bug. SSTI that reaches the Django signer leaks SECRET_KEY. In Arize Phoenix (CVE-2026-53998, CVSS 10), a GraphQL applyChatTemplate f-string template walks into Python globals, leaks PHOENIX_SECRET, and with it forges admin sessions and decrypts stored LLM keys. It needs no auth on default installs (GraphQL Security, AI Infrastructure Vulnerabilities, Stackurity).

What attackers do with them

Controls

  • Layered scanning with custom rules and unique prefixes for internal tokens (Secret Scanning).
  • Workload identity federation. Pin sub to owner/repo plus an environment, prefer ID-based subjects, and grant no IAM write (Workload Identity Federation). The SaaS version of the pattern is SonarQube Cloud’s secretless analysis: the GitHub or GitLab OIDC JWT is exchanged via RFC 8693 for a token that scans one project for 30 minutes. The exchange checks the RS256 signature against a configured JWKS, plus iss, aud set to region, expiry, single-use jti, and a repo binding by ID, not name, which defeats repo-jacking (Sonar).
  • Vaults. Vault/OpenBao dynamic engines, the Secrets Store CSI Driver, Vault Secrets Operator, and SOPS or Sealed Secrets for GitOps. Kubernetes Secret objects are only base64-encoded (Vaults and Secret Stores).
  • Rotation patterns. Dual-credential overlap, staged Secrets Manager rotation (AWSPENDING → AWSCURRENT), dynamic leases, and single-swap-with-revert (Credential Rotation and Revocation).
  • Endpoint hardening. Non-exportable SSH keys (Secure Enclave, Secretive), short-lived CLI sessions, .env kept outside agent working directories, and sandboxed coding agents (Developer Workstation Secrets, AI Coding Assistant Risks, MCP Security).

Tools

NeedToolNotes / command
Pre-commitGitleaks, detect-secretsgitleaks git -v --redact; gitleaks:allow inline; baselines for brownfield
CI and verificationTruffleHogtrufflehog git file://. --since-commit main --branch feature-1 --results=verified,unknown --fail
Org-wideTruffleHog, GitHub/GitLab secret scanningtrufflehog github --org=acme --exclude-archived; GitHub covers all branches, issues, PRs, wikis
Images and artifactsTruffleHogtrufflehog docker --image acme/app:latest --results=verified; gitleaks dir ./build for bundles
Second engineKingfisher, BetterleaksOn 7.25M Gitee repos, TruffleHog and Kingfisher shared only 1,001 findings
History cleanupBFG, git filter-repoOnly after revocation; forks and GH Archive keep the old objects
Testing trafficTruffleHog Burp/Chrome extensions, Hirdman RadarBurp leak counts per host; private-project mode sends nothing
StoresVault/OpenBao, AWS Secrets Manager, CSI Driver, VSO, SOPSvault read aws/creds/deploy mints a leased IAM key
FederationGitHub OIDC + aws-actions/configure-aws-credentials, IRSA, Roles Anywherepermissions: id-token: write
TrainingOWASP WrongSecrets65+ challenges across code, Docker, Kubernetes and cloud ([[raw/github.com/owasp-wrongsecrets-6950

Validate a found AWS key read-only with aws sts get-caller-identity. The CCS study verified keys the same way, through read-only provider endpoints (STS GetCallerIdentity, Slack auth.test, Cloudflare tokens/verify) (Keys on Doormats).

Pitfalls

  • Deleting instead of revoking. 75% of developers who removed a secret from a Docker image never rotated it (Flare).
  • Treating AWS quarantine as containment. Tachyon’s canary key drained Secrets Manager after the quarantine policy was attached (Leaked Cloud Credentials).
  • Revoking before you find the consumers. The next deploy breaks, and the outage teaches teams not to rotate. Updating the vault while a stale pipeline variable overrides it is the same failure in reverse (Credential Rotation and Revocation).
  • Scanning only repos. Bundles (62% of web JS exposures), third-party scripts, Slack and Jira (28% of incidents), images and endpoints are all outside git.
  • Trusting one scanner, or verification alone. Generic secrets made up 63% of the settings.local.json leaks. Gitleaks and TruffleHog together missed 1 in 5 leaking files (Secret Scanning).
  • Env-var fallbacks. process.env.JWT_SECRET || 'auth-secret-key' quietly becomes the production key (Hardcoded Secrets). A memorable HMAC secret is a password: anyone holding one token can crack it offline (hashcat mode 16500). Use ≥32/48/64 random bytes for HS256/384/512 and fail startup when the secret is missing or short (Avada Labs).
  • Treating notification or takedown as remediation. 62% of valid leaked credentials still worked after the owner was told; removing the code doesn’t help once it’s been copied (GitGuardian). Provider-side fixes don’t revoke either: Microsoft’s APIM patch left stolen Named Values valid (BleepingComputer).
  • Benchmarking scanners against one engine or valid-only sets. Checking whether B finds A’s findings measures only B’s recall on A; generic secrets (~70% of GitGuardian’s customer detections) can’t be validity-checked (Secret Scanning).
  • Environment variables as storage. They are readable via /proc/<pid>/environ, inherited by child processes, dumped in crash logs, and baked into images by ENV/ARG (Vaults and Secret Stores).
  • Over-broad federated roles. UNC6426 rode GitHub→AWS OIDC into a role allowed to create IAM roles, reaching admin in 72h (Workload Identity Federation).
  • Disabled guardrails. The CISA contractor turned off GitHub’s secret blocking before pushing GovCloud admin keys (Krebs).
  • AI agents committing and “fixing”. Agents remove the secret at HEAD and stop. “Don’t ask again” writes keys into .claude/settings.local.json (Secrets in Git History, AI Coding Assistant Risks).
  • Cloned environments and defaults. Training and RC instances inherit template credentials. One Keycloak instance ran EOL version 12.0.3 with ROPC enabled for admin-cli and leaked 766 employee accounts (write-up, Authentication Security).

Real-world cases

  • CISA “Private-CISA”: a public sync repo held AWS GovCloud admin keys and stayed valid about 48h after takedown (Krebs).
  • EleKtra-Leak: GitHub-leaked AWS keys were used within 5 min for EC2 Monero mining (Unit 42).
  • .env extortion: exposed .env files on 110,000 domains led to S3 exfiltration and ransom notes (Unit 42).
  • LLMjacking: stolen keys drove AI spend spikes of over $100k/day, up to $1M (THN/GTIG).
  • ARTEX / Storm-3358: an agentic framework hit finance targets. A GitHub search reached Key Vault in 5 min, and 102 forks appeared in the week of the takedown (GitGuardian, StepSecurity).
  • Agentic offensive frameworks in the wild (Oct–Nov 2026): ARTEX/CyberStrikeAI operators went straight for env vars and stored customer secrets, dumped CI secrets and Terraform state via workload-identity trust, and harvested Anthropic keys from 50 hosts (Wiz; Agentic Offensive Frameworks).
  • GitGuardian Enterprise Good Samaritan (Jun–Nov 2026): 4,064 high-impact leaks at 1,588 companies, median 320 days public; after direct notification 62% of valid credentials still worked, 77.8% of public leaks stayed online and only 35% replied; 5% were leaked by suppliers or contractors (GitGuardian).
  • Azure API Management Classic (Nov 2026): an unauthorized management-plane path (reportedly a legacy API that emitted no customer logs) exposed Named Values, IdP/OIDC client secrets, subscription keys and direct-management tokens; tied to attacks on Equinor and Skagerak Energi. Microsoft’s 19 Nov fix did not invalidate already-stolen credentials, so NSM said treat them as compromised (BleepingComputer, SecurityWeek).
  • agent-framework .pth stealer (17 Nov 2026): read /proc/<pid>/environ of up to 300 processes plus credential files, and minted Azure DevOps/GitHub Actions OIDC and IMDS tokens; Elastic’s advice is that every secret readable on an affected host is gone (Elastic).
  • ARTEX lab test: an agent with no secrets scanner found 8 of 9 planted secrets using git and grep, 7 of them outside current files (GitGuardian).
  • UNC6426: the nx stealer took a GitHub token, the actor abused the OIDC trust, and reached AWS admin in 72h (THN).
  • LiteLLM PyPI: the stealer swept CI runners, leaving 153 GB of loot from 2,488 orgs (GitGuardian).
  • Railway: a build-system privilege escalation gave CI credentials that could decrypt, exposing env vars for up to about 100,000 workspaces, followed by mass revocation upstream (write-up).
  • trivy-action / GhostAction: tag force-push read runner memory, and workflow-pushing campaigns harvested repo secrets (Sonar).
  • GitHub oops commits: a scan of dangling commits since 2020 earned about $25k, including an Istio admin PAT (InfoQ).
  • Gitee 7.25M repos: 26,400 live credentials, about half from 2025 (Peris).
  • Docker Hub: 10,000+ images leaked secrets in one month, LLM keys most common (Flare).
  • Claude Code settings.local.json: 31,088 secrets on public GitHub, 5,343 of them valid (GitGuardian).
  • Rackspace Spot (17 Nov 2026): leaked credentials → pods in customer clusters, all cluster Secrets and Spot API/refresh tokens readable; console outage delayed rotation for four days (BleepingComputer).
  • AI inference prompt theft (Jul–Nov 2026): canary AWS keys in prompts stolen from breached providers and abused within hours (S3, Secrets Manager, Parameter Store, Bedrock key creation, IAM users); OpenRouter dropped three providers and all four implicated providers told users to rotate secrets sent in prompts (BleepingComputer). Together AI’s prompt samples were stolen after an AI coding agent committed a credential to a public repo (THN).
  • BISHENG < 3.0.0 (CVE-2026-130840) and Tensei ≤ 0.11.5 (CVE-2026-129552): hard-coded JWT signing secrets, offline-forged admin tokens, CVSS 9.3 (VulnCheck, VulnCheck).
  • Swarm bee-js 13.3.0 / Desktop 0.56.2: maintainer credentials plus the release bot’s token let the pipeline publish without a second approver; stage-2 stole node keys and passwords (Swarm Foundation; Software Supply Chain Security).
  • Rails test secret in production: signed-cookie forgery led to deserialization, paid at $18,000 (write-up).
  • Arize Phoenix CVE-2026-53998: an unauthenticated GraphQL format string leaked PHOENIX_SECRET and the stored LLM keys (Stackurity).
  • Airline cargo Keycloak: admin:admin123 on a cloned training environment exposed 766 accounts (write-up).
  • Leaked TLS keys: 2,600 valid certificates mapped to leaked private keys, but only 24 were revoked via CRL (GitGuardian/Google).

Checklist

  • Inventory covers repos and full history, CI variables, images, built bundles and third-party scripts, chat and ticketing, endpoints and runners.
  • Scanning runs at pre-commit, at push, in CI, org-wide, in public monitoring and on artifacts, with at least two engines and generic rules enabled.
  • Custom detectors exist for internal token formats, and internal tokens use unique prefixes.
  • No IAM users or static cloud keys in CI. OIDC trust pins owner/repo/environment by ID, and roles have no IAM write.
  • Remaining static secrets sit in a store with per-secret least privilege, audit logs and mounted-file delivery, not environment variables.
  • No CI identity, build system or agent tool can decrypt production secrets.
  • No fallback defaults: the app fails closed when a secret is missing. Default admin passwords are changed on every cloned environment.
  • Client-shipped values (bundles, apps, firmware) are treated as public. Vendor calls are proxied or use per-user server-minted tokens.
  • The leak runbook ends in confirmed invalidation, then a log review from the exposure time. Time-to-revoke is tracked.
  • Every credential has an owner, an expiry and a rollback plan for rotation.
  • Canary credentials are seeded in repos, CI and agent/prompt context, and any use pages someone (THN).
  • Public JWKS contain public parameters only; diagnostic endpoints (Actuator /env) are unexposed or masked.
  • Developer and agent endpoints use non-exportable SSH keys, short-lived CLI sessions and .env outside agent working directories.
  • Self-hosted AI and observability tools (Phoenix, LiteLLM and similar) are inventoried and patched, and their master keys are rotated after exposure.

Sub-pages

Related topics: Software Supply Chain Security · CI-CD Pipeline Attacks · GitHub Actions Security · Pwn Requests · Server-Side Request Forgery · Cloud Metadata Service Exploitation · JWT Secret Cracking · JSON Web Tokens · JavaScript Analysis · AI and LLM Security · OpenID Connect Security · Authentication Security

Sources