Skip to main content

Dependency Security

Dependency security means keeping the third-party packages used in a project safe, updated, monitored, and locked properly.

In frontend projects, we commonly install many packages using npm. If any package or its internal dependency has a vulnerability, it can create security risk for the whole application.

One-line idea: Dependency security means auditing, updating, monitoring, locking, and scanning dependencies so the application stays safe and builds remain stable.

Core Concepts​

What It Is​

Dependency security focuses on protecting the project from risks that come from external libraries and packages.

A frontend project usually depends on:

  • direct dependencies installed by the developer
  • indirect dependencies installed by those packages
  • build tools and scripts
  • security scanning tools
  • package lock files

The goal is simple:

Install packages safely
Audit them regularly
Monitor them continuously
Lock versions for stable builds
Use tools to find hidden vulnerabilities

Why It Matters​

Dependencies can create security and stability problems when they are not managed properly.

Main reasons dependency security matters:

ReasonMeaning
Vulnerable packagesSome installed packages may contain known security issues
Frequent version changesNew installs may resolve different dependency versions
Build failuresUncontrolled dependency updates can break pipelines
Hidden transitive risksA package may depend on another vulnerable package
Manual checking is hardLarge projects need tools for continuous monitoring

In real projects, dependency security is important because every package becomes part of the application supply chain.

Core Flow​

A simple dependency security flow looks like this:

Install dependency
↓
Audit dependency
↓
Fix or update vulnerable packages
↓
Lock dependency versions
↓
Monitor continuously using tools
↓
Run security testing before release

Main Security Areas​

The PDF explains dependency security using these main areas:

AreaPurpose
Regular audit of dependenciesFind vulnerabilities in installed packages
Enforcing auditingAutomatically run audit checks during install/update
Code and dependency monitoringContinuously monitor project dependencies and code
Dependency lockingKeep dependency versions stable across builds
Security penetration testing toolsUse tools to find security issues beyond dependency checks

Practical Examples​

Regular Audit of Dependencies​

Regular auditing means checking installed packages for known vulnerabilities.

Common commands:

npm audit

This checks the project dependencies and reports known security vulnerabilities.

npm update

This updates dependencies where possible.

npm audit --json

This can generate a more detailed audit report that can be stored or reviewed.

Simple mental model:

npm audit  -> find dependency issues
npm update -> update packages when needed
audit report -> review details properly

Enforcing Auditing​

Sometimes developers may forget to run audit manually. To avoid that, auditing can be enforced in the project setup.

Command:

npm set audit true

After this, whenever npm install or npm update runs, npm can automatically execute audit checks and highlight vulnerabilities.

Flow:

Developer runs npm install/update
↓
Audit runs automatically
↓
Vulnerabilities are highlighted
↓
Developer can fix/update dependency

This helps catch issues early instead of waiting for manual checks.

Code and Dependency Monitoring​

In some projects, teams do not run dependency checks daily. But they still want the project to stay safe and updated.

For this, monitoring tools can be used.

Code and Dependency Monitoring: Dependabot​

Dependabot is used for dependency monitoring.

In GitHub projects, a dependabot.yml file can be added to configure dependency checks at a specific time interval.

dependabot.yml
↓
Monitors dependencies
↓
Finds outdated or vulnerable packages
↓
Helps developers update them

Code and Dependency Monitoring: CodeQL​

CodeQL goes one step further.

It can monitor:

  • code
  • dependencies

In GitHub projects, this is usually configured using:

codeql-analysis.yml

Simple difference:

ToolFocus
DependabotDependency monitoring
CodeQLCode and dependency monitoring

Dependency Locking​

Dependency locking means fixing the exact versions of direct and indirect dependencies so that builds remain stable.

In npm projects, this is commonly done using:

package-lock.json

Why it is needed:

  • pipelines usually run when code is merged
  • frequent dependency changes can create unexpected errors
  • builds should be reproducible
  • the same input should resolve the same package versions

Without dependency locking:

npm install today  -> one dependency version
npm install later -> another dependency version

With dependency locking:

package-lock.json
↓
Locks direct dependencies
↓
Locks transitive dependencies
↓
Builds become more predictable

Dependencies should be updated only when needed and after proper checking.

Security Penetration Testing Using Tools​

Even if dependency auditing, monitoring, and locking are done properly, some security issues may still remain.

That is why security testing tools are useful.

The PDF mentions OWASP vulnerability scanning tools and common security tools like:

  • App Scanner
  • Burp Suite
  • Zed Attack Proxy

These tools help find issues that may not be visible only from package audits.

Simple flow:

Audit dependencies
↓
Monitor dependencies and code
↓
Lock versions
↓
Run security scanning tools
↓
Fix discovered vulnerabilities

Common Commands and Files​

Command / FilePurpose
npm auditChecks dependencies for vulnerabilities
npm updateUpdates dependencies
npm audit --jsonGenerates detailed audit output
npm set audit trueEnables automatic audit checks
dependabot.ymlConfigures dependency monitoring
codeql-analysis.ymlConfigures code and dependency analysis
package-lock.jsonLocks dependency versions

Summary​

Dependency security means auditing, updating, monitoring, locking, and scanning dependencies so the application stays safe and builds remain stable.

Audit -> Update -> Enforce -> Monitor -> Lock -> Scan

Or remember it like this:

npm audit finds problems
npm update fixes required packages
npm set audit true catches issues automatically
Dependabot monitors dependencies
CodeQL checks code and dependencies
package-lock.json makes builds stable
Security tools find deeper issues