New: Cycode Offensive Security. Know what’s exploitable. Prove it’s fixed.

Explore the launch

Blog

CI/CD pipeline security: Best practices beyond build and deploy

13 MIN

CI/CD Pipeline Security: Best Practices Beyond Build and Deploy blog cover

What Is CI/CD Pipeline Security?

CI/CD pipeline security is the practice of protecting the systems that build, test, and deploy your software, including source control, build runners, pipeline configuration, secrets, and the third-party actions and packages your builds pull in. The goal is to stop attackers from using the pipeline to steal credentials or ship malicious code to production. The core practices are least-privilege access, short-lived credentials, pinned and verified third-party components, automated scanning on every change, and signed, traceable builds.

Pipelines are a prime target because they hold the keys to production. A single compromised build step can expose every secret the pipeline touches and push tampered code to every customer downstream. This guide covers how pipelines are exposed, the most common CI/CD security risks with recent examples, and the best practices that reduce them without slowing delivery.

Key Highlights

  • CI/CD pipeline security protects the delivery system itself, not just the code moving through it.
  • The biggest risks are leaked credentials, compromised third-party actions and packages, poisoned pipeline execution, over-permissive tokens, and weak access controls, which map closely to the OWASP Top 10 CI/CD Security Risks.
  • High-impact fixes include pinning third-party actions to a commit SHA, replacing long-lived secrets with OIDC, restricting default token permissions, and scanning every pull request.
  • Cycode correlates pipeline, secrets, SAST, and SCA findings so teams can fix the risks that actually reach production first.

What Is a CI/CD Pipeline?

A CI/CD pipeline is the automated path code takes from commit to production. CI (continuous integration) merges and tests every change as it lands, and CD (continuous delivery or deployment) packages tested code and releases it. Because the pipeline touches source code, secrets, build systems, and production credentials, it is also one of the most valuable targets in your software supply chain.

What is continuous integration (CI)?

Continuous integration acts as the first checkpoint, automatically merging code changes and triggering automated tests to ensure the new code integrates seamlessly with the existing codebase. This helps ensure errors and regressions are identified and addressed early in the development process.

Shift to AI podcast hosted by Roland Cloutier. Listen nowShift to AI podcast hosted by Roland Cloutier. Listen nowShift to AI podcast hosted by Roland Cloutier. Listen now

What is continuous delivery(CD)?

Continuous delivery then takes over, packaging and staging tested code for deployment. Continuous Deployment, an extension of Continuous Delivery, goes a step beyond by automatically deploying code changes directly into production, provided they pass all necessary tests. 

Importantly, the CI/CD pipeline is a crucial component of the software supply chain, and plays a significant role in the “build and release” stages. 

What is an Example of a CI/CD Pipeline?

While every pipeline is unique, tailored to specific tools, environments, and deployment strategies, it’s helpful to see a simplified example to understand how the process works. Keep in mind that real-world pipelines may include more complex steps.

For the below example, let’s imagine you’re building a web application using Node.js. You’re using GitHub for version control and a basic CI/CD pipeline to automate your workflow from code changes to production deployment.

Step 1: Trigger 

The pipeline begins when a developer pushes code to the main branch of the GitHub repository. This automatically triggers the CI/CD workflow, eliminating the need for manual intervention.

Where it’s exposed: if workflows triggered by pull requests can read secrets, anyone who can open a PR may be able to run code with them (poisoned pipeline execution).

Step 2: Build Stage

The pipeline fetches the latest code and installs the required dependencies. From there, the pipeline checks out the code and it installs dependencies using npm install. This ensures that the application is ready to run in the next steps.

Where it’s exposed: third-party actions, plugins, and packages fetched at build time run with the pipeline’s permissions.

Step 3: Test Stage

Once the application is built, automated tests are run to ensure the code is working as expected. Unit tests are executed to validate individual components of the application. At the same time, integration tests may run to verify how different parts of the app work together.

Where it’s exposed: test jobs often inherit the same secrets as deploy jobs, even though they don’t need them.

Step 4: Deploy to Staging 

Before deploying to production, the application is deployed to a staging environment for further testing or manual QA.

The application is packaged and deployed to a temporary staging server and QA engineers (or automated tests) verify functionality in an environment similar to production.

Where it’s exposed: long-lived cloud keys stored as pipeline secrets are a high-value target if they leak.

Step 5: Deploy to Production

If the staging tests pass, the pipeline automatically deploys the application to the production environment. In this case, the application is uploaded to a cloud platform like AWS, Azure, or Google Cloud.

From there, the production deployment is monitored to ensure it runs smoothly.

Where it’s exposed: without signed artifacts and build provenance, you can’t prove that what’s running came from your pipeline.

 

Key Elements of a CI/CD Pipeline

In the example above, you’ll notice several key elements of a CI/CD pipeline. These components enable the pipeline to function effectively and define what is required to implement a pipeline.

These elements are automated in the following sequence:

  1. Trigger: Starts the process based on code changes.
  2. Build: Ensures the code compiles and dependencies are installed.
  3. Test: Runs tests to validate functionality.
  4. Deploy: Moves code to staging or production.
  5. Monitor: Tracks performance and stability.

While key elements answer “What do we need to build a pipeline?”, the stages answer “How does the pipeline execute software delivery?” With that in mind, let’s take a closer look at the stages. 

See Cycode in action. Book a demoSee Cycode in action. Book a demoSee Cycode in action. Book a demo

CI/CD Pipeline Stages

CI/CD pipelines have several distinct stages. Each stage plays a crucial role in the software development lifecycle (SDLC). If you want to implement robust security measures throughout the pipeline, you first have to understand the stages.

CI/CD pipeline stages

Why Is CI/CD Security Important?

CI/CD pipelines are attractive targets. Attackers go after them to steal credentials or to tamper with code that ships to every downstream customer. From code commit to production, every stage is a possible target, and even well-written code is at risk if the pipeline that builds it is compromised. Recent incidents show how much damage one compromised pipeline component can do:

  • tj-actions/changed-files (March 2025): attackers modified a popular GitHub Action used in more than 23,000 repositories so that it printed CI secrets into workflow logs (CVE-2025-30066). See our breakdown of GitHub Actions supply chain attacks.
  • Shai-Hulud (September 2025): a self-replicating npm worm stole developer and CI tokens, then used them to publish infected versions of other packages.
  • GhostAction (September 2025): attackers pushed malicious workflows to hundreds of GitHub repositories and exfiltrated more than 3,000 secrets.
  • Codecov (2021): a modified script in Codecov’s CI tooling exposed credentials from customers’ build environments, as covered in this report on the Codecov breach.

These breaches cost organizations millions, erode customer trust, and can hit every customer downstream of the compromised build. 

Let’s explore a few other common CI/CD security vulnerabilities before identifying solutions to help you protect your end-to-end SDLC.

Common CI/CD Security Risks 

Secret Leaks

Sometimes developers inadvertently commit code containing secrets like API keys, passwords, or cryptographic keys. Attackers can exploit these exposed secrets and gain unauthorized access to critical systems and services. 

This happened in 2017 to Uber, when their GitHub repository was accidentally exposed. The repository contained access credentials. Attackers discovered and exploited these credentials to gain unauthorized access to Uber’s AWS account, compromising the personal data of nearly 60 million users.

Supply Chain Attacks

Supply chain attacks target the dependencies and components used in the CI/CD pipeline. For example, an attacker might inject malicious code into a commonly used library or compromise a package manager, leading to the distribution of tainted software. That means it’s not just the targeted organization that’s affected. Customers, suppliers, partners, and other third-parties are too.

When organizations unknowingly incorporate these compromised dependencies into their CI/CD pipelines, attackers gain a foothold and can wreak havoc.

One of the most notable recent examples of a supply chain attack happened in 2020 when malicious actors compromised the SolarWinds software build process, injecting a backdoor into their Orion software updates. Organizations then unknowingly installed the compromised updates, leading to widespread breaches and unauthorized access to sensitive networks.

More recently, the Shai-Hulud worm (2025) showed the same pattern at registry scale, spreading through npm by stealing publishing tokens from developer machines and CI environments.

Compromised Third-Party Actions and Plugins

Most pipelines run code written by people outside your organization: GitHub Actions, Jenkins plugins, and build tools fetched at runtime. When those components are referenced by a mutable tag like v4, an attacker who compromises the maintainer can repoint the tag to malicious code, and every pipeline using it runs that code on its next build. This is how the tj-actions/changed-files compromise reached thousands of repositories in March 2025.

Poisoned Pipeline Execution (PPE)

PPE happens when an attacker who can change pipeline configuration or the files a pipeline executes, often just by opening a pull request, gets their own commands to run inside the build with its secrets and permissions. Workflows that run untrusted pull request code with elevated tokens are the most common way in.

Misconfigurations

Misconfigurations in CI/CD tools, scripts, or infrastructure settings can expose vulnerabilities that attackers can exploit. This may include improperly configured access controls, insecure default settings, or mismanaged permissions. This may allow unauthorized users to view or modify sensitive code and configurations, compromising the overall security of the pipeline.

Code Injection

Code injection involves the introduction of malicious code into the CI/CD pipeline, potentially leading to unauthorized code execution or the introduction of vulnerabilities into the software being developed.

This is exactly what happened in 2021 when a malicious script was injected into Codecov’s CI/CD process. The compromised script exposed credentials, enabling attackers to exfiltrate sensitive information from the CI/CD environment and compromise the code repositories of multiple organizations.

Insufficient Access Controls

Weak or insufficient access controls can lead to unauthorized access to critical components of the CI/CD pipeline. This could enable them to modify code, insert malicious scripts, or compromise the pipeline’s integrity, posing a significant security risk.

This happened to LastPass in 2022 when attackers gained access to portions of their source code and proprietary technical information in their development environment. They then used this information to launch a series of attacks, including one targeted at a senior DevOps engineer with high-level security authentication.

Eventually, they stole the engineer’s master password, and gained access to encrypted secure notes and decryption keys, which opened the door to critical database backups.

This list is just a few examples of the thousands of attack paths that could lead to a compromised CI/CD pipeline. Hungry for more? The research team at NCC Group shares 10 examples of sophisticated attacks they’ve executed in this article. 

Your complete Post-Mythos toolkit. Learn moreYour complete Post-Mythos toolkit. Learn moreYour complete Post-Mythos toolkit. Learn more

CI/CD Pipeline Security Best Practices

The following best practice tips will help reduce the likelihood of a breach. Note: It’s important to consistently reevaluate your posture to keep up with evolving security standards and emerging threats.

For more tips, check this joint memo from the NSA and CISA.

Access Control

Proper access controls (including roles, permissions, and authentication mechanisms) are critical in preventing unauthorized access and manipulation of CI/CD pipelines. By limiting access to only those people who need it and enforcing the principle of least privilege, organizations can reduce the risk of malicious activities.

Code Scanning

By integrating automated code scanning into the CI/CD pipeline, issues like known vulnerabilities or common application security risks can be detected and addressed before vulnerable code is deployed. This reduces the risk of introducing vulnerabilities into the production environment.

Vulnerability Management

Stay ahead of potential threats and ensure your pipeline remains resilient by proactively identifying, prioritizing, and mitigating security vulnerabilities in software and infrastructure components. This includes regularly scanning for vulnerabilities, assessing their severity, and implementing measures to remediate or mitigate the risks.

Secure Environment Configurations

Misconfigurations can lead to security vulnerabilities, as we saw with Uber. That means properly configuring the settings for servers, containers, databases, and other components is crucial for preventing potential exploits.

Some top tips to avoid misconfigurations:

  • Limit access and permissions using least privilege policies
  • Use a secure and centralized method for managing environment variables
  • Keep all CI/CD components up-to-date with the latest security patches

Pin Third-Party Actions to a Commit SHA

Reference every third-party action by its full commit SHA instead of a version tag, and update pins deliberately. Tags can be moved; a commit SHA can’t.

Replace Long-Lived Secrets with OIDC

Use OpenID Connect so jobs request short-lived cloud credentials at runtime instead of storing static keys as pipeline secrets. A leaked token then expires in minutes, not months. See how OIDC tokens improve CI/CD security.

Restrict Default Token Permissions

Set the pipeline’s default token to read-only and grant write access per job only where needed. Avoid running untrusted pull request code in workflows that have access to secrets.

Harden Build Runners

Prefer ephemeral runners that are destroyed after each job, keep self-hosted runners away from public repositories, and limit outbound network access from builds. Our guide to CI/CD build hardening covers this in depth.

Sign Builds and Generate Provenance

Sign artifacts and record build provenance (for example, following SLSA) so you can verify that what reaches production came from your pipeline and wasn’t altered on the way.

Collaboration Between DevOps and Security Teams

Effective collaboration between DevOps and security teams ensures that security is not treated as an afterthought and is embedded throughout the CI/CD process. Unfortunately, 76% of security professionals find implementing a culture of collaboration between security and developer teams challenging.

So how can teams foster a better working relationship? Buy-in and commitment from the top, training, and incentivization all help. The best method is what we call controlled shift left. 

Under this model, security teams remain laser focused on reducing vulnerabilities, while also being mindful of the impact that fixing defects has on developers. This way, the two teams work together to build processes and workflows that work for everyone. With controlled shift left, developers maintain velocity, while security protects pipelines, improving the organization’s security posture.

Tools/Technology

The right tools and technologies can automate security processes, streamline vulnerability detection, and enforce security policies. Integrating these tools into CI/CD pipelines enhances the efficiency of security measures.This enables organizations to identify and address security issues while maintaining the pace of continuous delivery. 

Dozens of tools (SAST, SCA, secrets scanning, and dedicated CI/CD security tools) each cover part of the pipeline, but none covers all of it on its own. Application Security Posture Management (ASPM) brings their findings together, so teams can see which risks actually reach production and fix those first.

Complete ASPM offers continuous security in and of the pipeline, ingesting data from multiple sources throughout the software lifecycle and giving security teams an ongoing, real-time view of their risk. Issues are faster and easier to detect, respond to, and remediate. 

A complete ASPM solution is one that provides a suite of application security testing tools like SCA and SAST, delivers CI/CD security, and ingests data from other third-party scanners.

How Cycode Can Help 

Cycode is the leader in Agentic Development Security that secures AI development from prompt to cloud. Through unifying control, context, and autonomy in a single platform, Cycode continuously identifies risk across the AI development lifecycle, governs the AI tools developers use, correlates context across the entire software factory, and deploys and manages agents to prevent risk at AI speed.

By offering a single, unified security platform that correlates pipeline security, secrets scanning, code leak detection, SAST, SCA, and IaC scanning, Cycode gives security teams and developers peace of mind. 

Book a demo to see the platform in action, or compare options in our CI/CD security tools buyer’s guide.

See Cycode in actionBook a demo

FAQ

Frequently asked questions

What are the OWASP Top 10 CI/CD Security Risks?

The OWASP Top 10 CI/CD Security Risks are: insufficient flow control mechanisms, inadequate identity and access management, dependency chain abuse, poisoned pipeline execution, insufficient pipeline-based access controls, insufficient credential hygiene, insecure system configuration, ungoverned usage of third-party services, improper artifact integrity validation, and insufficient logging and visibility. Government guidance points the same way, see the CISA and NSA CI/CD threats and NIST SP 800-204D.

What is poisoned pipeline execution (PPE)?

Poisoned pipeline execution is when an attacker who can change code or configuration in a repository makes the CI system run malicious commands, for example by editing the pipeline file in a pull request or planting commands in a script or Makefile the pipeline calls. Because the pipeline runs with access to secrets and production systems, PPE can lead straight to credential theft. Our research team has found these flaws in the pipelines of popular open source projects.

How do you secure GitHub Actions workflows?

Pin third-party actions to a full commit SHA rather than a tag, set the GITHUB_TOKEN to the minimum permissions each job needs, avoid checking out untrusted pull request code in pull_request_target workflows, and never pass untrusted input such as issue titles directly into run steps. Review every third-party action as you would a dependency. Our guide to GitHub Actions supply chain attacks explains how these attacks work.

How should secrets be managed in CI/CD pipelines?

Keep secrets out of code and pipeline files, store them in a secrets manager or the platform's encrypted secret store, scope each secret to the jobs and environments that need it, and prefer short-lived credentials over static keys. Mask secrets in logs and scan repositories and build logs for leaks. See our secrets management best practices and how build systems can expose secrets.

What is OIDC in CI/CD and why should I use it?

OpenID Connect (OIDC) lets a pipeline job prove its identity to a cloud provider and receive a short-lived access token, so you no longer store long-lived cloud keys as pipeline secrets. Tokens expire within minutes and can be restricted to a specific repository, branch, or environment. Read our guide to OIDC tokens for cloud authentication.

What is SLSA and how does it apply to CI/CD pipelines?

SLSA (Supply-chain Levels for Software Artifacts) is a framework of increasing levels that describe how trustworthy a build is. In CI/CD it means generating signed provenance for every artifact, building on hardened and isolated build platforms, and verifying provenance before deployment. Learn more in SLSA 1.0 explained.

How do you secure CI/CD build runners?

Use ephemeral runners that are created fresh for each job and destroyed afterward, isolate runners per project or trust level, never attach self-hosted runners to public repositories, and limit their network access. Runtime monitoring of the build itself can catch tampering that static checks miss, as described in our guide to CI/CD build hardening and the open source Cimon project.

Which security checks belong in a CI/CD pipeline?

At minimum: SAST, SCA, and secrets scanning on every pull request, IaC and container scanning at build time, and DAST against staging. Add pipeline configuration checks for the CI system itself. Our guides on integrating security testing into CI/CD and the CI/CD security tools buyer's guide cover each one, and Cycode's CI/CD security brings them together.

How do you add security checks without slowing down pipelines?

Scan only the changed code on pull requests, block merges only on high-confidence critical findings, run slower full scans asynchronously, and route everything else to the owning team as a ticket. Automation helps here: Agentic Workflows can triage findings and open fixes when risk appears, inside boundaries the security team sets, so developers are not stuck waiting on manual review.