Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for severity #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Example configuration below shows default option values and the correct syntax t
js: ['app/src/*.js'], /** Which js-files to scan. **/
node: ['node'], /** Which node directories to scan (containing package.json). **/
options: {
severity: 'all', //accepted values are all, none, low, medium, high, critical
proxy: 'http://something.something:8080',
verbose: true,
packageOnly: true,
Expand Down
35 changes: 33 additions & 2 deletions tasks/retire.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ module.exports = function (grunt) {
var output = {};
var scanedFile;

var levels = {
'none': 0,
'critical': 1,
'high': 2,
'medium': 3,
'low': 4,
'all': 9999
};
var severity = 0;

function taskVulnLogger(msg) {
var keyValue;
keyValue = scanedFile.slice(scanedFile.lastIndexOf('/') + 1);
Expand Down Expand Up @@ -54,6 +64,12 @@ module.exports = function (grunt) {
});
var logger = log(options);

// get numeric rank for severity
severity = levels['all'];
if('severity' in options) {
severity = levels[options.severity];
}

if (!options.nocache) {
options.cachedir = path.resolve(os.tmpdir(), '.retire-cache/');
}
Expand Down Expand Up @@ -95,9 +111,17 @@ module.exports = function (grunt) {
// log (verbose) options before hooking in the reporter
grunt.verbose.writeflags(options, 'Options');

vulnsFound = false;
// required to throw proper grunt error
scanner.on('vulnerable-dependency-found', function(e) {
vulnsFound = true;
e.results.forEach(function(result) {
result.vulnerabilities.forEach(function(vulnerability) {
var sev = vulnerability.severity;
if(levels[sev] <= severity) {
vulnsFound = vulnsFound | true;
}
});
});
});
var events = [];
function once(name, fun) {
Expand Down Expand Up @@ -185,7 +209,14 @@ module.exports = function (grunt) {

once('retire-done', function() {
if(!vulnsFound){
grunt.log.writeln("No vulnerabilities found.");
if(!options.severity) {
grunt.log.writeln('No vulnerabilities found.');
}
else if(options.severity === 'none') {
grunt.log.writeln('Vulnerabilities ignored with severity set to none.');
} else {
grunt.log.writeln("No " + options.severity + " vulnerabilities found.");
}
}
events.forEach(function(e) {
grunt.event.removeAllListeners(e);
Expand Down