Safeguard
General•

How to Build a Custom Dependency Remediation Policy That Blocks Vulnerable Code Without Breaking CI

Learn how to write deterministic dependency remediation policies that block critical vulnerabilities in your build pipeline without halting developer velocity.

Safeguard Team
5 min read

The Problem with Default Vulnerability Gates

Most continuous integration pipelines fail at dependency management because they treat security alerts as binary switches. A new CVE drops, a scanner flags a transitive dependency three layers deep in your package tree, and the entire build pipeline halts. Developers respond by disabling the scanner, adding blanket ignore directives, or routing every finding through a slow manual review queue.

A better approach is to treat remediation policies as code. Instead of relying on generic severity ratings that lack context, you can write deterministic policies that evaluate reachability, environment exposure, and patch availability before deciding whether to fail a build.

By the end of this post, you will know how to write, test, and enforce custom dependency remediation policies that block actual risk while letting unexploitable CVEs pass through your CI system.

Anatomy of a Remediation Policy

A proper remediation policy is evaluated against an internal dependency graph and a reachability index. It does not just look at a lockfile. It looks at whether the vulnerable function is actually imported and called by your application code.

A policy file consists of three core components: selectors, conditions, and actions. Selectors target specific packages or vulnerability classes. Conditions inspect metadata such as CVSS score, reachability status, fix availability, and direct versus transitive status. Actions determine what the pipeline should do, ranging from warning the developer to failing the build or automatically opening a pull request.

Here is what a complete remediation policy looks like in practice:

version: "1.0"
policies:
  - name: block-reachable-critical
    description: Fail the build if a critical vulnerability is reachable in production code.
    selectors:
      - ecosystem: npm
        package: "*"
    conditions:
      - field: cvss_score
        operator: gte
        value: 9.0
      - field: reachability
        operator: equals
        value: reachable
      - field: environment
        operator: equals
        value: production
    action: fail_build

  - name: warn-unreachable-transitive
    description: Warn on critical vulnerabilities if the code path is not reachable.
    selectors:
      - ecosystem: npm
        package: "*"
    conditions:
      - field: cvss_score
        operator: gte
        value: 9.0
      - field: reachability
        operator: equals
        value: unreachable
    action: warn

Step-by-Step Developer Journey: Implementing Policy Evaluation in GitHub Actions

To enforce this policy automatically on every pull request, you need to integrate the evaluation step into your existing CI workflow without adding significant latency.

Step 1: Generate the Dependency Graph

Before evaluating policies, your CI runner must generate a complete dependency tree for the project. For Node.js projects, this means parsing package-lock.json or yarn.lock. For Python, it means parsing requirements.txt or poetry.lock.

Add the following step to your GitHub Actions workflow file:

- name: Generate Dependency Graph
  uses: safeguard/dependency-graph-action@v1
  with:
    lockfile-path: './package-lock.json'
    output-path: './dependency-tree.json'

Step 2: Run Local Reachability Analysis

Scanning a lockfile tells you what is installed, but not what is executed. Reachability analysis scans your source code AST to determine if vulnerable symbols are referenced in import statements and function calls.

Run the reachability scanner against your codebase:

- name: Analyze Reachability
  uses: safeguard/reachability-action@v1
  with:
    source-path: './src'
    dependency-tree: './dependency-tree.json'
    output-path: './reachability-report.json'

Step 3: Evaluate the Custom Policy

With the dependency tree and reachability report generated, you can evaluate your custom remediation policy against the findings. This step reads your policy configuration file and checks every vulnerability match.

- name: Evaluate Remediation Policy
  uses: safeguard/policy-engine-action@v1
  with:
    policy-file: './security/remediation-policy.yaml'
    reachability-report: './reachability-report.json'
    fail-on-violation: true

If a violation matches an action set to fail_build, the action exits with a non-zero status code, stopping the pipeline and printing the exact reason directly to the workflow console.

Fix It Without Waiting for Upstream

Sometimes a vulnerability is flagged as reachable, but the upstream maintainer has not released a patch, or updating the package requires refactoring half your codebase. Waiting for upstream fixes halts feature development.

When you cannot update immediately, you have two local mitigation strategies you can enforce through your policy engine.

Strategy 1: Path Suppression via Policy Override

If your code imports the vulnerable package but never calls the specific vulnerable function, you can document and enforce a policy override. This is superior to a global ignore because it requires explicit justification and an expiration date.

Add an override block to your policy file:

overrides:
  - cve: "CVE-2026-XXXX"
    package: "lodash"
    reason: "Vulnerable function template() is not invoked in our execution path."
    expires: "2027-06-01"
    approved_by: "security-lead"

The policy engine checks the expiration date on every run. Once the date passes, the override automatically expires and the build begins failing again, preventing temporary suppressions from becoming permanent blind spots.

Strategy 2: Automated Patch Resolution and Pinning

If the vulnerability is in a transitive dependency that you do not control directly, you can use package managers' native resolution mechanisms to force a secure version. For npm, use the overrides field in your package.json file to enforce a safe version across the entire dependency tree.

{
  "name": "my-secure-app",
  "version": "1.0.0",
  "dependencies": {
    "express": "4.19.2"
  },
  "overrides": {
    "vulnerable-subpackage": "^2.1.4"
  }
}

By forcing the resolution at the root level, you eliminate the vulnerable code without needing to wait for the direct dependency maintainer to push a new release.

Measuring Policy Effectiveness

A good remediation policy reduces noise while maintaining security posture. Track three metrics after rolling out your custom policies:

  1. Build failure rate due to security alerts: This should drop significantly because unreachable vulnerabilities no longer block deployments.
  2. Mean time to remediation (MTTR): Developers resolve fewer, higher-confidence issues faster.
  3. Override expiration compliance: Ensure no temporary suppression outlives its review date.

When security tooling matches the precision of your engineering workflow, developers stop fighting the pipeline and start shipping secure code by default.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

We email you a link to confirm, and only then add you to the list. Unsubscribe in one click. Privacy

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.