Script icon
Process icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

NPM Package Dependency Typosquatting Sentinel

Audits NPM package dependencies to detect typosquatting impostor packages and prevent malicious software supply-chain compromises.

Categories
CoreInfrastructure

Software supply-chain attacks increasingly rely on typosquatting, where attackers publish malicious packages with names nearly identical to popular libraries (such as loadash for lodash or expres for express). When developers make a typing error during package installation or automated dependency updates pull in malicious clones, unauthorized code executes inside build pipelines or production servers. This sentinel continuously parses application package manifests, computes string edit distances against popular open-source libraries, and alerts Application Security teams on Slack before malicious dependencies reach production.

How it works

  1. Scheduled triggering: Executes daily at 06:00 UTC using a cron schedule trigger (0 6 * * *) or triggers via CI/CD commit webhooks.
  2. Manifest ingestion: Fetches the specified package.json manifest via HTTP GET requests using optional repository authentication headers.
  3. Dependency parsing: Combines dependencies and devDependencies into a consolidated package catalog.
  4. String similarity analysis: Executes Levenshtein distance calculations between each project dependency and a curated database of popular NPM libraries.
  5. Condition evaluation: An io.kestra.plugin.core.flow.If task evaluates whether suspicious_packages_count exceeds max_tolerated_suspicious_packages.
  6. Slack notification: Sends high-priority incident details via SlackIncomingWebhook listing flagged dependencies and target libraries.
  7. Audit trail logging and return: Emits operational execution logs and returns a structured compliance manifest for auditing.

Architecture diagram

flowchart TD
  A[daily_dependency_audit Schedule Trigger] --> B[scan_npm_dependencies Python Script]
  B --> C[check_typosquat_findings Flowable If]
  C -- Typosquats Flagged --> D[notify_slack_appsec Webhook]
  C -- Safe Dependencies --> E[log_typosquat_audit Log]
  D --> E
  E --> F[export_typosquat_manifest Return]

Use cases

  • Software supply-chain defense: Detect and block accidental installation of malicious impostor packages across enterprise codebases.
  • CI/CD pre-merge gating: Trigger this workflow on pull requests modifying package.json to reject PRs introducing suspicious libraries.
  • Regulatory compliance: Demonstrate proactive open-source dependency auditing for NIST SP 800-218 and Executive Order 14028 software supply chain standards.

Inputs

Name Type Default Description
package_json_url STRING https://raw.githubusercontent.com/company/repo/main/package.json URL pointing to the raw package.json manifest to inspect for suspicious dependencies.
levenshtein_distance_threshold INT 1 Levenshtein distance threshold for flagging near-identical package names against popular libraries.
alert_on_typosquat_risk BOOL true Whether to dispatch alerts when suspected impostor package dependencies are detected.
max_tolerated_suspicious_packages INT 0 Maximum permissible suspicious package count before triggering high-severity alerts.

Expected outputs

  • {{ outputs.scan_npm_dependencies.vars.total_dependencies_scanned }}: Total number of dependencies analyzed in the manifest.
  • {{ outputs.scan_npm_dependencies.vars.suspicious_packages_count }}: Count of flagged packages matching popular libraries within the distance threshold.
  • {{ outputs.scan_npm_dependencies.vars.suspicious_packages_details }}: Serialized JSON list of flagged dependencies and target libraries.
  • {{ outputs.export_typosquat_manifest.value }}: Structured dictionary containing the consolidated security audit report.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to the manifest host (e.g., GitHub, GitLab, or internal Git servers).
  • Optional read access token for private source code repositories.
  • Slack Incoming Webhook configured for security alerts.

Secrets

  • GITHUB_READ_TOKEN: Personal access token with read permissions to private repository contents.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL used for sending security alerts.

Quick start

  1. Store GITHUB_READ_TOKEN and SLACK_WEBHOOK_URL in your Kestra Secret storage.
  2. Deploy this flow under the company.security namespace.
  3. Configure package_json_url to point to a target repository's raw package.json.
  4. Run a manual execution to test dependency extraction and verify Slack alerts.

Common pitfalls and troubleshooting

  • Scoped packages: Legitimate scoped packages (such as @types/lodash or @angular/core) contain slashes and scope prefixes. Ensure edit distance calculations evaluate root package names appropriately.
  • Private package namespaces: Internal enterprise libraries may share names with open-source forks. Adjust whitelist parameters or verify private registry scopes.
  • Raw URL authentication: For GitHub private repositories, use raw API endpoints (api.github.com/repos/{owner}/{repo}/contents/package.json) with an Authorization header.

How to extend

  • NPM registry download verification: Interrogate the official NPM registry API (https://registry.npmjs.org/{pkg}) to check package age and weekly download counts; typosquats typically have low downloads and recent publish dates.
  • Automated PR blocker: Integrate with GitHub status checks to block merging pull requests containing unverified dependencies.
  • Multi-manifest scanning: Expand to scan Monorepos containing multiple package.json files via a Kestra ForEach task.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.