Summary
cnpmcore registry endpoints can disclose upstream registry authentication tokens because they lack AdminAccess middleware. An unauthenticated attacker who obtains a token may replay it as a Bearer credential to access or publish packages upstream, depending on the token's permissions.
Affected context
The issue affects cnpmcore versions 3.46.0 before 3.84.3 and 4.0.0 before 4.37.3. The GET /-/registry and GET /-/registry/:id endpoints can expose upstream registry authTokens when requests are not protected by AdminAccess middleware.
Exploit preconditions
- Attack surface: The cnpmcore registry HTTP API, specifically the affected GET endpoints
- Required access: No authentication is required to request these endpoints
- Trigger point: A request to
/-/registryor/-/registry/:id - Why exploitation is possible: The endpoints lack AdminAccess middleware and can return upstream authentication tokens that may be replayed as Bearer credentials
Why this happens
The underlying issue is a missing authorization check on endpoints that expose sensitive credentials. This maps to CWE-306: Missing Authentication for Critical Function: access to registry configuration and its authTokens is not restricted to authenticated, authorized callers.
Potential impact
- An attacker may obtain upstream registry credentials
- Leaked tokens could allow package enumeration or downloads, subject to token permissions
- An attacker could publish or modify upstream packages if the token permits it
- Downstream users may be exposed to malicious or tampered packages
General mitigation guidance
Defensive measures generally focus on protecting secret-bearing endpoints and limiting the authority of credentials.
- Require authentication and appropriate authorization for registry configuration endpoints
- Avoid returning raw upstream tokens in API responses; expose only the minimum necessary information
- Apply least privilege and scope upstream credentials to required operations and packages
- Store and handle tokens through secure secret-management mechanisms, with rotation and revocation procedures
- Use secure-by-default access controls and treat registry configuration as sensitive data
How teams detect issues like this
Review route definitions and middleware chains for endpoints that return registry configuration or credentials. Static analysis and code review can flag sensitive response fields, routes without authentication or authorization checks, and inconsistent middleware coverage across related endpoints. Policy checks can require access controls on secret-bearing API routes, while monitoring can identify unexpected unauthenticated requests and upstream token use.

