appsec.fyi

Secrets — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

Secrets: A Practical Guide

Curated and synthesized by . Last updated 2026-11-01. Synthesized from 277 of 277 curated resources. Browse all 277 Secrets resources →

Problem Framing

The proliferation of secrets—API keys, credentials, certificates, and tokens—within application development and operational workflows has evolved into a critical security challenge. This is exacerbated by the rapid adoption of AI-assisted development tools, accelerated CI/CD pipelines, and complex cloud-native architectures. The sheer volume and dynamic nature of these secrets create a sprawling attack surface, where a single leaked credential can grant access to sensitive systems and data. This environment fosters an arms race, with attackers increasingly leveraging automation and AI to discover, exfiltrate, and exploit secrets at machine speed. The persistence of leaked secrets, often remaining unrevoked for extended periods, compounds the risk. Furthermore, the expansion of the attack perimeter to developer endpoints and collaboration tools means secrets are no longer confined to code repositories, demanding a more holistic approach to their management and protection.

Core Mechanics

Secrets are exposed through a variety of mechanisms, fundamentally boiling down to accidental or malicious introduction into insecure contexts. This often begins with developers, consciously or unconsciously, embedding secrets directly into source code, configuration files, or environment variables [1][2]. The widespread use of AI coding assistants has introduced new vectors; these tools can ingest and process sensitive information from their context windows, potentially leading to secrets appearing in generated code or cached configurations if not properly managed [3][4][2].

Supply chain attacks represent another significant avenue for secret exposure. Malicious actors compromise popular open-source packages, injecting code that harvests secrets from developer machines or CI/CD runners during the build or installation process [5][6][7][8][9]. These compromised packages, once integrated into downstream projects, can lead to widespread credential theft. Similarly, vulnerabilities in CI/CD pipelines, such as misconfigured webhooks or compromised GitHub Actions, can be exploited to extract secrets stored within the pipeline's environment [10][11][12][13].

Beyond traditional code repositories, secrets are increasingly found in less obvious locations. Collaboration tools like Slack, Jira, and Confluence have become repositories for sensitive information, often shared in plain text [14]. Developer endpoints themselves have transformed into critical attack surfaces, accumulating credentials from various applications, AI tools, and cloud CLI configurations [15]. Secrets embedded within container images, ConfigMaps, and environment variables in Kubernetes deployments also present a direct path to compromise [1].

The core mechanics of exfiltration often involve attackers automating the discovery of these exposed secrets. Tools can scan public repositories for patterns matching API keys or credentials, and then verify their validity by attempting to use them against issuing APIs or cloud provider endpoints [16][17][18][19]. The speed at which this happens means compromised credentials can be used for malicious activities, such as cryptocurrency mining or unauthorized resource access, within minutes of their exposure [16][20].

Notable Techniques

Hardcoding and Embedding: The most fundamental technique is hardcoding secrets directly into source code, configuration files (e.g., .env, mcp.json), or environment variables. This practice persists despite awareness, often due to convenience or lack of proper tooling [1][2]. Secrets are also embedded in container images, often through ARG or ENV instructions, making them part of the image metadata and accessible through image inspection [21]. Even seemingly inert files like archive formats (.zip, .tar.gz) can contain hardcoded secrets [14].

Supply Chain Compromise: Malicious actors inject credential-stealing logic into popular open-source packages. This can occur through compromised build scripts (build.rs in Rust crates), preinstall scripts in npm packages, or by manipulating package manager upload mechanisms [5][7][8][9][22]. The "Shai-Hulud" worm variants are prime examples, targeting SAP npm packages and others, exfiltrating cloud configurations and GitHub Actions secrets [23][24].

AI-Assisted Development Risks: AI coding assistants introduce novel risks. They can ingest secrets from prompts or cached commands, potentially leaking them into generated code or configuration files. For instance, the .claude/settings.local.json file has been observed leaking API keys [25][4]. Similarly, AI agents may require local credentials to perform tasks, increasing the risk on developer endpoints. Some AI agent frameworks use "Model Context Protocol" (MCP) configuration files, which have been found to contain numerous secrets [26].

CI/CD Pipeline Exploitation: Compromised GitHub Actions workflows are a significant vector. Vulnerabilities like pull_request_target triggers, cache poisoning, or the exploitation of OIDC tokens can allow attackers to exfiltrate secrets stored in the CI/CD environment [11][13][20]. Webhooks from systems like Harbor can also be exploited via SSRF to expose cloud IAM credentials [10].

Developer Endpoint as Attack Surface: Developer machines are becoming prime targets due to the accumulation of secrets. This includes secrets in shell history, .env files, AI tool configurations, browser storage (via DPAPI), and SSH keys [15][27]. Tools like Lazagne, SharpChrome, and DonPAPI can harvest these credentials.

Collaboration Tools and Non-Code Sources: Secrets are frequently found in collaboration platforms like Slack, Jira, and Confluence, often in plain text messages or issue descriptions [14]. GitHub comments, Gists, and even deleted commit histories can also reveal sensitive information [28][29].

Credential Verification and Harvesting: Attackers often don't just find secrets; they verify them. Automated scripts can test leaked API keys against cloud provider APIs or specific service endpoints to confirm their validity before attempting malicious actions [16][20].

Persistence Mechanisms: In some cases, attackers establish persistence. This can involve planting secret-dumping workflows, leveraging compromised tokens for ongoing access, or using mechanisms like Python's .pth files for stealthy execution [11].

Cloud Environment Exposure: Cloud IAM credentials, service account tokens, and API keys are frequently exposed in public repositories or via misconfigured cloud resources (e.g., unsecured S3 buckets, exposed container registries). This can lead to unauthorized access, data exfiltration, and resource abuse, such as cryptocurrency mining campaigns [10][20][19].

Detection & Prevention

Addressing secret sprawl requires a layered defense strategy, shifting security left into the development lifecycle while maintaining robust runtime monitoring.

Shifting Left: Developer and Build-Time Controls

Runtime and Infrastructure Controls

Specialized Techniques

Tooling

A comprehensive approach to secrets management and detection relies on a diverse set of tools.

Secret Scanning and Detection

Secrets Management Platforms

Developer Endpoint and AI Security

History Rewriting Tools

Credential Verification and Monitoring

Recent Developments

The landscape of secrets management and exposure is rapidly evolving, largely driven by the integration of AI and the increasing complexity of software supply chains.

AI's Amplifying Effect

The most significant development is AI's role in both creating and discovering secrets. AI coding assistants are becoming ubiquitous, and their inherent design to ingest context can lead to the accidental leakage of secrets into code or cached configurations [3][25][4][2]. Researchers have observed AI-assisted commits exhibiting a significantly higher rate of secret leakage compared to human-written code. Furthermore, AI models trained on public code repositories may inadvertently reproduce leaked API keys they've encountered [3][39]. Concurrently, threat actors are leveraging AI to automate the discovery and exfiltration of secrets at an unprecedented scale [40][26].

Supply Chain Sophistication

Supply chain attacks are becoming more sophisticated. Beyond simple package poisoning, attackers are now using techniques like compromising legitimate build pipelines, creating malicious packages with valid provenance (e.g., SLSA attestation), and targeting niche package ecosystems like SAP npm packages [8][22]. The "Shai-Hulud" worm and its variants demonstrate the potential for widespread credential harvesting from developers and CI/CD environments through these compromised dependencies [23][24].

Persistence of Leaked Secrets

A persistent and alarming trend is the longevity of leaked secrets. A significant percentage of secrets first identified in previous years remain unrevoked and active [39][41]. This indicates a systemic failure in credential lifecycle management, where secrets are created, exposed, and then forgotten rather than actively managed and revoked.

Expanding Attack Surface Beyond Code

The focus of secret exposure has expanded beyond code repositories. Collaboration tools, cloud storage, and developer endpoints are increasingly becoming targets. The statistic that a substantial portion of secret incidents originate entirely outside source code highlights this shift [14][15]. This necessitates tools and strategies that monitor these non-traditional locations.

AI Agent Security and Non-Human Identities (NHI)

The rise of AI agents has brought the security of non-human identities to the forefront. These agents often require permissions and credentials to operate, making their security posture critical. Misconfigurations or compromises of AI agents can grant attackers broad access to systems and data [35][37].

Improved Detection and Remediation Tools

Tooling is evolving to keep pace. Enhanced secret scanning algorithms, including AI-powered pattern detection, are improving accuracy and reducing false positives [17]. Innovations like credential verification (testing discovered secrets) and improved capabilities for analyzing AI agent behavior are also emerging. However, the sheer volume of secrets and the speed of exposure continue to challenge remediation efforts.

Where to Go Deeper

For practitioners seeking to deepen their understanding and practical application of secrets management and security, several resources offer invaluable insights:

Sources cited in this guide

  1. The State of Secrets Sprawl 2026 - GitGuardian Annual Report — gitguardian.com
  2. Hardcoded Secrets in AI-Generated Code: Catch Them Before They Ship — toxsec.com
  3. Leaked API Keys in LLMs: How AI Agents Expose Secrets — blog.gitguardian.com
  4. From .env to Leakage: Mishandling of Secrets by Coding Agents — knostic.ai
  5. LiteLLM compromised again: infostealer and RAT found in version 1.107.0 — aikido.dev
  6. 153GB of stolen credentials surface after LiteLLM supply chain attack — helpnetsecurity.com
  7. ChainDrop: Inside a Self-Propagating npm Worm — unit42.paloaltonetworks.com
  8. Supply Chain Campaign Targets SAP npm Packages with Credential-Stealing Malware — wiz.io
  9. Malicious Release of elementary-data PyPI Package Steals Cloud Credentials from Data Engineers — snyk.io
  10. SSRF in Harbor Webhooks exposes cloud credentials — ox.security
  11. Gheist: Attempted Scaled Abuse of Stolen GitHub Tokens Stumbles — wiz.io
  12. Reconstructing the TJ Actions Changed Files GitHub Actions Compromise — snyk.io
  13. KICS GitHub Action Compromised: TeamPCP Strikes Again in Supply Chain Attack — wiz.io
  14. The State of Secrets Sprawl 2025 — blog.gitguardian.com
  15. The Perimeter Moved to the Laptop: From Network, to Identity, to the Developer Endpoint — blog.gitguardian.com
  16. What happened after we pushed our .env to a public repo — tachyon.so
  17. GitHub Secret Scanning 2026: New Patterns, Push Protection — buildmvpfast.com
  18. GitHub Found 39M Secret Leaks in 2024 — The GitHub Blog — github.blog
  19. Leaked Env Variables Allow Large-Scale Cloud Extortion — unit42.paloaltonetworks.com
  20. UNC6426 Exploits nx npm Supply-Chain Attack to Gain AWS Admin Access in 72 Hours — thehackernews.com
  21. Terraform Secrets Management Best Practices — blog.gitguardian.com
  22. TanStack Npm Packages Compromised Inside The Mini Shai Hulud Supply Chain Attack — snyk.io
  23. Shai-Hulud Hits SAP: Stolen Credentials Found in 1200 GitHub Repos — ox.security
  24. Supply Chain Campaign Targets SAP npm Packages with Credential-Stealing Malware — wiz.io
  25. Claude Code is leaking API keys into public package registries — bdtechtalks.com
  26. 29 Million Secrets Leaked: AI Coding Tools Making It Worse — turbogeek.co.uk
  27. Leaking Secrets in the Age of AI — wiz.io
  28. Researcher Unearths Thousands of Leaked Secrets in GitHub's "Oops Commits" — infoq.com
  29. Why 28 Million Credentials Leaked on GitHub in 2025 | Snyk — snyk.io
  30. Secure Code Scanning: Basics & Best Practices — wiz.io
  31. AI Agent Threat Response: Why Pre-Runtime Controls Matter More Than Runtime Detection — blog.gitguardian.com
  32. Secrets Management in 2026: Vault, AWS Secrets Manager, and Beyond — javacodegeeks.com
  33. The Complete 2026 Secrets Management Guide — dev.to
  34. How to Measure Time to Revoke for Exposed Credentials — blog.gitguardian.com
  35. AI Agent Security: Best Practices for Safe Deployment — blog.gitguardian.com
  36. Credential Exposure and the Security Stack Gap — blog.gitguardian.com
  37. AI Is Fueling Secrets Sprawl: GitGuardian Reports 81% Surge of AI-Service Leaks — blog.gitguardian.com
  38. Lab 2 : Information Disclosure on a Debug Page — infosecwriteups.com
  39. AI Created a Leaked Credentials Flood: Here's How We're Draining It — blog.gitguardian.com
  40. 29 Million Leaked Secrets: How AI Coding Tools Are Making It Worse — helpnetsecurity.com
  41. 23.8 Million Secrets Leaked on GitHub: The Case for Expiring Credentials — zerohost.net
  42. The State of Secrets Sprawl 2026: 9 Takeaways for CISOs — thehackernews.com
  43. A new type of long-lived key on AWS: Bedrock API keys — wiz.io
  44. Tracking TeamPCP: Investigating Post-Compromise Attacks Seen in the Wild — wiz.io
  45. OWASP Top 10 CI/CD Security Risks Explained: Why Credential Hygiene Decides the Outcome — blog.gitguardian.com
📚 This guide is synthesized from the full text of resources curated in the Secrets library, and refreshed as new material is added.