mailparser 2.2.1, 2.2.2 and 2.2.3 on npm added a dependency leading to the getcookies backdoor, which let any visitor send commands, in April 2018.
npm found the chain and removed all of it the same day. The mailparser versions never called the new package.
What happened
An attacker hid a remote code execution backdoor in a chain of npm packages and added the chain to mailparser.
- The chain was
mailparsertohttp-fetch-cookiestoexpress-cookiestogetcookies. - The last package read HTTP request headers for a pattern of the form
gCOMMANDhDATAi. - The control code
0xfffereset a buffer. - The control code
0xfffaran the buffered code withvm.runInThisContext. - An Express app that used the module directly can run attacker code from a web request.
npm got the first report at 5:23 AM PDT. It removed the three malicious packages at 7:01 AM and the three mailparser versions at 7:26 AM.
Affected versions
mailparser2.2.1, 2.2.2, 2.2.3: removed from npm. Version 2.2.0 is clean.http-fetch-cookies,express-cookiesandgetcookies: all versions removed.- The mailparser versions did not use the module. Mailparser users were not exposed by the backdoor itself.
Indicators of compromise
- Any of the packages
getcookies,express-cookiesorhttp-fetch-cookiesinnode_modulesor in a lock file. - A mailparser entry at 2.2.1, 2.2.2 or 2.2.3 in a lock file.
- A
vm.runInThisContextcall in a package that has no reason to run code. - The publisher account
dustin87.
How to check
List the malicious packages in your dependency tree and check the mailparser version. An empty result for the first three packages means the chain is not installed.
npm ls getcookies express-cookies http-fetch-cookies mailparser grep -nE "getcookies|express-cookies|http-fetch-cookies" package-lock.json
What to do now
- Move mailparser to 2.2.0 or a later release that does not contain the chain.
- Delete
node_modulesand install again from a clean lock file. - Stop use of
getcookies,express-cookiesandhttp-fetch-cookies. - If an Express app used the packages directly, treat the server as exposed. Review the logs for odd request headers and rotate secrets.
What Vigilance would show
These examples show an install hold and the corresponding owner report.
Example install message
Vigilance blocked `mailparser` 2.2.1. This version is too new or changed in a way Vigilance must check first.
Example owner report
Bad update
mailparser 2.2.1
The email reader pulled in a hidden helper that let any visitor send commands and have them run.
No security team? See who reads the alert.
Frequently asked questions
Which mailparser versions had the getcookies backdoor?
Versions 2.2.1, 2.2.2 and 2.2.3. They depended on http-fetch-cookies, which depended on express-cookies and then getcookies.
Was mailparser itself exploitable?
According to the npm report, the mailparser versions did not use the module in any way. Apps that used the malicious packages directly were the real risk.
How do I check for getcookies in my project?
Run npm ls getcookies express-cookies http-fetch-cookies mailparser and search package-lock.json for the same names.
Sources
Send this page to the person who looks after AI at your company.