Skip to content

Commit 3d1bf82

Browse files
authored
chore: add eslint-plugin-eslint-plugin (#91)
1 parent 352a088 commit 3d1bf82

16 files changed

+88
-46
lines changed

.eslintrc

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
{
22
"extends": [
33
"eslint:recommended",
4-
"prettier"
4+
"prettier",
5+
"plugin:eslint-plugin/recommended"
56
],
67
"parserOptions": {
78
"ecmaVersion": "latest"
89
},
910
"env": {
1011
"node": true,
1112
"es2020": true
13+
},
14+
"rules": {
15+
"eslint-plugin/prefer-message-ids": "off", // TODO: enable
16+
"eslint-plugin/require-meta-docs-url": [
17+
"error",
18+
{
19+
"pattern":
20+
"https://github.com/nodesecurity/eslint-plugin-security#{{name}}",
21+
},
22+
],
23+
"eslint-plugin/require-meta-schema": "off", // TODO: enable
24+
"eslint-plugin/require-meta-type": "off"// TODO: enable
1225
}
1326
}

package-lock.json

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"eslint": "^8.11.0",
4747
"eslint-config-nodesecurity": "^1.3.1",
4848
"eslint-config-prettier": "^8.5.0",
49+
"eslint-plugin-eslint-plugin": "^5.0.2",
4950
"lint-staged": "^12.3.7",
5051
"mocha": "^9.2.2",
5152
"prettier": "^2.6.2",

rules/detect-buffer-noassert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
}
7373

7474
if (index && node.parent && node.parent.arguments && node.parent.arguments[index] && node.parent.arguments[index].value) {
75-
return context.report(node, `Found Buffer.${node.property.name} with noAssert flag set true`);
75+
return context.report({ node: node, message: `Found Buffer.${node.property.name} with noAssert flag set true` });
7676
}
7777
},
7878
};

rules/detect-child-process.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
description: 'Detect instances of "child_process" & non-literal "exec()" calls.',
2222
category: 'Possible Security Vulnerability',
2323
recommended: true,
24-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/avoid-command-injection-node.md',
24+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-child-process',
2525
},
2626
},
2727
create: function (context) {
@@ -35,14 +35,14 @@ module.exports = {
3535
} else if (node.parent.type === 'AssignmentExpression' && node.parent.operator === '=') {
3636
names.push(node.parent.left.name);
3737
}
38-
return context.report(node, 'Found require("child_process")');
38+
return context.report({ node: node, message: 'Found require("child_process")' });
3939
}
4040
}
4141
},
4242
MemberExpression: function (node) {
4343
if (node.property.name === 'exec' && names.indexOf(node.object.name) > -1) {
4444
if (node.parent && node.parent.arguments.length && node.parent.arguments[0].type !== 'Literal') {
45-
return context.report(node, 'Found child_process.exec() with non Literal first argument');
45+
return context.report({ node: node, message: 'Found child_process.exec() with non Literal first argument' });
4646
}
4747
}
4848
},

rules/detect-disable-mustache-escape.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
description: 'Detects "object.escapeMarkup = false", which can be used with some template engines to disable escaping of HTML entities.',
88
category: 'Possible Security Vulnerability',
99
recommended: true,
10-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-disable-mustache-escape'
11-
}
10+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-disable-mustache-escape',
11+
},
1212
},
1313
create: function (context) {
1414
return {
@@ -17,12 +17,12 @@ module.exports = {
1717
if (node.left.property) {
1818
if (node.left.property.name === 'escapeMarkup') {
1919
if (node.right.value === false) {
20-
context.report(node, 'Markup escaping disabled.');
20+
context.report({ node: node, message: 'Markup escaping disabled.' });
2121
}
2222
}
2323
}
2424
}
25-
}
25+
},
2626
};
27-
}
27+
},
2828
};

rules/detect-eval-with-expression.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ module.exports = {
1616
description: 'Detects "eval(variable)" which can allow an attacker to run arbitrary code inside your process.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-eval-with-expression'
20-
}
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-eval-with-expression',
20+
},
2121
},
2222
create: function (context) {
2323
return {
2424
CallExpression: function (node) {
2525
if (node.callee.name === 'eval' && node.arguments[0].type !== 'Literal') {
26-
context.report(node, `eval with argument of type ${node.arguments[0].type}`);
26+
context.report({ node: node, message: `eval with argument of type ${node.arguments[0].type}` });
2727
}
28-
}
28+
},
2929
};
30-
}
30+
},
3131
};

rules/detect-new-buffer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ module.exports = {
77
description: 'Detect instances of new Buffer(argument) where argument is any non-literal value.',
88
category: 'Possible Security Vulnerability',
99
recommended: true,
10-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/README.md'
11-
}
10+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-new-buffer',
11+
},
1212
},
1313
create: function (context) {
1414
return {
1515
NewExpression: function (node) {
1616
if (node.callee.name === 'Buffer' && node.arguments[0] && node.arguments[0].type !== 'Literal') {
17-
return context.report(node, 'Found new Buffer');
17+
return context.report({ node: node, message: 'Found new Buffer' });
1818
}
19-
}
19+
},
2020
};
21-
}
21+
},
2222
};

rules/detect-no-csrf-before-method-override.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ module.exports = {
1616
description: 'Detects Express "csrf" middleware setup before "method-override" middleware.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/bypass-connect-csrf-protection-by-abusing.md',
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-no-csrf-before-method-override',
2020
},
2121
},
2222
create: function (context) {
2323
let csrf = false;
2424

2525
return {
2626
CallExpression: function (node) {
27-
const token = context.getTokens(node)[0];
27+
const token = context.getSourceCode().getTokens(node)[0];
2828
const nodeValue = token.value;
2929

3030
if (nodeValue === 'express') {
@@ -33,7 +33,7 @@ module.exports = {
3333
}
3434

3535
if (node.callee.property.name === 'methodOverride' && csrf) {
36-
context.report(node, 'express.csrf() middleware found before express.methodOverride()');
36+
context.report({ node: node, message: 'express.csrf() middleware found before express.methodOverride()' });
3737
}
3838
if (node.callee.property.name === 'csrf') {
3939
// Keep track of found CSRF

rules/detect-non-literal-fs-filename.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
}
4040

4141
if (result.length > 0) {
42-
return context.report(node, `Found fs.${node.property.name} with non literal argument at index ${result.join(',')}`);
42+
return context.report({ node: node, message: `Found fs.${node.property.name} with non literal argument at index ${result.join(',')}` });
4343
}
4444

4545
/*

rules/detect-non-literal-regexp.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
description: 'Detects "RegExp(variable)", which might allow an attacker to DOS your server with a long-running regular expression.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/regular-expression-dos-and-node.md',
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-non-literal-regexp',
2020
},
2121
},
2222
create: function (context) {
@@ -25,7 +25,7 @@ module.exports = {
2525
if (node.callee.name === 'RegExp') {
2626
const args = node.arguments;
2727
if (args && args.length > 0 && args[0].type !== 'Literal') {
28-
return context.report(node, 'Found non-literal argument to RegExp Constructor');
28+
return context.report({ node: node, message: 'Found non-literal argument to RegExp Constructor' });
2929
}
3030
}
3131
},

rules/detect-non-literal-require.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
(args && args.length > 0 && args[0].type === 'TemplateLiteral' && args[0].expressions.length > 0) ||
2929
(args[0].type !== 'TemplateLiteral' && args[0].type !== 'Literal')
3030
) {
31-
return context.report(node, 'Found non-literal argument in require');
31+
return context.report({ node: node, message: 'Found non-literal argument in require' });
3232
}
3333
}
3434
},

rules/detect-object-injection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
description: 'Detects "variable[key]" as a left- or right-hand assignment operand.',
5959
category: 'Possible Security Vulnerability',
6060
recommended: true,
61-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/the-dangers-of-square-bracket-notation.md',
61+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-object-injection',
6262
},
6363
},
6464
create: function (context) {
@@ -67,11 +67,11 @@ module.exports = {
6767
if (node.computed === true) {
6868
if (node.property.type === 'Identifier') {
6969
if (node.parent.type === 'VariableDeclarator') {
70-
context.report(node, 'Variable Assigned to Object Injection Sink');
70+
context.report({ node: node, message: 'Variable Assigned to Object Injection Sink' });
7171
} else if (node.parent.type === 'CallExpression') {
72-
context.report(node, 'Function Call Object Injection Sink');
72+
context.report({ node: node, message: 'Function Call Object Injection Sink' });
7373
} else {
74-
context.report(node, 'Generic Object Injection Sink');
74+
context.report({ node: node, message: 'Generic Object Injection Sink' });
7575
}
7676
}
7777
}

rules/detect-possible-timing-attacks.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module.exports = {
2929
description: 'Detects insecure comparisons (`==`, `!=`, `!==` and `===`), which check input sequentially.',
3030
category: 'Possible Security Vulnerability',
3131
recommended: true,
32-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-possible-timing-attacks'
33-
}
32+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-possible-timing-attacks',
33+
},
3434
},
3535
create: function (context) {
3636
return {
@@ -40,19 +40,19 @@ module.exports = {
4040
if (node.test.left) {
4141
const left = containsKeyword(node.test.left);
4242
if (left) {
43-
return context.report(node, `Potential timing attack, left side: ${left}`);
43+
return context.report({ node: node, message: `Potential timing attack, left side: ${left}` });
4444
}
4545
}
4646

4747
if (node.test.right) {
4848
const right = containsKeyword(node.test.right);
4949
if (right) {
50-
return context.report(node, `Potential timing attack, right side: ${right}`);
50+
return context.report({ node: node, message: `Potential timing attack, right side: ${right}` });
5151
}
5252
}
5353
}
5454
}
55-
}
55+
},
5656
};
57-
}
57+
},
5858
};

rules/detect-pseudoRandomBytes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ module.exports = {
1616
description: 'Detects if "pseudoRandomBytes()" is in use, which might not give you the randomness you need and expect.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-pseudorandombytes',
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-pseudoRandomBytes',
2020
},
2121
},
2222
create: function (context) {
2323
return {
2424
MemberExpression: function (node) {
2525
if (node.property.name === 'pseudoRandomBytes') {
26-
return context.report(node, 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers');
26+
return context.report({ node: node, message: 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers' });
2727
}
2828
},
2929
};

rules/detect-unsafe-regex.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ module.exports = {
2222
description: 'Locates potentially unsafe regular expressions, which may take a very long time to run, blocking the event loop.',
2323
category: 'Possible Security Vulnerability',
2424
recommended: true,
25-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/regular-expression-dos-and-node.md'
26-
}
25+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-unsafe-regex',
26+
},
2727
},
2828
create: function (context) {
2929
return {
3030
Literal: function (node) {
31-
const token = context.getTokens(node)[0];
31+
const token = context.getSourceCode().getTokens(node)[0];
3232
const nodeType = token.type;
3333
const nodeValue = token.value;
3434

3535
if (nodeType === 'RegularExpression') {
3636
if (!safe(nodeValue)) {
37-
context.report(node, 'Unsafe Regular Expression');
37+
context.report({ node: node, message: 'Unsafe Regular Expression' });
3838
}
3939
}
4040
},
4141
NewExpression: function (node) {
4242
if (node.callee.name === 'RegExp' && node.arguments && node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
4343
if (!safe(node.arguments[0].value)) {
44-
context.report(node, 'Unsafe Regular Expression (new RegExp)');
44+
context.report({ node: node, message: 'Unsafe Regular Expression (new RegExp)' });
4545
}
4646
}
47-
}
47+
},
4848
};
49-
}
49+
},
5050
};

0 commit comments

Comments
 (0)