eslint-plugin-express-security 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +100 -0
- package/CHANGELOG.md +105 -0
- package/README.md +48 -26
- package/package.json +21 -5
- package/src/index.js +19 -1
- package/src/oxlint.d.ts +20 -0
- package/src/oxlint.js +21 -0
- package/src/rules/no-cors-credentials-wildcard/index.js +3 -0
- package/src/rules/no-exposed-debug-endpoints/index.js +4 -0
- package/src/rules/no-express-unsafe-regex-route/index.js +5 -2
- package/src/rules/no-graphql-introspection-production/index.js +3 -0
- package/src/rules/no-insecure-cookie-options/index.js +3 -0
- package/src/rules/no-missing-cors-check/index.d.ts +28 -0
- package/src/rules/no-missing-cors-check/index.js +402 -0
- package/src/rules/no-missing-csrf-protection/index.d.ts +30 -0
- package/src/rules/no-missing-csrf-protection/index.js +188 -0
- package/src/rules/no-missing-security-headers/index.d.ts +26 -0
- package/src/rules/no-missing-security-headers/index.js +226 -0
- package/src/rules/no-permissive-cors/index.js +3 -0
- package/src/rules/no-user-controlled-redirect/index.d.ts +44 -0
- package/src/rules/no-user-controlled-redirect/index.js +142 -0
- package/src/rules/require-csrf-protection/index.js +3 -0
- package/src/rules/require-express-body-parser-limits/index.js +5 -2
- package/src/rules/require-helmet/index.js +4 -0
- package/src/rules/require-rate-limiting/index.js +3 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noMissingSecurityHeaders = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
const DEFAULT_REQUIRED_HEADERS = [
|
|
12
|
+
'Content-Security-Policy',
|
|
13
|
+
'X-Frame-Options',
|
|
14
|
+
'X-Content-Type-Options',
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Extract header name from setHeader call
|
|
18
|
+
*/
|
|
19
|
+
function extractHeaderName(node) {
|
|
20
|
+
if (node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
|
|
21
|
+
return String(node.arguments[0].value);
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if all security headers are set in the current scope
|
|
27
|
+
*/
|
|
28
|
+
function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
|
|
29
|
+
const setHeaders = new Set();
|
|
30
|
+
// Find the function that contains this setHeader call
|
|
31
|
+
let current = node;
|
|
32
|
+
let scopeNode = null;
|
|
33
|
+
while (current) {
|
|
34
|
+
if (current.type === 'FunctionDeclaration' ||
|
|
35
|
+
current.type === 'FunctionExpression' ||
|
|
36
|
+
current.type === 'ArrowFunctionExpression') {
|
|
37
|
+
scopeNode = current;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
current = current.parent ?? null;
|
|
41
|
+
}
|
|
42
|
+
// If no function found, use the program scope (for test cases)
|
|
43
|
+
if (!scopeNode) {
|
|
44
|
+
scopeNode = context.sourceCode.ast;
|
|
45
|
+
}
|
|
46
|
+
// Collect all setHeader calls in this scope
|
|
47
|
+
function collectHeaders(astNode) {
|
|
48
|
+
if (astNode.type === 'CallExpression' &&
|
|
49
|
+
astNode.callee.type === 'MemberExpression' &&
|
|
50
|
+
astNode.callee.property.type === 'Identifier' &&
|
|
51
|
+
['setHeader', 'header', 'set'].includes(astNode.callee.property.name)) {
|
|
52
|
+
const headerName = extractHeaderName(astNode);
|
|
53
|
+
if (headerName) {
|
|
54
|
+
setHeaders.add(headerName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Recursively check children - only traverse standard AST properties
|
|
58
|
+
if (astNode.type === 'Program' && astNode.body) {
|
|
59
|
+
astNode.body.forEach(collectHeaders);
|
|
60
|
+
}
|
|
61
|
+
else if ((astNode.type === 'FunctionDeclaration' ||
|
|
62
|
+
astNode.type === 'FunctionExpression' ||
|
|
63
|
+
astNode.type === 'ArrowFunctionExpression') && astNode.body) {
|
|
64
|
+
collectHeaders(astNode.body);
|
|
65
|
+
}
|
|
66
|
+
else if (astNode.type === 'BlockStatement' && astNode.body) {
|
|
67
|
+
astNode.body.forEach(collectHeaders);
|
|
68
|
+
}
|
|
69
|
+
else if (astNode.type === 'ExpressionStatement' && astNode.expression) {
|
|
70
|
+
collectHeaders(astNode.expression);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (scopeNode) {
|
|
74
|
+
collectHeaders(scopeNode);
|
|
75
|
+
}
|
|
76
|
+
// Return missing headers
|
|
77
|
+
return requiredHeaders.filter(header => !setHeaders.has(header));
|
|
78
|
+
}
|
|
79
|
+
exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
|
|
80
|
+
name: 'no-missing-security-headers',
|
|
81
|
+
meta: {
|
|
82
|
+
type: 'problem',
|
|
83
|
+
deprecated: true,
|
|
84
|
+
replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
|
|
85
|
+
docs: {
|
|
86
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-security-headers.md',
|
|
87
|
+
description: 'Detects missing security headers in HTTP responses',
|
|
88
|
+
cwe: 'CWE-693',
|
|
89
|
+
cvss: 7.5,
|
|
90
|
+
},
|
|
91
|
+
hasSuggestions: true,
|
|
92
|
+
messages: {
|
|
93
|
+
missingSecurityHeader: (0, eslint_devkit_1.formatLLMMessage)({
|
|
94
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
95
|
+
issueName: 'Missing security headers',
|
|
96
|
+
cwe: 'CWE-693',
|
|
97
|
+
description: 'Missing security headers: {{headers}}',
|
|
98
|
+
severity: 'HIGH',
|
|
99
|
+
fix: 'Set security headers: Content-Security-Policy, X-Frame-Options, X-Content-Type-Options',
|
|
100
|
+
documentationLink: 'https://owasp.org/www-project-secure-headers/',
|
|
101
|
+
}),
|
|
102
|
+
addSecurityHeaders: (0, eslint_devkit_1.formatLLMMessage)({
|
|
103
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
104
|
+
issueName: 'Add Security Headers',
|
|
105
|
+
description: 'Add security headers middleware',
|
|
106
|
+
severity: 'LOW',
|
|
107
|
+
fix: 'Add Content-Security-Policy, X-Frame-Options headers',
|
|
108
|
+
documentationLink: 'https://owasp.org/www-project-secure-headers/',
|
|
109
|
+
}),
|
|
110
|
+
useMiddleware: (0, eslint_devkit_1.formatLLMMessage)({
|
|
111
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
112
|
+
issueName: 'Use Helmet',
|
|
113
|
+
description: 'Use helmet.js for security headers',
|
|
114
|
+
severity: 'LOW',
|
|
115
|
+
fix: 'app.use(helmet())',
|
|
116
|
+
documentationLink: 'https://helmetjs.github.io/',
|
|
117
|
+
}),
|
|
118
|
+
setHeader: (0, eslint_devkit_1.formatLLMMessage)({
|
|
119
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
120
|
+
issueName: 'Set Headers',
|
|
121
|
+
description: 'Set security headers manually',
|
|
122
|
+
severity: 'LOW',
|
|
123
|
+
fix: 'res.setHeader("X-Frame-Options", "DENY")',
|
|
124
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers',
|
|
125
|
+
}),
|
|
126
|
+
},
|
|
127
|
+
schema: [
|
|
128
|
+
{
|
|
129
|
+
type: 'object',
|
|
130
|
+
properties: {
|
|
131
|
+
requiredHeaders: {
|
|
132
|
+
type: 'array',
|
|
133
|
+
items: { type: 'string' },
|
|
134
|
+
default: DEFAULT_REQUIRED_HEADERS,
|
|
135
|
+
},
|
|
136
|
+
ignoreInTests: {
|
|
137
|
+
type: 'boolean',
|
|
138
|
+
default: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
additionalProperties: false,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
defaultOptions: [
|
|
146
|
+
{
|
|
147
|
+
requiredHeaders: DEFAULT_REQUIRED_HEADERS,
|
|
148
|
+
ignoreInTests: true,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
create(context, [options = {}]) {
|
|
152
|
+
const { requiredHeaders = DEFAULT_REQUIRED_HEADERS, ignoreInTests = true, } = options || {};
|
|
153
|
+
const filename = context.filename;
|
|
154
|
+
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
155
|
+
if (isTestFile) {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
const reportedScopes = new Set();
|
|
159
|
+
/**
|
|
160
|
+
* Get a unique key for the current scope
|
|
161
|
+
*/
|
|
162
|
+
function getScopeKey(node) {
|
|
163
|
+
// Find the function that contains this call
|
|
164
|
+
let current = node;
|
|
165
|
+
while (current) {
|
|
166
|
+
if (current.type === 'FunctionDeclaration' ||
|
|
167
|
+
current.type === 'FunctionExpression' ||
|
|
168
|
+
current.type === 'ArrowFunctionExpression') {
|
|
169
|
+
return `${current.range?.[0]}-${current.range?.[1]}`;
|
|
170
|
+
}
|
|
171
|
+
current = current.parent ?? null;
|
|
172
|
+
}
|
|
173
|
+
// If no function found, use program scope
|
|
174
|
+
return 'program';
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check for response header setting
|
|
178
|
+
*/
|
|
179
|
+
function checkCallExpression(node) {
|
|
180
|
+
// Check for res.setHeader, res.header, res.set
|
|
181
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
182
|
+
node.callee.property.type === 'Identifier') {
|
|
183
|
+
const methodName = node.callee.property.name;
|
|
184
|
+
if (['setHeader', 'header', 'set'].includes(methodName)) {
|
|
185
|
+
const scopeKey = getScopeKey(node);
|
|
186
|
+
// Only check once per scope
|
|
187
|
+
if (reportedScopes.has(scopeKey)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const missing = checkFunctionForSecurityHeaders(node, requiredHeaders, context);
|
|
191
|
+
if (missing.length > 0) {
|
|
192
|
+
reportedScopes.add(scopeKey);
|
|
193
|
+
context.report({
|
|
194
|
+
node,
|
|
195
|
+
messageId: 'missingSecurityHeader',
|
|
196
|
+
data: {
|
|
197
|
+
headers: missing.join(', '),
|
|
198
|
+
},
|
|
199
|
+
suggest: [
|
|
200
|
+
{
|
|
201
|
+
messageId: 'addSecurityHeaders',
|
|
202
|
+
fix: () => null,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
messageId: 'useMiddleware',
|
|
206
|
+
fix: () => null,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
messageId: 'setHeader',
|
|
210
|
+
fix: () => null,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// Mark as checked even if no error
|
|
217
|
+
reportedScopes.add(scopeKey);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
CallExpression: checkCallExpression,
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
});
|
|
@@ -84,7 +84,10 @@ exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
|
|
|
84
84
|
meta: {
|
|
85
85
|
type: 'problem',
|
|
86
86
|
docs: {
|
|
87
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-permissive-cors.md',
|
|
87
88
|
description: 'Disallow overly permissive CORS configurations (wildcard origin, origin: true)',
|
|
89
|
+
cwe: 'CWE-942',
|
|
90
|
+
cvss: 7.5,
|
|
88
91
|
},
|
|
89
92
|
hasSuggestions: true,
|
|
90
93
|
messages: {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-user-controlled-redirect
|
|
8
|
+
*
|
|
9
|
+
* Detects open-redirect vulnerabilities where res.redirect() is called with a
|
|
10
|
+
* value directly sourced from user-controlled request properties (req.query,
|
|
11
|
+
* req.body, req.params, req.headers). An attacker can craft a link that
|
|
12
|
+
* redirects victims to a malicious site after a legitimate-looking interaction.
|
|
13
|
+
*
|
|
14
|
+
* CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
|
|
15
|
+
* OWASP A01:2021 – Broken Access Control
|
|
16
|
+
*
|
|
17
|
+
* ## Detection method: structural-api
|
|
18
|
+
*
|
|
19
|
+
* This rule passes the litmus test: it fires on the AST shape of
|
|
20
|
+
* `res.redirect(req.query.*)` — not on variable names. Rename `res` to `r`
|
|
21
|
+
* and `req` to `q` in the source; the rule still fires because it checks the
|
|
22
|
+
* member-access chain `<ident>.redirect(<ident>.<userSourceProp>.*)`.
|
|
23
|
+
*
|
|
24
|
+
* The rule only fires when the redirect argument is DIRECTLY a request
|
|
25
|
+
* property access — it does NOT attempt data-flow or taint analysis.
|
|
26
|
+
* `const url = req.query.url; res.redirect(url)` is not detected (the
|
|
27
|
+
* indirect case). This conservative approach means zero false positives on
|
|
28
|
+
* validated redirects while catching the most common unvalidated pattern.
|
|
29
|
+
*
|
|
30
|
+
* @see https://cwe.mitre.org/data/definitions/601.html
|
|
31
|
+
* @see https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
|
|
32
|
+
*/
|
|
33
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
34
|
+
export interface Options {
|
|
35
|
+
/** Additional response object names beyond the default set. Default: [] */
|
|
36
|
+
responseObjects?: string[];
|
|
37
|
+
/** Additional request object names beyond the default set. Default: [] */
|
|
38
|
+
requestObjects?: string[];
|
|
39
|
+
}
|
|
40
|
+
type RuleOptions = [Options?];
|
|
41
|
+
export declare const noUserControlledRedirect: TSESLint.RuleModule<"openRedirect", RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noUserControlledRedirect = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
/** Property names on the request object that carry user-controlled values. */
|
|
11
|
+
const USER_SOURCE_PROPS = new Set(['query', 'body', 'params', 'headers', 'cookies']);
|
|
12
|
+
/** Method names that perform HTTP redirects. */
|
|
13
|
+
const REDIRECT_METHODS = new Set(['redirect', 'location']);
|
|
14
|
+
exports.noUserControlledRedirect = (0, eslint_devkit_1.createRule)({
|
|
15
|
+
name: 'no-user-controlled-redirect',
|
|
16
|
+
meta: {
|
|
17
|
+
type: 'problem',
|
|
18
|
+
docs: {
|
|
19
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-user-controlled-redirect.md',
|
|
20
|
+
description: 'Disallow res.redirect() with values directly from req.query / req.body / req.params',
|
|
21
|
+
cwe: 'CWE-601',
|
|
22
|
+
cvss: 6.1,
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
openRedirect: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
27
|
+
issueName: 'Open Redirect (CWE-601)',
|
|
28
|
+
cwe: 'CWE-601',
|
|
29
|
+
description: 'res.redirect() receives a value directly from {{source}}, which is user-controlled. An attacker can redirect victims to a malicious site.',
|
|
30
|
+
severity: 'HIGH',
|
|
31
|
+
fix: 'Validate the redirect target against an allowlist of trusted paths/origins, or use a relative path that cannot be redirected off-domain.',
|
|
32
|
+
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html',
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
schema: [
|
|
36
|
+
{
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
responseObjects: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
items: { type: 'string' },
|
|
42
|
+
description: 'Additional response object names (e.g. ["reply"] for Fastify)',
|
|
43
|
+
},
|
|
44
|
+
requestObjects: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
items: { type: 'string' },
|
|
47
|
+
description: 'Additional request object names',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
defaultOptions: [{}],
|
|
55
|
+
create(context, [options = {}]) {
|
|
56
|
+
const extraResNames = new Set(options.responseObjects ?? []);
|
|
57
|
+
const extraReqNames = new Set(options.requestObjects ?? []);
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if `node` is a member expression whose root object is a
|
|
60
|
+
* known response object name and whose property is a redirect method.
|
|
61
|
+
* e.g. `res.redirect`, `response.location`, `reply.redirect`
|
|
62
|
+
*/
|
|
63
|
+
function isRedirectCall(node) {
|
|
64
|
+
const callee = node.callee;
|
|
65
|
+
if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
66
|
+
return false;
|
|
67
|
+
if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
|
|
68
|
+
return false;
|
|
69
|
+
if (!REDIRECT_METHODS.has(callee.property.name))
|
|
70
|
+
return false;
|
|
71
|
+
const obj = callee.object;
|
|
72
|
+
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
|
|
73
|
+
return false;
|
|
74
|
+
const name = obj.name.toLowerCase();
|
|
75
|
+
return (name === 'res' ||
|
|
76
|
+
name === 'response' ||
|
|
77
|
+
name === 'reply' ||
|
|
78
|
+
extraResNames.has(obj.name));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a human-readable description if `node` is a direct access on a
|
|
82
|
+
* user-controlled request property (req.query.foo, req.body.bar, etc.)
|
|
83
|
+
* Returns null if not a user-source access.
|
|
84
|
+
*
|
|
85
|
+
* Valid patterns:
|
|
86
|
+
* req.query.returnUrl → MemberExpr(MemberExpr(req, query), returnUrl)
|
|
87
|
+
* req.body['redirect'] → MemberExpr(MemberExpr(req, body), computed)
|
|
88
|
+
* req.params.slug → same
|
|
89
|
+
* req.headers['x-redirect'] → same
|
|
90
|
+
* req.query → direct property (whole query object)
|
|
91
|
+
*/
|
|
92
|
+
function getUserSourceDescription(node) {
|
|
93
|
+
if (node.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
94
|
+
return null;
|
|
95
|
+
// Case 1: req.query.foo (three levels)
|
|
96
|
+
const obj = node.object;
|
|
97
|
+
if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
98
|
+
const root = obj.object;
|
|
99
|
+
const sourceProp = obj.property;
|
|
100
|
+
if (root.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
101
|
+
sourceProp.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
102
|
+
USER_SOURCE_PROPS.has(sourceProp.name) &&
|
|
103
|
+
isRequestIdent(root.name)) {
|
|
104
|
+
return `req.${sourceProp.name}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Case 2: req.query (two levels — whole user-source object)
|
|
108
|
+
const prop = node.property;
|
|
109
|
+
if (obj.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
110
|
+
prop.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
111
|
+
USER_SOURCE_PROPS.has(prop.name) &&
|
|
112
|
+
isRequestIdent(obj.name)) {
|
|
113
|
+
return `req.${prop.name}`;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
function isRequestIdent(name) {
|
|
118
|
+
const lower = name.toLowerCase();
|
|
119
|
+
return (lower === 'req' ||
|
|
120
|
+
lower === 'request' ||
|
|
121
|
+
lower === 'ctx' ||
|
|
122
|
+
extraReqNames.has(name));
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
CallExpression(node) {
|
|
126
|
+
if (!isRedirectCall(node))
|
|
127
|
+
return;
|
|
128
|
+
const firstArg = node.arguments[0];
|
|
129
|
+
if (!firstArg)
|
|
130
|
+
return;
|
|
131
|
+
const source = getUserSourceDescription(firstArg);
|
|
132
|
+
if (!source)
|
|
133
|
+
return;
|
|
134
|
+
context.report({
|
|
135
|
+
node: firstArg,
|
|
136
|
+
messageId: 'openRedirect',
|
|
137
|
+
data: { source },
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
});
|
|
@@ -93,7 +93,10 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
|
|
|
93
93
|
meta: {
|
|
94
94
|
type: 'problem',
|
|
95
95
|
docs: {
|
|
96
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-csrf-protection.md',
|
|
96
97
|
description: 'Require CSRF protection middleware for state-changing HTTP methods',
|
|
98
|
+
cwe: 'CWE-352',
|
|
99
|
+
cvss: 7.5,
|
|
97
100
|
},
|
|
98
101
|
hasSuggestions: true,
|
|
99
102
|
messages: {
|
|
@@ -22,7 +22,7 @@ const DEFAULT_EXCESSIVE_LIMITS = [
|
|
|
22
22
|
/**
|
|
23
23
|
* Body parser function names to check
|
|
24
24
|
*/
|
|
25
|
-
const BODY_PARSER_METHODS = ['json', 'urlencoded', 'raw', 'text'];
|
|
25
|
+
const BODY_PARSER_METHODS = new Set(['json', 'urlencoded', 'raw', 'text']);
|
|
26
26
|
/**
|
|
27
27
|
* Check if a property has a limit option
|
|
28
28
|
*/
|
|
@@ -50,7 +50,10 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
|
|
|
50
50
|
meta: {
|
|
51
51
|
type: 'problem',
|
|
52
52
|
docs: {
|
|
53
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-express-body-parser-limits.md',
|
|
53
54
|
description: 'Require size limits on Express.js body parsers to prevent DoS attacks',
|
|
55
|
+
cwe: 'CWE-400',
|
|
56
|
+
cvss: 7.5,
|
|
54
57
|
},
|
|
55
58
|
hasSuggestions: true,
|
|
56
59
|
messages: {
|
|
@@ -142,7 +145,7 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
|
|
|
142
145
|
if (property.type !== 'Identifier') {
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
|
-
if (!BODY_PARSER_METHODS.
|
|
148
|
+
if (!BODY_PARSER_METHODS.has(property.name)) {
|
|
146
149
|
return;
|
|
147
150
|
}
|
|
148
151
|
// Check arguments
|
|
@@ -65,7 +65,11 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
|
|
|
65
65
|
meta: {
|
|
66
66
|
type: 'problem',
|
|
67
67
|
docs: {
|
|
68
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-helmet.md',
|
|
68
69
|
description: 'Require helmet middleware for security headers in Express.js applications',
|
|
70
|
+
cwe: 'CWE-693',
|
|
71
|
+
cvss: 7.5,
|
|
72
|
+
confidence: 'high',
|
|
69
73
|
},
|
|
70
74
|
hasSuggestions: true,
|
|
71
75
|
messages: {
|
|
@@ -43,7 +43,10 @@ exports.requireRateLimiting = (0, eslint_devkit_1.createRule)({
|
|
|
43
43
|
meta: {
|
|
44
44
|
type: 'problem',
|
|
45
45
|
docs: {
|
|
46
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-rate-limiting.md',
|
|
46
47
|
description: 'Require rate limiting middleware in Express.js applications',
|
|
48
|
+
cwe: 'CWE-770',
|
|
49
|
+
cvss: 7.5,
|
|
47
50
|
},
|
|
48
51
|
hasSuggestions: true,
|
|
49
52
|
messages: {
|