Skip to content

Remove filename from error output #17

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

Merged
merged 1 commit into from
Jun 13, 2017
Merged
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
7 changes: 1 addition & 6 deletions rules/detect-buffer-noassert.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ module.exports = function(context) {
"writeDoubleBE"
];


var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"MemberExpression": function (node) {
var index;
Expand All @@ -63,7 +58,7 @@ module.exports = function(context) {

if (index && node.parent && node.parent.arguments && node.parent.arguments[index] && node.parent.arguments[index].value) {
var token = context.getTokens(node)[0];
return context.report(node, 'Found Buffer.' + node.property.name + ' with noAssert flag set true:\n\t' + getSource(token));
return context.report(node, 'Found Buffer.' + node.property.name + ' with noAssert flag set true');

}
}
Expand Down
8 changes: 2 additions & 6 deletions rules/detect-child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ module.exports = function(context) {

"use strict";

var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"CallExpression": function (node) {
var token = context.getTokens(node)[0];
Expand All @@ -28,15 +24,15 @@ module.exports = function(context) {
} else if (node.parent.type === 'AssignmentExpression' && node.parent.operator === '=') {
names.push(node.parent.left.name);
}
return context.report(node, 'Found require("child_process")\n\t' + getSource(token));
return context.report(node, 'Found require("child_process")');
}
}
},
"MemberExpression": function (node) {
var token = context.getTokens(node)[0];
if (node.property.name === 'exec' && names.indexOf(node.object.name) > -1) {
if (node.parent && node.parent.arguments && node.parent.arguments[0].type !== 'Literal') {
return context.report(node, 'Found child_process.exec() with non Literal first argument\n\t' + getSource(token));
return context.report(node, 'Found child_process.exec() with non Literal first argument');
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions rules/detect-new-buffer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
module.exports = function (context) {

var getSource = function (node) {
var token = context.getTokens(node)[0];
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}


// Detects instances of new Buffer(argument)
// where argument is any non literal value.
return {
Expand All @@ -14,7 +7,7 @@ module.exports = function (context) {
node.arguments[0] &&
node.arguments[0].type != 'Literal') {

return context.report(node, "Found new Buffer\n\t" + getSource(node));
return context.report(node, "Found new Buffer");
}


Expand Down
8 changes: 2 additions & 6 deletions rules/detect-non-literal-fs-filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ module.exports = function(context) {

"use strict";

var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"MemberExpression": function (node) {
var result = [];
Expand All @@ -36,13 +32,13 @@ module.exports = function(context) {

if (result.length > 0) {
var token = context.getTokens(node)[0];
return context.report(node, 'Found fs.' + node.property.name + ' with non literal argument at index ' + result.join(',') + '\n\t' + getSource(token));
return context.report(node, 'Found fs.' + node.property.name + ' with non literal argument at index ' + result.join(','));
}


/*
if (node.parent && node.parent.arguments && node.parent.arguments[index].value) {
return context.report(node, 'found Buffer.' + node.property.name + ' with noAssert flag set true:\n\t' + getSource(token));
return context.report(node, 'found Buffer.' + node.property.name + ' with noAssert flag set true');

}
*/
Expand Down
5 changes: 1 addition & 4 deletions rules/detect-non-literal-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ module.exports = function(context) {

"use strict";

var getSource = function(token) {
return token.loc.start.line + ': ' + context.getSourceLines().slice(token.loc.start.line - 1, token.loc.end.line).join('\n\t');
}
return {
"NewExpression": function(node) {
if (node.callee.name === 'RegExp') {
var args = node.arguments;
if (args && args.length > 0 && args[0].type !== 'Literal') {
var token = context.getTokens(node)[0];
return context.report(node, 'Found non-literal argument to RegExp Constructor\n\t' + getSource(token));
return context.report(node, 'Found non-literal argument to RegExp Constructor');
}
}

Expand Down
6 changes: 1 addition & 5 deletions rules/detect-non-literal-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ module.exports = function(context) {

"use strict";

var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"CallExpression": function (node) {
if (node.callee.name === 'require') {
var args = node.arguments;
if (args && args.length > 0 && args[0].type !== 'Literal') {
var token = context.getTokens(node)[0];
return context.report(node, 'Found non-literal argument in require\n\t' + getSource(token));
return context.report(node, 'Found non-literal argument in require');
}
}

Expand Down
6 changes: 3 additions & 3 deletions rules/detect-object-injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ var isChanged = false;
var token = context.getTokens(node)[0];
if (node.property.type === 'Identifier') {
if (node.parent.type === 'VariableDeclarator') {
context.report(node, 'Variable Assigned to Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
context.report(node, 'Variable Assigned to Object Injection Sink');

} else if (node.parent.type === 'CallExpression') {
// console.log(node.parent)
context.report(node, 'Function Call Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
context.report(node, 'Function Call Object Injection Sink');
} else {
context.report(node, 'Generic Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
context.report(node, 'Generic Object Injection Sink');

}

Expand Down
8 changes: 2 additions & 6 deletions rules/detect-possible-timing-attacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ module.exports = function(context) {

"use strict";

var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"IfStatement": function(node) {
if (node.test && node.test.type === 'BinaryExpression') {
Expand All @@ -46,14 +42,14 @@ module.exports = function(context) {
if (node.test.left) {
var left = containsKeyword(node.test.left);
if (left) {
return context.report(node, "Potential timing attack, left side: " + left + '\n\t' + getSource(token));
return context.report(node, "Potential timing attack, left side: " + left);
}
}

if (node.test.right) {
var right = containsKeyword(node.test.right);
if (right) {
return context.report(node, "Potential timing attack, right side: " + right + '\n\t' + getSource(token));
return context.report(node, "Potential timing attack, right side: " + right);
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions rules/detect-pseudoRandomBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ module.exports = function(context) {

"use strict";

var getSource = function (token) {
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
}

return {
"MemberExpression": function (node) {
if (node.property.name === 'pseudoRandomBytes') {
var token = context.getTokens(node)[0];
return context.report(node, 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers:\n\t' + getSource(token));
return context.report(node, 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers');
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/detect-buffer-noassert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tester.run(ruleName, Rule, {
invalid: [
{
code: invalid,
errors: [{ message: `Found Buffer.readUInt8 with noAssert flag set true:\n\t1: ${invalid}` }]
errors: [{ message: 'Found Buffer.readUInt8 with noAssert flag set true' }]
}
]
});
Expand All @@ -24,7 +24,7 @@ tester.run(`${ruleName} (false)`, Rule, {
invalid: [
{
code: invalid,
errors: [{ message: `Found Buffer.readUInt8 with noAssert flag set true:\n\t1: ${invalid}` }]
errors: [{ message: 'Found Buffer.readUInt8 with noAssert flag set true' }]
}
]
});
6 changes: 3 additions & 3 deletions test/detect-child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tester.run(`${ruleName} (require("child_process"))`, Rule, {
invalid: [
{
code: invalidRequire,
errors: [{ message: `Found require("child_process")\n\t1: ${invalidRequire}` }]
errors: [{ message: 'Found require("child_process")' }]
}
]
});
Expand All @@ -28,8 +28,8 @@ tester.run(`${ruleName} (child_process.exec() wih non literal 1st arg.)`, Rule,
{
code: invalidExec,
errors: [
{ message: `Found require("child_process")\n\t1: ${invalidExec}` },
{ message: `Found child_process.exec() with non Literal first argument\n\t1: ${invalidExec}` }]
{ message: 'Found require("child_process")' },
{ message: 'Found child_process.exec() with non Literal first argument' }]
}
]
});
2 changes: 1 addition & 1 deletion test/detect-new-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
invalid: [
{
code: invalid,
errors: [{ message: `Found new Buffer\n\t1: ${invalid}` }]
errors: [{ message: 'Found new Buffer' }]
}
]
});
2 changes: 1 addition & 1 deletion test/detect-non-literal-fs-filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
invalid: [
{
code: invalid,
errors: [{ message: `Found fs.open with non literal argument at index 0\n\t1: ${invalid}` }]
errors: [{ message: 'Found fs.open with non literal argument at index 0' }]
}
]
});
2 changes: 1 addition & 1 deletion test/detect-non-literal-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
invalid: [
{
code: invalid,
errors: [{ message: `Found non-literal argument to RegExp Constructor\n\t1: ${invalid}` }]
errors: [{ message: 'Found non-literal argument to RegExp Constructor' }]
}
]
});
2 changes: 1 addition & 1 deletion test/detect-non-literal-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
invalid: [
{
code: invalid,
errors: [{ message: `Found non-literal argument in require\n\t1: ${invalid}` }]
errors: [{ message: 'Found non-literal argument in require' }]
}
]
});
4 changes: 2 additions & 2 deletions test/detect-object-injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const invalidGeneric = 'var a = {}; a[b] = 4';
// invalid: [
// {
// code: invalidVariable,
// errors: [{ message: `Variable Assigned to Object Injection Sink: <input>: 1\n\t${invalidVariable}\n\n` }]
// errors: [{ message: 'Variable Assigned to Object Injection Sink' }]
// }
// ]
// });
Expand All @@ -41,7 +41,7 @@ tester.run(`${ruleName} (Generic)`, Rule, {
invalid: [
{
code: invalidGeneric,
errors: [{ message: `Generic Object Injection Sink: <input>: 1\n\t${invalidGeneric}\n\n` }]
errors: [{ message: 'Generic Object Injection Sink' }]
}
]
});
4 changes: 2 additions & 2 deletions test/detect-possible-timing-attacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tester.run(`${ruleName} (left side)`, Rule, {
invalid: [
{
code: invalidLeft,
errors: [{ message: `Potential timing attack, left side: true\n\t1: ${invalidLeft}` }]
errors: [{ message: 'Potential timing attack, left side: true' }]
}
]
});
Expand All @@ -30,7 +30,7 @@ tester.run(`${ruleName} (right side)`, Rule, {
invalid: [
{
code: invalidRigth,
errors: [{ message: `Potential timing attack, right side: true\n\t1: ${invalidRigth}` }]
errors: [{ message: 'Potential timing attack, right side: true' }]
}
]
});
2 changes: 1 addition & 1 deletion test/detect-pseudoRandomBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
invalid: [
{
code: invalid,
errors: [{ message: `Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers:\n\t1: ${invalid}` }]
errors: [{ message: 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers' }]
}
]
});