Skip to content

Instantly share code, notes, and snippets.

@rjz
Last active October 22, 2015 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjz/6c9ad04f884c1911790d to your computer and use it in GitHub Desktop.
Save rjz/6c9ad04f884c1911790d to your computer and use it in GitHub Desktop.
Scan node package dependencies for vulnerabilities
#!/bin/sh
# Check for vulnerabilities in package dependencies
#
# Script extracted from https://github.com/rjz/node-boilerplate
#
# Reference: http://blog.nodesecurity.io/2014/02/01/new-feature-validate-modules-with-npm-shrinkwrap
if [ ! -f 'npm-shrinkwrap.json' ]; then
echo 'Audit [FAIL]: Create npm-shrinkwrap.json by running:
$ npm shrinkwrap
'
exit 1;
fi
VULNERABILITIES=$(curl -s -XPOST \
-d@npm-shrinkwrap.json \
-HContent-type:application/json \
https://nodesecurity.io/validate/shrinkwrap)
size=${#VULNERABILITIES}
if [ "$size" -eq "2" ]; then
echo 'Audit [PASS]: no vulnerabilities found in listed dependencies!'
exit 0;
else
echo 'Audit [FAIL]: vulnerabilities discovered in shrinkwrapped dependencies!'
echo "$VULNERABILITIES"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment