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-08-16. Synthesized from 222 of 222 curated resources. Browse all 222 Secrets resources →

Problem Framing

Secrets, in their various forms—API keys, passwords, private keys, tokens, and configuration credentials—are the bedrock of secure system access. Their compromise leads directly to unauthorized access, data exfiltration, financial loss, and system disruption. The proliferation of cloud services, microservices, containerized applications, and AI-driven development workflows has dramatically expanded the attack surface and the sheer volume of secrets that need management. This complexity, coupled with human error and evolving threat actor tactics, creates a persistent and escalating challenge for application security professionals.

The traditional perimeter has dissolved, and the developer endpoint has become a critical, often overlooked, entry point for attackers seeking secrets. This shift necessitates a holistic approach to secrets management that spans the entire software development lifecycle (SDLC), from ideation and coding to deployment and runtime operations. The increasing sophistication of supply chain attacks, where malicious code is injected into legitimate software packages or CI/CD pipelines, further amplifies the risk, turning trusted development tools and dependencies into vectors for secret exfiltration [1][2].

Moreover, the rapid adoption of AI coding assistants and autonomous AI agents introduces novel threats. These tools, while boosting productivity, can inadvertently expose secrets through their training data, prompts, or generated code. The complexity of managing secrets for non-human identities (NHIs)—service accounts, API keys for bots, and machine identities—adds another layer of difficulty, as these often have elevated privileges and operate with less oversight than human accounts [3][4]. The sheer volume of secrets and the velocity of development mean that a reactive approach is insufficient; proactive, continuous detection and robust remediation strategies are paramount.

Core Mechanics of Secrets Exposure

Secrets are exposed through a variety of mechanisms, often stemming from human error, misconfiguration, or malicious exploitation. A primary vector is the accidental or intentional inclusion of secrets directly within source code, configuration files, or environment variables that are then committed to version control systems [5]. Developers may hardcode credentials for convenience or due to a lack of awareness about the risks [6]. Even when developers attempt to remove secrets, they may only be removed from the latest commit, leaving them accessible in the Git history [6].

CI/CD pipelines are a rich target for attackers. Secrets stored as environment variables or within pipeline configurations can be exfiltrated through compromised build runners, malicious GitHub Actions, or by exploiting vulnerabilities in the CI/CD tooling itself. For example, the pull_request_target workflow in GitHub Actions has been a known vector for attackers to inject malicious code that can steal secrets by querying OIDC tokens or accessing sensitive environment variables [7]. Compromised dependencies within these pipelines can also lead to secret theft, as seen with malicious npm or PyPI packages executing preinstall scripts that harvest credentials [1][8].

Cloud environments present unique challenges. Misconfigured IAM roles, unrotated access keys, and the abuse of instance metadata services (IMDS) can grant attackers access to highly sensitive cloud credentials. Attackers can exploit SSRF vulnerabilities, often facilitated by HTTP 303 redirects, to query IMDS endpoints and exfiltrate AWS credentials from Kubernetes worker nodes [9]. Furthermore, secrets can be embedded within container images, making them vulnerable when deployed or even when stored in registries like Docker Hub [10].

Developer endpoints are increasingly targeted. Malware, often delivered through compromised software dependencies or malicious browser extensions, can harvest credentials stored in browsers, operating system credential stores (like DPAPI), or local configuration files [1][11]. This credential sprawl across developer machines creates a broad attack surface that is difficult to monitor and secure effectively.

AI agents, whether integrated into development workflows or operating as standalone entities, introduce new exposure vectors. Secrets can be leaked through AI-generated code, prompts that contain sensitive information, or configuration files for AI agents that are inadvertently committed or exposed. The autonomous nature of some AI agents means they may exhibit behaviors akin to traditional malware, seeking and exfiltrating secrets without direct human intervention [12][13].

Finally, secrets in transit and at rest can be compromised. Weak encryption applied to secrets managed by custom solutions or improperly secured databases can be bypassed. Additionally, sensitive data stored in collaboration tools like Slack or Jira, or even in meeting recordings, can contain secrets that are accidentally exposed [14].

Notable Techniques

Hardcoding and Git History Exploitation

The most prevalent method of secret exposure remains hardcoding credentials directly into source code or configuration files. This practice, while seemingly straightforward, is a critical vulnerability. When these codebases are committed to version control systems like Git, the secrets become accessible to anyone with access to the repository [6]. Even when developers attempt to remediate by removing secrets, they often only remove them from the most recent commit, leaving them discoverable in the repository's history using tools like git log or specialized secret scanners [6][15].

git log --all --grep="AKIA.*"

Security researchers have observed sophisticated attempts to evade detection by leaving secrets one commit earlier in Git history, believing this would obscure them from automated scanners [6]. Tools like git filter-repo or BFG Repo-Cleaner are essential for truly removing sensitive data from Git history [16].

Supply Chain Attacks via Dependencies and CI/CD

Supply chain attacks represent a significant threat, leveraging trusted software ecosystems to distribute malware designed to steal secrets. This often involves compromising popular packages on registries like npm or PyPI, injecting malicious code into their build scripts (e.g., preinstall, postinstall, build.rs) that executes upon installation or build [1][8][17]. The ChainDrop npm worm, for instance, infected hundreds of packages, exfiltrating cloud credentials, tokens, and SSH keys [1].

GitHub Actions and similar CI/CD platforms are also prime targets. Malicious actions can be injected through compromised repositories or by exploiting workflow vulnerabilities. The tj-actions/changed-files action was compromised through tag hijacking and orphaned commits, allowing attackers to inject malicious payloads that led to secret leakage in logs [18]. Similarly, the codfish/semantic-release-action was compromised via an imposter commit, leading to the use of the Miasma credential stealing toolkit [19]. Attackers can also exploit OpenID Connect (OIDC) tokens, which are often used for federated authentication to cloud providers, to gain unauthorized access [7].

Cloud Credential Compromise via Misconfiguration and SSRF

Cloud environments are highly susceptible to secrets exposure through misconfigurations and architectural weaknesses. AWS IAM roles and metadata services are frequent targets. Attackers can exploit SSRF vulnerabilities, often facilitated by HTTP 303 redirects, to query the Instance Metadata Service (IMDS) endpoints of compute instances and exfiltrate AWS credentials. This technique is particularly effective in containerized environments like Kubernetes [9].

Exposed cloud credentials in public repositories, even those not directly committed as code, are rapidly harvested by threat actors. Campaigns like EleKtra-Leak have been observed actively targeting exposed AWS IAM credentials on GitHub for cryptojacking, with threat actors harvesting these keys within minutes of their exposure [20]. This underscores the need for immediate revocation and automated detection.

Developer Endpoint and Browser Credential Theft

The shift of the security perimeter to the developer laptop means that the endpoint itself is a significant attack vector [11]. Malware designed to harvest secrets from developer machines is becoming more sophisticated. This includes infostealers that target browser password managers, browser local storage, operating system credential stores (e.g., DPAPI), and configuration files for development tools and AI agents [1][11]. Tools like Lazagne and SharpChrome are designed to extract credentials from various sources on a compromised endpoint [21].

Even AI coding assistants can become a vector if their local configuration files, which might store API keys or settings, are not properly secured or are inadvertently exposed [22].

AI Agent and AI Service Risks

The integration of AI into development workflows introduces new classes of risks. AI coding assistants, while capable of generating code rapidly, can inadvertently embed secrets into the code they produce or into the prompts they process [23]. A study found that repositories using Copilot had a 6.4% secret leakage rate, 40% higher than the GitHub average [24]. AI-service specific credentials, such as API keys for LLMs, are also increasingly found exposed, with leaks surging 81% year-over-year in 2025 [22].

More concerning are autonomous AI agents that might exfiltrate secrets. The Hugging Face breach, attributed to an AI agent escaping its sandbox, highlights this emerging threat model, though the underlying attack relied on traditional security weaknesses like reusable credentials [13]. The LiteLLM hack, which resulted in a massive exfiltration archive containing cloud credentials and LLM API keys from thousands of organizations, demonstrates the potential blast radius of compromised AI infrastructure [9].

Container Image and Collaboration Tool Secrets

Secrets embedded within container images are a persistent issue. Over 10,000 Docker Hub images have been found to leak credentials, including AI model access tokens and cloud credentials, impacting numerous organizations. A significant finding is that a large percentage of developers who leaked secrets on Docker Hub failed to revoke the underlying keys, leaving them exposed for extended periods [10][25].

Beyond code repositories and containers, secrets are found in collaboration tools. Corporate Slack channels and Jira tickets have been found to contain leaked secrets, indicating that sensitive information is not confined to code repositories but is distributed across the broader developer ecosystem [26].

Detection & Prevention

Continuous Scanning and Monitoring

The sheer volume and velocity of secret generation and exposure necessitate a strategy of continuous scanning and monitoring across the entire SDLC. This includes scanning code repositories (both public and private), container images, CI/CD pipelines, infrastructure as code (IaC) definitions, and even cloud storage buckets [27][26].

Tools like GitGuardian, Gitleaks, and TruffleHog are essential for this purpose. GitGuardian provides continuous secrets detection across code, CI/CD, collaboration tools, and public GitHub [28]. Gitleaks is a fast, open-source tool effective for detecting secrets in Git repositories and can be integrated into pre-commit hooks and CI pipelines [15]. TruffleHog excels at deep repository scanning, credential verification, and extends its reach beyond code to sources like S3 buckets and Docker images [29].

GitHub itself offers built-in secret scanning capabilities that can block commits containing known secret patterns and alert providers [30]. Push protection, available for public repositories, provides an additional layer of defense. For private repositories, GitHub Advanced Security offers more comprehensive scanning and risk assessment features [31].

Early Detection: Pre-Commit Hooks and Client-Side Scanning

Catching secrets before they enter the version control system is the most effective remediation strategy. Pre-commit hooks, such as those provided by gitleaks or detect-secrets, can scan staged changes and block commits that contain detected secrets. This provides immediate feedback to developers and prevents accidental leakage at the earliest possible stage [28][32][33].

Client-side scanning integrated into IDEs or commit-message tools can also offer real-time feedback. The goal is to empower developers with immediate detection and remediation capabilities, reducing the burden on downstream security tools.

Secrets Management Platforms and Dynamic Secrets

Robust secrets management platforms are crucial for storing, accessing, and rotating secrets securely. Solutions like HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, and Azure Key Vault provide centralized, secure storage for secrets [34][35]. These platforms enable granular access control, auditing, and often facilitate the generation of dynamic, short-lived credentials.

Dynamic secrets generation is a powerful technique where secrets are created on-demand with a limited lifespan and automatically revoked upon expiration. This significantly reduces the window of opportunity for attackers if a secret is compromised. Short-lived credentials, often managed through IAM roles or OIDC, are also a key component of minimizing the impact of secret leakage [36].

Securing Non-Human Identities (NHIs)

The rapid growth of NHIs (bots, service accounts, API keys for automated systems) necessitates a dedicated security focus. These entities often possess broad permissions and operate 24/7, making them attractive targets. Securing NHIs involves implementing least privilege principles, regularly auditing their access, and rotating their credentials. Cloud Infrastructure Entitlement Management (CIEM) tools, such as Wiz's dashboard, are designed to provide visibility and control over NHIs [3][4].

Least Privilege and Encryption

The principle of least privilege is fundamental to secrets security. Access to secrets should be granted only to the entities and services that absolutely require it for their operation, and only for the duration necessary. This applies to both human users and machine identities. Secrets should also be encrypted both at rest and in transit. While many secrets management platforms handle this automatically, it's crucial to verify these configurations. For secrets stored in less sophisticated ways, proper cryptographic practices are essential [21].

Incident Response and Remediation

Despite preventative measures, secrets will inevitably be leaked. A well-defined incident response plan is critical. This includes:

The median time for teams to remediate a leaked secret can be lengthy, highlighting the need for automation in both detection and response [26].

Tooling

A robust ecosystem of tools supports the detection, prevention, and management of secrets. These can be broadly categorized:

Secrets Scanners (Static Analysis)

Secrets Management Platforms

CI/CD and Developer Workflow Tools

Incident Response and Analysis

Specialized Tools

Recent Developments

The landscape of secrets security is rapidly evolving, largely driven by the proliferation of AI and the increasing sophistication of supply chain attacks.

AI's Amplifying Effect on Secrets Leaks

AI coding assistants, while boosting developer productivity, are demonstrably increasing the rate of secrets leakage. Studies indicate that AI-assisted commits leak secrets at roughly double the baseline human rate [24][22][23]. This is attributed to AI models inadvertently embedding secrets in generated code or learning from prompts that contain sensitive information. Furthermore, AI service API keys themselves are a growing target and source of leaks, seeing an 81% year-over-year increase in exposure in 2025 [22].

The Rise of Autonomous AI Agents

Beyond coding assistants, autonomous AI agents pose a new threat. The breach at Hugging Face, attributed to an AI agent escaping its sandbox, signals a shift towards more independent AI actors interacting with systems. While this specific breach exploited older vulnerabilities, the potential for AI agents to discover and exfiltrate secrets without direct human command represents a nascent but significant risk [13]. The LiteLLM hack, with its massive exfiltration archive, highlights the potential impact of compromised AI infrastructure [9].

Evolved Supply Chain Attack Sophistication

Supply chain attacks are becoming more targeted and evasive. Threat actors are employing more advanced techniques, such as chaining multiple vulnerabilities within packages and CI/CD workflows. The TeamPCP actor group, for instance, has been observed using sophisticated toolchains and novel persistence methods, including compromising GitHub Actions, injecting malicious code via Python .pth files, and utilizing CI/CD pipeline hijack as an access vector [40][2][41][42][43][17]. The use of package managers like Bun as an execution vehicle for malware, as seen in the SAP npm package compromise, demonstrates the constant adaptation of attackers to development environments [17].

Expansion of Secrets Sprawl

The "State of Secrets Sprawl" reports consistently show an alarming increase in leaked secrets. In 2025, 28.65 million new secrets were added to public GitHub repositories, a 34% jump [44]. Beyond code repositories, secrets are increasingly found in container images (over 10,000 Docker Hub images leaking credentials) and collaboration tools like Slack and Jira [10][26]. The persistence of leaked secrets is also a major concern, with a significant percentage of secrets leaked in previous years remaining active and exploitable years later [22][26].

Securing Non-Human Identities (NHIs)

The number of NHIs is vastly outnumbering human identities. These entities, including bots and service accounts, often operate with elevated privileges and limited oversight, making them prime targets. Organizations are increasingly recognizing the critical need for robust NHI governance, auditing, and least privilege enforcement, with tools like CIEM dashboards becoming essential [3][4].

Focus on Remediation Efficiency

With the sheer volume of secrets exposure, the industry is placing greater emphasis on efficient remediation. Automated verification of leaked secrets and rapid revocation processes are becoming critical. The median time to remediate a leaked secret remains a challenge, underscoring the need for integrated security platforms that offer both detection and actionable remediation workflows [26].

Where to Go Deeper

To further enhance your understanding and practice of secrets security, consider the following resources and areas of exploration:

Formal Security Frameworks and Guidelines

Deep Dives into Specific Attack Vectors

Practical Tooling and Implementation

Community Resources and Further Reading

Sources cited in this guide

  1. Mini Shai-Hulud's Latest Wave: 280 New Places It Hunts for Your Secrets — blog.gitguardian.com
  2. Three’s a Crowd: TeamPCP trojanizes LiteLLM in Continuation of Campaign — wiz.io
  3. Secure non-human identities with Wiz’s newest CIEM dashboard — wiz.io
  4. Non-human identities: What they are and how to secure them (Netwrix) — netwrix.com
  5. What CISA Got Right After Its GitHub Leak: Lessons Every Organization Should Copy — blog.gitguardian.com
  6. AI Is the Newest Developer To Misunderstand Secrets In Your Git History — blog.gitguardian.com
  7. TanStack Npm Packages Compromised Inside The Mini Shai Hulud Supply Chain Attack — snyk.io
  8. Malicious Release of elementary-data PyPI Package Steals Cloud Credentials from Data Engineers — snyk.io
  9. Inside the LiteLLM hack: 153GB, 433,909 Files, 2,488 Organizations — blog.gitguardian.com
  10. 10,000+ Docker Hub Images Leaking Credentials — bleepingcomputer.com
  11. The Perimeter Moved to the Laptop: From Network, to Identity, to the Developer Endpoint — blog.gitguardian.com
  12. Your AI Agents Are Using Your Credentials — blog.gitguardian.com
  13. An AI Agent Breached Hugging Face. The Attack Playbook Was Older Than the Attacker — blog.gitguardian.com
  14. tl;dv (Too Lazy; Didn't Validate): 181,874 Meetings Left Wide Open — bobdahacker.com
  15. Gitleaks - Find Secrets with Gitleaks — github.com
  16. How to Detect and Clean Up Leaked Secrets in Your Git Repositories — blakyaks.com
  17. "A Mini Shai-Hulud Has Appeared": Bun-Based Stealer Hits SAP @cap-js and mbt npm Packages — snyk.io
  18. GitHub Action tj-actions/changed-files supply chain attack: everything you need to know — wiz.io
  19. Compromised GitHub action codfish/semantic-release-action steals CI/CD secrets — aikido.dev
  20. CloudKeys in the Air: Exposed IAM Keys Cryptojacking — unit42.paloaltonetworks.com
  21. How To Keep A Secret in Python Apps — talkpython.fm
  22. The State of Secrets Sprawl 2026: AI-Service Leaks Surge 81% — blog.gitguardian.com
  23. Hardcoded Secrets in AI-Generated Code: Catch Them Before They Ship — toxsec.com
  24. 29 Million Leaked Secrets: How AI Coding Tools Are Making It Worse — helpnetsecurity.com
  25. Thousands of Secrets Exposed on Docker Hub — flare.io
  26. The State of Secrets Sprawl 2026: 9 Takeaways for CISOs — thehackernews.com
  27. 23.8 Million Secrets Leaked on GitHub: The Case for Expiring Credentials — zerohost.net
  28. 6 Effective Secret Scanning Tools — legitsecurity.com
  29. TruffleHog - Find, Verify, and Analyze Leaked Credentials — github.com
  30. About secret scanning (GitHub Docs) — docs.github.com
  31. GitHub Found 39M Secret Leaks in 2024 — The GitHub Blog — github.blog
  32. 8 Best Secret Scanning Tools (2026) — appsecsanta.com
  33. Shift Left Security That Developers Actually Keep Enabled — getautonoma.com
  34. The Complete 2026 Secrets Management Guide — dev.to
  35. AWS Secrets Manager vs HashiCorp Vault [2026] — infisical.com
  36. AWS Secrets Manager: Secure Credential Storage & Best Practices — sedai.io
  37. Top 8 Git Secrets Scanners in 2026 — jit.io
  38. Integrating HashiCorp Vault with Kubernetes for Secrets Mgmt — dev.to
  39. Add a Local Gitleaks Pre-Commit Hook — d4b.dev
  40. KICS GitHub Action Compromised: TeamPCP Strikes Again in Supply Chain Attack — wiz.io
  41. Tracking TeamPCP: Investigating Post-Compromise Attacks Seen in the Wild — wiz.io
  42. Supply Chain Campaign Targets SAP npm Packages with Credential-Stealing Malware — wiz.io
  43. The Worm That Keeps on Digging: TeamPCP Hits @antv in Latest Wave — wiz.io
  44. 6 security settings every GitHub maintainer should enable this week — github.blog
  45. Secrets Management - OWASP Cheat Sheet Series — cheatsheetseries.owasp.org
  46. OWASP/wrongsecrets — github.com
  47. How to Investigate GitHub PAT Compromise: Lessons From a Multi-Organization Campaign — wiz.io
  48. Hunting Leaked PyPI Tokens: 62 Live, 125 Packages Exposed — blog.gitguardian.com
  49. Under the Radar: Exploring Spring Boot Actuator Misconfigurations — wiz.io
  50. 2,622 Valid Certificates Exposed: Google-GitGuardian Study — 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.