Security Scanning Best Practices for CI/CD Pipelines

Dylan Reyes 10 min read

Putting a dependency scanner into CI and running it well are separate problems. Placement, the threshold that stops a build, and the handling of warnings rather than hard failures each change the outcome. Miss on any of them and a team either ships vulnerable code or trains itself to click past security alerts.

What follows covers the placement and policy calls that matter most. Integration details differ by tool and platform; gate placement, blocking thresholds, and remediation workflow stay much the same across tools.

Choosing gate positions

A dependency scan gate fits at four points: pre-install, scanning the manifest before packages are fetched; post-install, scanning the resolved lockfile or installed node_modules; pre-merge, as a pull request check; and post-merge, as part of the main branch build.

For supply-chain threats, pre-install is where the value concentrates, because it fires before lifecycle hooks can run. Behavioral anomalies in a package must be judged before installation, not after. Post-install scanning suits CVE findings, where the full resolved graph including transitive dependencies has to be examined.

Pre-merge scanning catches dependency changes before they land on main. Blocking belongs here: a PR that adds a critically flagged package should not merge until somebody reviews it. Each merge also ends up with a scan result attached, which makes a usable audit trail.

Post-merge scanning on main catches packages that passed at PR time and have been flagged since, either through a newly published CVE or an updated behavioral score. Run it on a schedule or on registry update events rather than only when code changes.

Blocking early or watching later

Pre-merge blocking gets attention, but it also generates the most developer friction when the false-positive rate runs high. A developer bumping a version who gets blocked over a theoretical low-severity finding will eventually learn to suppress or ignore the flags.

Post-merge monitoring with alerting irritates less and responds slower. Something flagged does reach main, and the team trusts the monitoring loop to catch it before production. Teams releasing often can live with that window. Teams deploying rarely may leave a main-branch flag sitting for days.

Layering the two works better. Pre-merge scanning blocks only on critical or high-severity findings; post-merge monitoring covers the wider set, informational and low-severity included. Blocking stays where risk is highest, and the post-merge layer handles volume as a queue rather than as individual PR blockers.

Thresholds that hold up

Poorly calibrated severity thresholds sink more security scan programs than any other cause. Block on everything, informational detections and low-severity findings with no realistic exploit path included, and blocked PRs pile up. Teams answer with a suppression policy or disable the gate.

A Node.js microservices team added a scan step that blocked on any finding. Two weeks later, more than 40 pull requests carried suppression notes, because misconfigured severity thresholds had made alerts meaningless to reviewers. The scan step existed on paper and provided no security value. It was eventually switched off.

A threshold policy that lasts splits findings three ways. Critical: behavioral anomalies, confirmed malicious packages, critical CVEs under active exploitation. These block the merge. High: high-severity CVEs in code paths actually in use, or behavioral signals not confirmed malicious. These require an acknowledgment before merge, overridable with written justification. The rest, low and informational, goes into a weekly-reviewed queue rather than a per-PR gate.

False positives without eroding trust

Behavioral scanning will produce false positives. Any scoring system built on pattern matching will flag a legitimate package now and then. The question is handling it without teaching engineers to dismiss every alert.

Resolution speed carries the most weight. A false positive that blocks a PR for two days while a review queue moves will breed more resentment than one acknowledged and suppressed within the hour. If a critical alert cannot get reviewed and cleared inside four business hours, either triage needs to speed up or that finding category needs a different threshold.

Write down every suppression: package, version, triggering signal, and the reason. The record shows where a package or signal class keeps generating false positives, and it holds up as an audit trail if the suppressed finding later proves real.

HuntedIabs attaches a confidence score to each detection, and that score feeds the default threshold logic. A high-confidence signal is treated differently from one where the behavioral pattern is suggestive but not conclusive. Human judgment is still required; the score just gives the reviewer what is needed to reach it quickly.

Deciding remediation before the alarm

When a critical finding is confirmed, the remediation path should already exist. CVE findings usually resolve through a version upgrade to a patched release, sometimes through replacing the dependency. Transitive dependencies complicate this: a flaw in a package nobody chose directly requires pinning that package's version or upgrading the direct dependency that drags it in.

Behavioral findings take a different route, since upgrading may change nothing. Options: hold the package until registry monitoring confirms or clears it, swap in an alternative without the same signals, or send it to the security team for manual code review before allowing the dependency.

A written policy that maps each finding category to a path takes the decision out of the pressured moment. A developer near a sprint deadline should not be weighing whether a behavioral finding is worth investigating or can be suppressed. That call belongs in the security policy, made in advance, with an escalation path for edge cases.

What latency the scan can justify

Three minutes added to every PR build, across a team merging 50 a day, comes to two and a half hours of aggregate pipeline time daily. Not enormous, but the scan has to earn it. If actionable findings show up only occasionally, that latency starts to look expensive against the output.

Some of this is tool infrastructure and some is placement. A pre-install manifest scan finishes in seconds because it reads the declared list, not the resolved tree. Full graph resolution that traces transitive dependencies to depth takes longer, typically 10 to 60 seconds for a standard Node.js application depending on dependency count. That is the scan most likely to catch supply-chain threats, and it costs real pipeline time.

Caching graph results against the lockfile hash helps. An unchanged lockfile means an unchanged resolved graph, so the full resolution can be skipped. Commits that leave dependencies alone cost close to nothing, while a changed dependency set still gets the full scan.

Where a gate earns its place

Not every pipeline stage needs to become a checkpoint. The aim is specific placement where a missed finding costs the most, not coverage everywhere, which produces reviewer fatigue and suppression policies. One well-calibrated pre-merge gate that blocks confirmed critical findings and routes high-severity ones to triage will catch more real threats than three poorly calibrated gates spread through the pipeline.

Teams getting the most from supply-chain scanning treated it as workflow design rather than tool deployment. The scanner is one part. Alert routing, threshold policy, the remediation runbook, and false-positive triage matter just as much. Without them, even a sophisticated scanner produces findings that get ignored.

The companion article on hardening GitHub Actions against supply chain threats deals with what happens when the pipeline tooling itself becomes the attack surface, which is the layer to take on after dependency scan gates are settled.

Back to Security Insights