Safeguard
Developer Tools•

How do you configure Yarn registries safely with npmScopes and HTTPS?

Yarn routes packages with npmRegistryServer and npmScopes, requires HTTPS by default and strict SSL. How to scope private registries and avoid token leaks.

Safeguard Security Team
4 min read

In Yarn Berry, npmRegistryServer sets the default registry and npmScopes routes specific scopes to other registries, each with its own auth token. URLs must use HTTPS by default, enableStrictSsl is true by default, and npmAlwaysAuth stays false unless you point at a private mirror that needs credentials on every request.

The pieces

From the Yarn configuration reference:

SettingWhat it doesDefault or example
npmRegistryServerRegistry used when fetching packageshttps://registry.yarnpkg.com
npmScopesPer-scope registry configurationone block per scope name
npmAuthTokenToken for a registryset per registry or scope
npmAlwaysAuthSend credentials on every request to the registryfalse
npmAuditRegistryRegistry used for auditsfalls back to npmRegistryServer
enableStrictSslFail requests on SSL errorstrue
unsafeHttpWhitelistHostname globs where plain HTTP is allowedempty

The docs say the registry URL must use HTTPS by default, and the only way around it is the whitelist.

A private scope example

# .yarnrc.yml
npmScopes:
  my-company:
    npmRegistryServer: "https://npm.internal.example"
    npmAuthToken: "${INTERNAL_NPM_TOKEN}"

Packages under the my-company scope go to the internal host with its token. Everything else goes to the default registry. That routing is what keeps internal package names from being requested from the public registry, which is the setup that dependency confusion attacks rely on being absent. See npm scopes and package name collisions.

Keep the token in an environment variable, not in the committed file.

Do not weaken TLS

Two settings are tempting when a corporate proxy causes errors: adding a host to unsafeHttpWhitelist, and setting enableStrictSsl to false. The docs state that with strict SSL off, certificate errors are ignored. Either change lets anyone on the network path read or change what you download. Integrity hashes in the lockfile still catch altered tarballs, but they do not protect credentials sent in the clear, and metadata can be altered to steer resolution.

Better fixes:

  1. Install your proxy's certificate authority properly on the build machines.
  2. Use HTTPS on the internal registry.
  3. If you must allow HTTP for a legacy host, whitelist exactly that host with a comment, and plan its removal.

npmAlwaysAuth

The docs say this should not be needed unless you configured the registry to reference a private npm mirror. If you set it to true, credentials are sent with every request to that registry, so be sure the host is the one you intend. Do not set it for the public registry.

Audit registry

npmAuditRegistry defaults to your npmRegistryServer. If your internal mirror does not implement the audit endpoint, audits may fail or silently lack data, so confirm that your audit source is what you think. Our post on what yarn npm audit and pnpm audit check covers that.

A short review checklist

  1. Every internal scope has an entry in npmScopes.
  2. No literal tokens in committed files.
  3. enableStrictSsl is not set to false anywhere.
  4. unsafeHttpWhitelist is empty or minimal.
  5. CI installs from a clean checkout with the same settings.

Where Safeguard fits

Safeguard's dependency scanning and SBOM generation read your lockfile and record where each component resolved, and policies and gates can flag unexpected sources in a pull request. A free scan is at https://gold.safeguard.sh/scan.

Quick check

Does Yarn allow an HTTP registry by default?

No. The docs say the URL must use HTTPS by default, and the only exception is a host listed in unsafeHttpWhitelist.

Is it safe to set enableStrictSsl to false behind a proxy?

No. It makes Yarn ignore certificate errors. Install the proxy's certificate authority instead.

Sources

Last reviewed: 19 October 2026.

Never miss an update

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

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.