Security News

Timing Attacks Via Npm API Discloses Custom Package Names

An npm timing attack can reveal an organization's private package names through 404 response times. See how it works and how to defend against fakes.

Brandefense logo Updated 3 Min Read
npm timing attacks

The npm timing attack lets an outsider find out which private package names an organization uses. The npm registry answers requests for private and non-existent packages with the same 404 error, but the response time reportedly differs. By testing guessed names, attackers can list private packages and then publish fake public packages with the same names.

What is the npm timing attack?

An attack method that reveals the names of special packages has been identified by researchers. Organizations create internal projects and custom packages of certain software products to keep their code and functionality private to minimize the risk of their development teams and inventories being exposed to targeted attacks.

The detected attack method includes a timing attack using the npm API. The npm Register API allows users to download existing packages and check for the existence of packages. When using the npm registry to download a package that does not exist or is set as private, the website returns a 404 HTTP error code stating that the package could not be found.

How does the timing attack reveal private package names?

The researchers used this feature to compare the response time of 404 HTTP errors with non-existent packets to check for the presence of custom packets they created in npm. As a result of the results obtained, it was observed that the response time to the request containing the name of an existing package was longer than the response time to the request made for the non-existent package. Therefore, threat actors can learn whether the package exists in the system through dictionary attacks by creating a list of possible package names for special packages used by institutions/organizations.

What can organizations do about exposed private package names?

After detecting the private packages of the organizations, the threat actors can create fake malicious packages with the same name and trick the public/organizational employees into downloading them. It is predicted that such an attack could be linked to wider supply chain attacks. In this context, it is recommended to take the following security measures in order to reduce the risk of attacks that can be carried out using the said method.

  • Organizations should take preventive measures by frequently searching npm for suspicious packages that spoof their custom packages with similar names,
  • Because npm doesn’t allow same-named packages to be installed in public repositories, organizations should create public packages that emulate their private packages as placeholders,
  • If similar packages are found, it should be ensured that they do not contain malware, and relevant stakeholders should be informed.

Frequently Asked Questions.

What is the npm timing attack?

It is a method that compares how long the npm registry takes to return a 404 error. Requests for an existing private package were reported to take longer than requests for a non-existent one, which reveals private package names.

Why do npm private packages need to be scoped?

According to npm documentation, private packages are always scoped and unscoped packages are always public. A scope also lets you use a name that another user or organization already uses without conflict.

Who can access an npm private package?

npm documentation says user-scoped private packages can only be accessed by you and collaborators you grant access to, and organization-scoped ones only by teams granted access.

How can organizations reduce the risk of fake packages with their private names?

The post advises searching npm often for look-alike packages, publishing public placeholder packages for private names, and checking any similar package for malware and informing stakeholders.

Sources

  1. 1 npm Docs: About scopes
  2. 2 npm Docs: About private packages
  3. 3 MITRE ATT&CK: Compromise Software Dependencies and Development Tools (T1195.001)
  4. 4 MITRE ATT&CK: Supply Chain Compromise (T1195)
Share