Skip to content

Commit c924d38

Browse files
v1.0.2
- Fixed issues with wildcards in signature paths - Improved error-handling in various places - Updated dependencies.
1 parent dda4bec commit c924d38

File tree

5 files changed

+67
-33
lines changed

5 files changed

+67
-33
lines changed

app/config.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const expand = require('expand-tilde');
2-
const glob = require('glob');
3-
const lodash = require('lodash');
4-
const rc = require('rc');
1+
const glob = require('glob');
2+
const rc = require('rc');
53

64
module.exports = function(options, config) {
75

@@ -13,7 +11,6 @@ module.exports = function(options, config) {
1311

1412
// HTML report date formatting
1513
dateFormat : 'D MMMM YYYY, hh:mm A',
16-
signatures : [],
1714
ignore : [],
1815
},
1916

@@ -26,26 +23,14 @@ module.exports = function(options, config) {
2623
config.glob = {};
2724

2825
// --ignore config override
29-
config.glob.ignore = (! lodash.isEmpty(options['--ignore']))
26+
config.glob.ignore = (options['--ignore'])
3027
? options['--ignore']
3128
: config.ignore ;
3229

33-
// process --signatures if provided
34-
if (! lodash.isEmpty(options['--signatures'])) {
35-
// do a glob search on --signatures to expand wildcards and such
36-
config.signatures = glob.sync(expand(options['--signatures']));
37-
}
38-
39-
// otherwise, load from the `.drekrc file`.
40-
else if (! config.signatures) {
41-
var signatures = [];
42-
config.signatures.forEach(function (file) {
43-
// do a glob search on --signatures to expand wildcards and such
44-
signatures = signatures.concat(glob.sync(expand(file)));
45-
});
46-
47-
config.signatures = lodash(signatures).sort().uniq().value();
48-
}
30+
// determine the signature paths
31+
config.signatures =
32+
(options['--signatures']) ? [ options['--signatures'] ]:
33+
(config.signatures) ? config.signatures : [] ;
4934

5035
// return the config object
5136
return config;

app/docopt.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ Examples:
2929
--signatures='/path/to/signatures/*.yml' \
3030
--ignore='node_modules' \
3131
./my-app > drek-scan.html
32+
33+
When using wildcards with --signatures, be certain to enclose the file paths
34+
within quotation marks to avoid unwanted behavior from the shell!

app/util-load-signatures.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,47 @@ const glob = require('glob');
33
const lodash = require('lodash');
44
const yaml = require('yamljs');
55

6+
67
module.exports = function (options, config) {
78

8-
// restructure the signatures into a hash
9-
var signatures = [];
9+
// resolve each signature glob into signature files
10+
var files = [];
11+
config.signatures.forEach(function (path) {
12+
files = files.concat(glob.sync(expand(path)));
13+
});
14+
15+
// sort and de-dup the files
16+
files = lodash(files).sort().uniq().value();
17+
18+
// throw an error is no files are specified
19+
if (lodash.isEmpty(files)) {
20+
throw new Error('No signatures were specified.');
21+
}
1022

1123
// iterate over each signature file
12-
config.signatures.forEach(function (file) {
24+
var signatures = [];
25+
files.forEach(function (file) {
1326

1427
// load each yaml file
15-
const yml = yaml.load(file);
16-
const filetypes = yml.filetypes;
28+
const yml = yaml.load(file);
1729

1830
// throw an error if a yaml file is invalid
1931
if (! lodash.isObject(yml)) {
2032
throw new Error(file + ' is not a valid YAML file.');
2133
}
2234

35+
// throw an error if a yaml file contains no filetypes
36+
if (lodash.isEmpty(yml.filetypes)) {
37+
throw new Error(file + ' contains no filetypes.');
38+
}
39+
2340
// throw an error if a yaml file contains no patterns
2441
if (lodash.isEmpty(yml.patterns)) {
2542
throw new Error(file + ' contains no patterns.');
2643
}
2744

45+
const filetypes = yml.filetypes;
46+
2847
// load the patterns
2948
yml.patterns.forEach(function (pattern) {
3049
signatures.push({

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drek",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A static-code-analysis tool that can be used to perform security-focused code reviews. It enables an auditor to swiftly map the attack-surface of a large application, with an emphasis on identifying development anti-patterns and footguns.",
55
"homepage": "https://github.com/chrisallenlane/drek",
66
"author": {
@@ -31,11 +31,11 @@
3131
"rc": "^1.2.1",
3232
"uuid-v4": "^0.1.0",
3333
"xmlbuilder": "^9.0.1",
34-
"yamljs": "^0.2.10"
34+
"yamljs": "^0.3.0"
3535
},
3636
"devDependencies": {
3737
"faucet": "0.0.1",
38-
"jshint": "2.9.4",
38+
"jshint": "2.9.5",
3939
"less": "^2.7.2",
4040
"tape": "^4.6.3"
4141
},

test/util-load-signatures.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,51 @@ const path = require('path');
44
const test = require('tape');
55

66

7-
test('util-load-signatures: it should load signature files', function (t) {
7+
test('util-load-signatures: it should load signatures (no wildcards)', function (t) {
88
t.plan(1);
9-
9+
1010
// stub configs
1111
const config = {
1212
signatures: [
1313
__dirname + '/mock/signatures/js.yml',
1414
__dirname + '/mock/signatures/php.yml',
1515
],
1616
};
17+
18+
// expected signatures
19+
const expected = [
20+
{ signature : '\\sconsole' , filetypes : [ 'js' ] } ,
21+
{ signature : '\\seval\\s*\\(' , filetypes : [ 'js' ] } ,
22+
{ signature : '\\s\\$_GET' , filetypes : [ 'php' ] } ,
23+
{ signature : '\\s\\$_POST' , filetypes : [ 'php' ] } ,
24+
{ signature : '\\seval\\s*\\(' , filetypes : [ 'php' ] } ,
25+
];
26+
27+
// assert that the returned signatures match the expected
28+
t.equals(
29+
lodash.isEqual(load({}, config), expected),
30+
true
31+
);
32+
});
33+
34+
35+
test('util-load-signatures: it should load signatures (wildcards)', function (t) {
36+
t.plan(1);
1737

38+
// stub configs
39+
const config = {
40+
signatures: [
41+
__dirname + '/mock/signatures/*.yml',
42+
],
43+
};
44+
1845
// expected signatures
1946
const expected = [
2047
{ signature : '\\sconsole' , filetypes : [ 'js' ] } ,
2148
{ signature : '\\seval\\s*\\(' , filetypes : [ 'js' ] } ,
2249
{ signature : '\\s\\$_GET' , filetypes : [ 'php' ] } ,
2350
{ signature : '\\s\\$_POST' , filetypes : [ 'php' ] } ,
24-
{ signature : '\\seval\\s*\\(' , filetypes : [ 'php' ] } ,
51+
{ signature : '\\seval\\s*\\(' , filetypes : [ 'php' ] } ,
2552
];
2653

2754
// assert that the returned signatures match the expected

0 commit comments

Comments
 (0)