This typosquatting attack on npm went undetected for 2 weeks

Lookalike npm packages grabbed stored credentials

A two-week-old campaign to steal developers' credentials using malicious code distributed through npm, the Node.js package management registry, has been halted with the removal of 39 malicious npm packages.

Developers regularly add these bundles of JavaScript code to Node.js applications to implement common functions, so they don't have to write the code themselves.

In a blog post published on Wednesday, CJ Silverio, CTO at npm, said that between July 19 and July 31, an account named hacktask conducted a typosquatting attack by publishing a series of packages with names that are similar to popular existing npm packages.

"In the past, it's been mostly accidental," Silverio said. "In a few cases we’ve seen deliberate typo-squatting by authors of libraries that compete with existing packages. This time, the package naming was both deliberate and malicious – the intent was to collect useful data from tricked users."

Oscar Bolmsten, a developer based in Sweden, spotted the malicious code in a package named crossenv, designed to dupe people searching for cross-env, a popular script for setting environmental variables.

"Because environmental variables are such common a way to hand credentials to software, it's a pretty good thing to go after," said Silverio in a phone interview with The Register.

Environmental variables are used for, among other things, storing the account names, passwords, tokens, and keys that provide access to applications, cloud services, and APIs.

In this case, the malicious code attempts to copy any environmental variables set on the victim's machine and to transmit them to an attacker-controlled server at

The JSON configuration file used by crossenv runs a script named package-setup.js that converts existing environmental variables into a string and then sends the data via POST request.

According to Silverio, "about 40" packages submitted by hacktask have been removed from npm. Lift Security, she said, scanned every npm package for the abusive package setup code but found no other instances of it.

Silverio expressed doubt that the attack worked very well. "Typo-squatting turns out not to be a very effective way to get malware into the registries," she said, noting that people tend to rely on searches or copying and pasting published code.

Among the 39 packages that npm has linked to hacktask, most had about 40 downloads each since mid-July, excluding the surge in curiosity-driven downloads once word of the malware got out. The malicious crossenv package had the most downloads, at 700. But most of these are believed to be automated downloads triggered by npm mirror servers.

Silverio estimates that only about 50 people downloaded the bad crossenv package during the exposure period. She said she's not aware of any developers who have reported account compromises as a result of this incident.

A search of GitHub repos turns up a handful of references to the malicious crossenv package.

The hacktask account has been banned but the person or persons behind the account have not been publicly identified.

Asked whether npm has put measures in place to prevent someone else from conducting a similar attack under a different account name, Silverio acknowledged that the attack probably wouldn't be caught immediately.

"Even if we can't catch it all at the moment of publication, we have a system that works pretty well," she said, praising the vigilance of the npm community.

Nonetheless, in her blog post, Silverio said npm is looking into ways to identify name similarities in packages, in order to prevent future typo-squatting. The company is also working with security firm Smyte to detect spam published to the registry – apparently, spammers publish packages hoping the README files will be indexed by search engines, in order to boost website search rankings.

In a 2016 presentation at Kiwicon about Node.js security, developer Jeff Andrews posed this question to himself: "I use Node.js/npm. How do I stay safe?" His answer: "You can't." ®

PS: Nikolai Tschacher wrote a thesis on typosquatting and programming language package managers in 2016.

Broader topics

Other stories you might like

  • World’s smallest remote-controlled robots are smaller than a flea
    So small, you can't feel it crawl

    Video Robot boffins have revealed they've created a half-millimeter wide remote-controlled walking robot that resembles a crab, and hope it will one day perform tasks in tiny crevices.

    In a paper published in the journal Science Robotics , the boffins said they had in mind applications like minimally invasive surgery or manipulation of cells or tissue in biological research.

    With a round tick-like body and 10 protruding legs, the smaller-than-a-flea robot crab can bend, twist, crawl, walk, turn and even jump. The machines can move at an average speed of half their body length per second - a huge challenge at such a small scale, said the boffins.

    Continue reading
  • IBM-powered Mayflower robo-ship once again tries to cross Atlantic
    Whaddayaknow? It's made it more than halfway to America

    The autonomous Mayflower ship is making another attempt at a transatlantic journey from the UK to the US, after engineers hauled the vessel to port and fixed a technical glitch. 

    Built by ProMare, a non-profit organization focused on marine research, and IBM, the Mayflower set sail on April 28, beginning its over 3,000-mile voyage across the Atlantic Ocean. But after less than two weeks, the crewless ship broke down and was brought back to port in Horta in the Azores, 850 miles off the coast of Portugal, for engineers to inspect.

    With no humans onboard, the Mayflower Autonomous Ship (MAS) can only rely on its numerous cameras, sensors, equipment controllers, and various bits of hardware running machine-learning algorithms to survive. The computer-vision software helps it navigate through choppy waters and avoid objects that may be in its path.

    Continue reading
  • Revealed: The semi-secret list of techs Beijing really really wishes it didn't have to import
    I think we can all agree that China is not alone in wishing it had an alternative to Microsoft Windows

    China has identified "chokepoints" that leave it dependent on foreign countries for key technologies, and the US-based Center for Security and Emerging Technology (CSET) claims to have translated and published key document that name the technologies about which Beijing is most worried.

    CSET considered 35 articles published in Science and Technology Daily from April until July 2018. Each story detailed a different “chokepoint” or tech import dependency that China faces. The pieces are complete with insights from Chinese academics, industry insiders and other experts.

    CSET said the items, which offer a rare admission of economic and technological vulnerability , have hitherto “largely unnoticed in the non-Chinese speaking world.”

    Continue reading

Biting the hand that feeds IT © 1998–2022