eslint-plugin-express-security 1.3.4 → 1.5.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.
Files changed (52) hide show
  1. package/README.md +46 -27
  2. package/package.json +27 -18
  3. package/src/index.d.ts +17 -40
  4. package/src/index.js +47 -62
  5. package/src/oxlint.d.ts +17 -20
  6. package/src/oxlint.js +0 -18
  7. package/src/rules/no-client-controlled-authorization/index.js +194 -0
  8. package/src/rules/no-cors-credentials-wildcard/index.js +0 -22
  9. package/src/rules/no-disabled-helmet-protections/index.js +125 -0
  10. package/src/rules/no-error-details-in-response/index.js +176 -0
  11. package/src/rules/no-exposed-debug-endpoints/index.js +27 -32
  12. package/src/rules/no-express-unsafe-regex-route/index.js +1 -32
  13. package/src/rules/no-graphql-introspection-production/index.js +0 -21
  14. package/src/rules/no-host-header-in-links/index.js +235 -0
  15. package/src/rules/no-idor-resource-access/index.js +126 -0
  16. package/src/rules/no-insecure-cookie-options/index.js +0 -12
  17. package/src/rules/no-missing-cors-check/index.js +4 -54
  18. package/src/rules/no-missing-csrf-protection/index.js +0 -25
  19. package/src/rules/no-missing-security-headers/index.js +50 -69
  20. package/src/rules/no-permissive-cors/index.js +0 -27
  21. package/src/rules/no-permissive-trust-proxy/index.js +106 -0
  22. package/src/rules/no-sensitive-data-in-query/index.js +182 -0
  23. package/src/rules/no-static-root-exposure/index.js +267 -0
  24. package/src/rules/no-unsafe-csp-directives/index.js +264 -0
  25. package/src/rules/no-user-controlled-redirect/index.js +0 -26
  26. package/src/rules/no-user-controlled-render-locals/index.js +268 -0
  27. package/src/rules/require-case-insensitive-path-guard/index.js +180 -0
  28. package/src/rules/require-csrf-protection/index.js +0 -42
  29. package/src/rules/require-express-body-parser-limits/index.js +0 -24
  30. package/src/rules/require-helmet/index.js +1 -25
  31. package/src/rules/require-query-type-guard/index.js +258 -0
  32. package/src/rules/require-rate-limiting/index.js +0 -13
  33. package/src/rules/require-route-authentication/index.js +225 -0
  34. package/src/rules/require-strict-transport-security/index.js +171 -0
  35. package/src/types/index.js +0 -5
  36. package/src/utils/index.js +81 -0
  37. package/AGENTS.md +0 -100
  38. package/CHANGELOG.md +0 -149
  39. package/src/rules/no-cors-credentials-wildcard/index.d.ts +0 -26
  40. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -14
  41. package/src/rules/no-express-unsafe-regex-route/index.d.ts +0 -27
  42. package/src/rules/no-graphql-introspection-production/index.d.ts +0 -26
  43. package/src/rules/no-insecure-cookie-options/index.d.ts +0 -39
  44. package/src/rules/no-missing-cors-check/index.d.ts +0 -28
  45. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -30
  46. package/src/rules/no-missing-security-headers/index.d.ts +0 -26
  47. package/src/rules/no-permissive-cors/index.d.ts +0 -28
  48. package/src/rules/no-user-controlled-redirect/index.d.ts +0 -44
  49. package/src/rules/require-csrf-protection/index.d.ts +0 -28
  50. package/src/rules/require-express-body-parser-limits/index.d.ts +0 -31
  51. package/src/rules/require-helmet/index.d.ts +0 -29
  52. package/src/rules/require-rate-limiting/index.d.ts +0 -31
@@ -1,47 +1,21 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noExpressUnsafeRegexRoute = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /**
11
- * HTTP method names used for routing
12
- */
13
5
  const HTTP_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all', 'use']);
14
- /**
15
- * Patterns that indicate potential ReDoS vulnerability
16
- * These are simplified heuristics - a full ReDoS detector would be more complex
17
- */
18
6
  const VULNERABLE_PATTERNS = [
19
- // Nested quantifiers: (a+)+, (a*)*
20
7
  /\([^)]*[+*][^)]*\)[+*]/,
21
- // Overlapping alternatives: (a|a)+
22
8
  /\([^)]*\|[^)]*\)[+*]/,
23
- // Repetition of repetition: a++, a**
24
9
  /[+*]{2,}/,
25
- // Greedy patterns with backreferences
26
10
  /\([^)]+\)[+*].*\\[1-9]/,
27
11
  ];
28
- /**
29
- * Route parameter patterns that may cause issues
30
- */
31
12
  const VULNERABLE_PARAM_PATTERNS = [
32
- // :param+ or :param* - can match multiple segments
33
13
  /:[a-zA-Z_][a-zA-Z0-9_]*\+/,
34
14
  /:[a-zA-Z_][a-zA-Z0-9_]*\*/,
35
15
  ];
36
- /**
37
- * Check if a regex pattern is potentially vulnerable to ReDoS
38
- */
39
16
  function isVulnerableRegex(pattern) {
40
17
  return VULNERABLE_PATTERNS.some((regex) => regex.test(pattern));
41
18
  }
42
- /**
43
- * Check if a route string has vulnerable param patterns
44
- */
45
19
  function hasVulnerableParamPattern(route) {
46
20
  return VULNERABLE_PARAM_PATTERNS.some((regex) => regex.test(route));
47
21
  }
@@ -109,7 +83,6 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
109
83
  return {
110
84
  CallExpression(node) {
111
85
  const callee = node.callee;
112
- // Check for app.get(), router.post(), etc.
113
86
  if (callee.type !== 'MemberExpression') {
114
87
  return;
115
88
  }
@@ -120,12 +93,10 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
120
93
  if (!HTTP_METHODS.has(property.name)) {
121
94
  return;
122
95
  }
123
- // Check the route argument (first argument)
124
96
  const routeArg = node.arguments[0];
125
97
  if (!routeArg) {
126
98
  return;
127
99
  }
128
- // Check regex literal routes (e.g., /pattern/)
129
100
  if (routeArg.type === 'Literal' && 'regex' in routeArg && routeArg.regex) {
130
101
  const regexNode = routeArg;
131
102
  const pattern = regexNode.regex.pattern;
@@ -136,14 +107,13 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
136
107
  suggest: [
137
108
  {
138
109
  messageId: 'refactorRoute',
139
- fix: () => null, // Manual fix required
110
+ fix: () => null,
140
111
  },
141
112
  ],
142
113
  });
143
114
  }
144
115
  return;
145
116
  }
146
- // Check new RegExp() routes
147
117
  if (routeArg.type === 'NewExpression' &&
148
118
  routeArg.callee.type === 'Identifier' &&
149
119
  routeArg.callee.name === 'RegExp') {
@@ -164,7 +134,6 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
164
134
  }
165
135
  return;
166
136
  }
167
- // Check string routes with vulnerable param patterns
168
137
  if (routeArg.type === 'Literal' && typeof routeArg.value === 'string') {
169
138
  if (hasVulnerableParamPattern(routeArg.value)) {
170
139
  context.report({
@@ -1,31 +1,16 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noGraphqlIntrospectionProduction = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /**
11
- * Check if introspection is explicitly enabled
12
- */
13
5
  function hasIntrospectionEnabled(node, sourceCode) {
14
6
  const text = sourceCode.getText(node);
15
- // Check for introspection: true
16
7
  if (/\bintrospection\s*:\s*true\b/.test(text)) {
17
8
  return true;
18
9
  }
19
- // Check for no introspection setting (defaults to true in many libraries)
20
- // We only flag explicit true or missing with warning
21
10
  return false;
22
11
  }
23
- /**
24
- * Check if there's a production guard for introspection
25
- */
26
12
  function hasProductionGuard(node, sourceCode) {
27
13
  const text = sourceCode.getText(node);
28
- // Check for common production guards
29
14
  const productionGuards = [
30
15
  /introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]production['"]/,
31
16
  /introspection\s*:\s*!?\s*isProd/,
@@ -98,27 +83,22 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
98
83
  return {
99
84
  CallExpression(node) {
100
85
  const callee = node.callee;
101
- // Check for Apollo Server, Express-GraphQL, or similar
102
86
  const isGraphQLServer = (callee.type === 'Identifier' &&
103
87
  ['ApolloServer', 'GraphQLServer', 'createServer'].includes(callee.name)) ||
104
88
  (callee.type === 'NewExpression' &&
105
89
  callee.callee.type === 'Identifier' &&
106
90
  ['ApolloServer', 'GraphQLServer'].includes(callee.callee.name));
107
- // Also check for graphqlHTTP (express-graphql)
108
91
  const isExpressGraphQL = callee.type === 'Identifier' && callee.name === 'graphqlHTTP';
109
92
  if (!isGraphQLServer && !isExpressGraphQL) {
110
93
  return;
111
94
  }
112
- // Get the options/config argument
113
95
  const configArg = node.arguments[0];
114
96
  if (!configArg || configArg.type !== 'ObjectExpression') {
115
97
  return;
116
98
  }
117
- // Check if there's a production guard
118
99
  if (hasProductionGuard(configArg, sourceCode)) {
119
100
  return;
120
101
  }
121
- // Check if introspection is explicitly enabled
122
102
  if (hasIntrospectionEnabled(configArg, sourceCode)) {
123
103
  context.report({
124
104
  node: configArg,
@@ -132,7 +112,6 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
132
112
  });
133
113
  }
134
114
  },
135
- // Also check NewExpression for new ApolloServer({...})
136
115
  NewExpression(node) {
137
116
  const callee = node.callee;
138
117
  if (callee.type !== 'Identifier' ||
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noHostHeaderInLinks = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const HOST_HEADER_NAMES = new Set(['host', 'x-forwarded-host']);
6
+ const HOST_GETTER_METHODS = new Set(['get', 'header']);
7
+ exports.noHostHeaderInLinks = (0, eslint_devkit_1.createRule)({
8
+ name: 'no-host-header-in-links',
9
+ meta: {
10
+ type: 'problem',
11
+ hasSuggestions: true,
12
+ docs: {
13
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-host-header-in-links.md',
14
+ description: 'Disallow building absolute URLs (reset/verification links) from the Host or X-Forwarded-Host request header',
15
+ cwe: 'CWE-640',
16
+ cvss: 8.1,
17
+ },
18
+ messages: {
19
+ hostHeaderInLink: (0, eslint_devkit_1.formatLLMMessage)({
20
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
21
+ issueName: 'Host-Header Poisoning (CWE-640)',
22
+ cwe: 'CWE-640',
23
+ description: 'A URL is built from {{source}}, which the client controls. Reset/verification links built this way can be redirected to an attacker-owned host, leaking the token.',
24
+ severity: 'HIGH',
25
+ fix: 'Build absolute links from a server-side constant (e.g. process.env.PUBLIC_ORIGIN), never from request headers.',
26
+ documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
27
+ }),
28
+ useConfiguredOrigin: (0, eslint_devkit_1.formatLLMMessage)({
29
+ icon: eslint_devkit_1.MessageIcons.INFO,
30
+ issueName: 'Use a configured origin',
31
+ description: 'Replace the header-derived host with a deployment constant such as process.env.PUBLIC_ORIGIN',
32
+ severity: 'LOW',
33
+ fix: "const origin = process.env.PUBLIC_ORIGIN; // 'https://app.example.com'",
34
+ documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
35
+ }),
36
+ },
37
+ schema: [
38
+ {
39
+ type: 'object',
40
+ properties: {
41
+ allowedHosts: {
42
+ type: 'array',
43
+ items: { type: 'string' },
44
+ description: 'Trusted literal hosts — an if-guard comparing against one of these suppresses the report',
45
+ },
46
+ checkMailCallees: {
47
+ type: 'array',
48
+ items: { type: 'string' },
49
+ description: 'Callee names treated as mail-send sinks (default: ["sendMail", "send"])',
50
+ },
51
+ },
52
+ additionalProperties: false,
53
+ },
54
+ ],
55
+ },
56
+ defaultOptions: [{}],
57
+ create(context, [options]) {
58
+ const { allowedHosts, checkMailCallees } = options;
59
+ const allowed = allowedHosts ?? [];
60
+ const mailCallees = new Set(checkMailCallees ?? ['sendMail', 'send']);
61
+ const sourceCode = context.sourceCode;
62
+ const hostVars = new Map();
63
+ function isRequestIdent(name) {
64
+ const lower = name.toLowerCase();
65
+ return lower === 'req' || lower === 'request' || lower === 'ctx';
66
+ }
67
+ function propName(node) {
68
+ if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && !node.computed) {
69
+ return node.property.name;
70
+ }
71
+ if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
72
+ typeof node.property.value === 'string') {
73
+ return node.property.value;
74
+ }
75
+ return null;
76
+ }
77
+ function getHostHeaderSource(node) {
78
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.LogicalExpression) {
79
+ return (getHostHeaderSource(node.left) ?? getHostHeaderSource(node.right));
80
+ }
81
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
82
+ const callee = node.callee;
83
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
84
+ callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
85
+ HOST_GETTER_METHODS.has(callee.property.name) &&
86
+ callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
87
+ isRequestIdent(callee.object.name)) {
88
+ const arg = node.arguments[0];
89
+ if (arg !== undefined &&
90
+ arg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
91
+ typeof arg.value === 'string' &&
92
+ HOST_HEADER_NAMES.has(arg.value.toLowerCase())) {
93
+ return `req.${callee.property.name}('${arg.value}')`;
94
+ }
95
+ }
96
+ return null;
97
+ }
98
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
99
+ const obj = node.object;
100
+ if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
101
+ obj.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
102
+ obj.property.name === 'headers' &&
103
+ obj.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
104
+ isRequestIdent(obj.object.name)) {
105
+ const name = propName(node);
106
+ if (name !== null && HOST_HEADER_NAMES.has(name.toLowerCase())) {
107
+ return `req.headers['${name}']`;
108
+ }
109
+ }
110
+ }
111
+ return null;
112
+ }
113
+ function resolveHostSource(node) {
114
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
115
+ let scope = sourceCode.getScope(node);
116
+ while (scope) {
117
+ const variable = scope.variables.find((v) => v.name === node.name);
118
+ if (variable)
119
+ return hostVars.get(variable) ?? null;
120
+ scope = scope.upper;
121
+ }
122
+ return null;
123
+ }
124
+ return getHostHeaderSource(node);
125
+ }
126
+ function isUrlish(text) {
127
+ return text.includes('://') || text.startsWith('//');
128
+ }
129
+ function isInMailCall(node) {
130
+ let current = node.parent;
131
+ while (current != null) {
132
+ if (current.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
133
+ const callee = current.callee;
134
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
135
+ mailCallees.has(callee.name)) {
136
+ return true;
137
+ }
138
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
139
+ callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
140
+ mailCallees.has(callee.property.name)) {
141
+ return true;
142
+ }
143
+ }
144
+ current = current.parent;
145
+ }
146
+ return false;
147
+ }
148
+ function isValidatedByAllowlist(node) {
149
+ if (allowed.length === 0)
150
+ return false;
151
+ let current = node.parent;
152
+ while (current != null) {
153
+ if (current.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement) {
154
+ const testText = sourceCode.getText(current.test);
155
+ if (allowed.some((host) => testText.includes(host)))
156
+ return true;
157
+ }
158
+ current = current.parent;
159
+ }
160
+ return false;
161
+ }
162
+ function reportHostUse(node, source) {
163
+ if (isValidatedByAllowlist(node))
164
+ return;
165
+ context.report({
166
+ node,
167
+ messageId: 'hostHeaderInLink',
168
+ data: { source },
169
+ suggest: [{ messageId: 'useConfiguredOrigin', fix: () => null }],
170
+ });
171
+ }
172
+ return {
173
+ VariableDeclarator(node) {
174
+ if (node.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || node.init == null) {
175
+ return;
176
+ }
177
+ const source = getHostHeaderSource(node.init);
178
+ if (source === null)
179
+ return;
180
+ for (const variable of sourceCode.getDeclaredVariables(node)) {
181
+ hostVars.set(variable, source);
182
+ }
183
+ },
184
+ TemplateLiteral(node) {
185
+ const urlish = node.quasis.some((q) => isUrlish(q.value.raw));
186
+ for (const expr of node.expressions) {
187
+ const source = resolveHostSource(expr);
188
+ if (source !== null && (urlish || isInMailCall(node))) {
189
+ reportHostUse(expr, source);
190
+ }
191
+ }
192
+ },
193
+ BinaryExpression(node) {
194
+ if (node.operator !== '+')
195
+ return;
196
+ if (node.parent.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression &&
197
+ node.parent.operator === '+') {
198
+ return;
199
+ }
200
+ const operands = [];
201
+ const stack = [node];
202
+ while (stack.length > 0) {
203
+ const current = stack.pop();
204
+ if (current.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression &&
205
+ current.operator === '+') {
206
+ stack.push(current.left, current.right);
207
+ }
208
+ else {
209
+ operands.push(current);
210
+ }
211
+ }
212
+ let urlish = false;
213
+ let hostNode = null;
214
+ let hostSource = null;
215
+ for (const operand of operands) {
216
+ if (operand.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
217
+ typeof operand.value === 'string' &&
218
+ isUrlish(operand.value)) {
219
+ urlish = true;
220
+ }
221
+ if (hostSource === null) {
222
+ const source = resolveHostSource(operand);
223
+ if (source !== null) {
224
+ hostSource = source;
225
+ hostNode = operand;
226
+ }
227
+ }
228
+ }
229
+ if (hostNode !== null && (urlish || isInMailCall(node))) {
230
+ reportHostUse(hostNode, hostSource);
231
+ }
232
+ },
233
+ };
234
+ },
235
+ });
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noIdorResourceAccess = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const utils_1 = require("../../utils");
6
+ const DEFAULT_LOOKUP_METHODS = [
7
+ 'findById',
8
+ 'findByPk',
9
+ 'findOne',
10
+ 'findUnique',
11
+ 'findFirst',
12
+ 'findByIdAndUpdate',
13
+ 'findByIdAndDelete',
14
+ 'findByIdAndRemove',
15
+ 'getById',
16
+ 'deleteOne',
17
+ 'deleteById',
18
+ 'updateOne',
19
+ 'replaceOne',
20
+ ];
21
+ const REQUEST_PARAM = /^(req|request)$/i;
22
+ function isHandlerFunction(node) {
23
+ if (node.type !== eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration &&
24
+ node.type !== eslint_devkit_1.AST_NODE_TYPES.FunctionExpression &&
25
+ node.type !== eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression) {
26
+ return false;
27
+ }
28
+ return node.params.some((param) => param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && REQUEST_PARAM.test(param.name));
29
+ }
30
+ function isRequestKeyArgument(arg) {
31
+ if ((0, utils_1.isClientRequestMember)(arg))
32
+ return true;
33
+ if (arg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
34
+ let found = false;
35
+ (0, utils_1.walk)(arg, (child) => {
36
+ if (found)
37
+ return;
38
+ if ((0, utils_1.isClientRequestMember)(child))
39
+ found = true;
40
+ });
41
+ return found;
42
+ }
43
+ return false;
44
+ }
45
+ exports.noIdorResourceAccess = (0, eslint_devkit_1.createRule)({
46
+ name: 'no-idor-resource-access',
47
+ meta: {
48
+ type: 'problem',
49
+ docs: {
50
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-idor-resource-access.md',
51
+ description: 'Disallow fetching a resource by a request-supplied key in a handler with no principal in scope',
52
+ cwe: 'CWE-639',
53
+ cvss: 7.5,
54
+ confidence: 'medium',
55
+ },
56
+ messages: {
57
+ unscopedResourceLookup: (0, eslint_devkit_1.formatLLMMessage)({
58
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
59
+ issueName: 'Resource Fetched By Client-Supplied Key (CWE-639)',
60
+ cwe: 'CWE-639',
61
+ cvss: 7.5,
62
+ description: '{{method}}() is keyed on {{key}} and nothing in this handler ties the lookup to the caller. Incrementing the id in the URL returns another tenant’s record.',
63
+ severity: 'HIGH',
64
+ fix: "Scope the query to the principal — {{method}}({ _id: {{key}}, owner: req.user.id }) — or verify ownership on the loaded document before responding.",
65
+ documentationLink: 'https://cwe.mitre.org/data/definitions/639.html',
66
+ }),
67
+ },
68
+ schema: [
69
+ {
70
+ type: 'object',
71
+ properties: {
72
+ lookupMethods: {
73
+ type: 'array',
74
+ items: { type: 'string' },
75
+ description: 'Lookup methods treated as a fetch-by-key',
76
+ },
77
+ },
78
+ additionalProperties: false,
79
+ },
80
+ ],
81
+ },
82
+ defaultOptions: [{}],
83
+ create(context, [options]) {
84
+ const { lookupMethods } = options;
85
+ const lookups = new Set(lookupMethods ?? DEFAULT_LOOKUP_METHODS);
86
+ function enclosingHandler(node) {
87
+ let current = node.parent;
88
+ while (current) {
89
+ if (isHandlerFunction(current))
90
+ return current;
91
+ current = current.parent;
92
+ }
93
+ return null;
94
+ }
95
+ return {
96
+ CallExpression(node) {
97
+ const callee = node.callee;
98
+ if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
99
+ return;
100
+ if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
101
+ return;
102
+ if (callee.computed)
103
+ return;
104
+ const method = callee.property.name;
105
+ if (!lookups.has(method))
106
+ return;
107
+ const keyArg = node.arguments.find((arg) => isRequestKeyArgument(arg));
108
+ if (!keyArg)
109
+ return;
110
+ const handler = enclosingHandler(node);
111
+ if (!handler)
112
+ return;
113
+ if ((0, utils_1.readsPrincipal)(handler))
114
+ return;
115
+ context.report({
116
+ node,
117
+ messageId: 'unscopedResourceLookup',
118
+ data: {
119
+ method,
120
+ key: context.sourceCode.getText(keyArg),
121
+ },
122
+ });
123
+ },
124
+ };
125
+ },
126
+ });
@@ -1,16 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noInsecureCookieOptions = void 0;
9
4
  exports.checkCookieOptions = checkCookieOptions;
10
5
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
11
- /**
12
- * Check cookie options object for security flags
13
- */
14
6
  function checkCookieOptions(node, sourceCode, options) {
15
7
  const text = sourceCode.getText(node);
16
8
  const issues = [];
@@ -118,13 +110,10 @@ exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
118
110
  return {
119
111
  CallExpression(node) {
120
112
  const callee = node.callee;
121
- // Check for res.cookie() calls
122
113
  if (callee.type === 'MemberExpression' &&
123
114
  callee.property.type === 'Identifier' &&
124
115
  callee.property.name === 'cookie') {
125
- // res.cookie(name, value, options)
126
116
  const optionsArg = node.arguments[2];
127
- // No options provided
128
117
  if (!optionsArg) {
129
118
  context.report({
130
119
  node,
@@ -144,7 +133,6 @@ exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
144
133
  });
145
134
  return;
146
135
  }
147
- // Options is an object expression
148
136
  if (optionsArg.type === 'ObjectExpression') {
149
137
  const { issues } = checkCookieOptions(optionsArg, sourceCode, options);
150
138
  if (issues.length > 0) {