Skip to content

fix(analyzer): compare hostname when matching npm trusted registry URLs - #760

Merged
abhisek merged 3 commits into
safedep:mainfrom
yuvrajnode:fix/lfp-npm-trusted-registry-port
Jul 30, 2026
Merged

abhisek merged 3 commits into
safedep:mainfrom
yuvrajnode:fix/lfp-npm-trusted-registry-port

Conversation

@yuvrajnode

@yuvrajnode yuvrajnode commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #759

npmIsTrustedSource compared the trusted URL's Host (port included) against the resolved URL's Hostname() (port stripped), so any trusted registry URL configured with an explicit port could never match — and the dedicated port comparison below it was unreachable.

This compares Hostname() on both sides and lets the existing port check do its job.

Tests: adds cases for matching port, mismatched port, trusted-has-port/source-doesn't, and port + base path. go test ./pkg/analyzer/... passes and go vet ./... is clean.

npmIsTrustedSource compared the trusted URL's `Host` (which includes the
port) against the resolved URL's `Hostname()` (which does not). Any
trusted registry URL configured with an explicit port could therefore
never match, and the dedicated port comparison a few lines below was
unreachable.

Effect: users pointing `trusted_registry_urls` at a self-hosted registry
on a non-default port (e.g. https://registry.internal:8443) had every
single package in package-lock.json reported as "resolved to an
untrusted host", making the lockfile poisoning analyzer unusable for
those setups.

Compare `Hostname()` on both sides and let the existing port check
handle the port. Adds test cases for matching port, mismatched port,
missing port, and port plus base path.

Signed-off-by: Yuvraj singh <yuvrajsinghrock1221@gmail.com>
@safedep

safedep Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@abhisek
abhisek enabled auto-merge (squash) July 30, 2026 13:26
@yuvrajnode

yuvrajnode commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Looks like the run-e2e / run-test workflows are waiting on maintainer approval. Happy to wait, just flagging in case it slipped by. @abhisek @KunalSin9h @sudhanshutech

@abhisek
abhisek merged commit 2ae1aaf into safedep:main Jul 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npm lockfile poisoning: trusted registry URLs with an explicit port never match

2 participants