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
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireCaseInsensitivePathGuard = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const PATH_PROPS = new Set(['path', 'url', 'originalUrl']);
6
+ const GUARD_METHODS = new Set([
7
+ 'startsWith',
8
+ 'endsWith',
9
+ 'includes',
10
+ 'indexOf',
11
+ 'match',
12
+ ]);
13
+ const EQUALITY_OPS = new Set(['===', '==', '!==', '!=']);
14
+ function quoteLiteral(value) {
15
+ const json = JSON.stringify(value.toLowerCase());
16
+ const inner = json.slice(1, -1);
17
+ return /['\\]/.test(inner) ? json : `'${inner}'`;
18
+ }
19
+ const DEFAULT_PROTECTED_PATHS = [
20
+ 'admin',
21
+ 'api',
22
+ 'dashboard',
23
+ 'internal',
24
+ 'private',
25
+ ];
26
+ exports.requireCaseInsensitivePathGuard = (0, eslint_devkit_1.createRule)({
27
+ name: 'require-case-insensitive-path-guard',
28
+ meta: {
29
+ type: 'problem',
30
+ hasSuggestions: true,
31
+ docs: {
32
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-case-insensitive-path-guard.md',
33
+ description: 'Require case-insensitive comparison when guarding protected paths via req.path / req.url / req.originalUrl',
34
+ cwe: 'CWE-178',
35
+ cvss: 7.3,
36
+ },
37
+ messages: {
38
+ caseSensitivePathGuard: (0, eslint_devkit_1.formatLLMMessage)({
39
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
40
+ issueName: 'Case-Sensitive Path Guard (CWE-178)',
41
+ cwe: 'CWE-178',
42
+ description: "{{pathExpr}} is compared case-sensitively against '{{value}}', but Express routes can match case-insensitively. A request to an upper-cased variant (e.g. /Admin) reaches the handler without ever hitting this guard.",
43
+ severity: 'HIGH',
44
+ fix: 'Normalize the path with .toLowerCase() before comparing (and lower-case the compared literal), or add the /i flag to the guard regex.',
45
+ documentationLink: 'https://cwe.mitre.org/data/definitions/178.html',
46
+ }),
47
+ addToLowerCase: 'Normalize with .toLowerCase() before comparing',
48
+ addIgnoreCaseFlag: 'Add the i flag to the guard regex',
49
+ },
50
+ schema: [
51
+ {
52
+ type: 'object',
53
+ properties: {
54
+ protectedPaths: {
55
+ type: 'array',
56
+ items: { type: 'string' },
57
+ description: 'Substrings that mark a compared value as a protected path',
58
+ },
59
+ checkAllPaths: {
60
+ type: 'boolean',
61
+ description: 'Flag every case-sensitive path guard regardless of the compared value',
62
+ },
63
+ },
64
+ additionalProperties: false,
65
+ },
66
+ ],
67
+ },
68
+ defaultOptions: [{}],
69
+ create(context, [options]) {
70
+ const { protectedPaths, checkAllPaths } = options;
71
+ const patterns = (protectedPaths ?? DEFAULT_PROTECTED_PATHS).map((p) => p.toLowerCase());
72
+ const flagAll = checkAllPaths ?? false;
73
+ const sourceCode = context.sourceCode;
74
+ function isRequestIdent(name) {
75
+ const lower = name.toLowerCase();
76
+ return lower === 'req' || lower === 'request';
77
+ }
78
+ function isPathAccess(node) {
79
+ return (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
80
+ !node.computed &&
81
+ node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
82
+ isRequestIdent(node.object.name) &&
83
+ node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
84
+ PATH_PROPS.has(node.property.name));
85
+ }
86
+ function isProtectedValue(value) {
87
+ if (flagAll)
88
+ return true;
89
+ const lower = value.toLowerCase();
90
+ return patterns.some((p) => lower.includes(p));
91
+ }
92
+ function isStringLiteral(node) {
93
+ return (node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'string');
94
+ }
95
+ function reportWithLowerCaseSuggestion(node, pathNode, literalNode) {
96
+ const value = literalNode.value;
97
+ context.report({
98
+ node,
99
+ messageId: 'caseSensitivePathGuard',
100
+ data: { pathExpr: sourceCode.getText(pathNode), value },
101
+ suggest: [
102
+ {
103
+ messageId: 'addToLowerCase',
104
+ fix(fixer) {
105
+ const fixes = [fixer.insertTextAfter(pathNode, '.toLowerCase()')];
106
+ if (/[A-Z]/.test(value)) {
107
+ fixes.push(fixer.replaceText(literalNode, quoteLiteral(value)));
108
+ }
109
+ return fixes;
110
+ },
111
+ },
112
+ ],
113
+ });
114
+ }
115
+ return {
116
+ CallExpression(node) {
117
+ const callee = node.callee;
118
+ if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
119
+ return;
120
+ if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
121
+ return;
122
+ if (!GUARD_METHODS.has(callee.property.name))
123
+ return;
124
+ if (!isPathAccess(callee.object))
125
+ return;
126
+ const arg = node.arguments[0];
127
+ if (!arg)
128
+ return;
129
+ if (arg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal)
130
+ return;
131
+ if ('regex' in arg) {
132
+ if (arg.regex.flags.includes('i'))
133
+ return;
134
+ if (!isProtectedValue(arg.regex.pattern))
135
+ return;
136
+ context.report({
137
+ node,
138
+ messageId: 'caseSensitivePathGuard',
139
+ data: {
140
+ pathExpr: sourceCode.getText(callee.object),
141
+ value: arg.regex.pattern,
142
+ },
143
+ suggest: [
144
+ {
145
+ messageId: 'addIgnoreCaseFlag',
146
+ fix: (fixer) => fixer.insertTextAfter(arg, 'i'),
147
+ },
148
+ ],
149
+ });
150
+ return;
151
+ }
152
+ if (typeof arg.value !== 'string')
153
+ return;
154
+ if (!isProtectedValue(arg.value))
155
+ return;
156
+ reportWithLowerCaseSuggestion(node, callee.object, arg);
157
+ },
158
+ BinaryExpression(node) {
159
+ if (!EQUALITY_OPS.has(node.operator))
160
+ return;
161
+ let pathNode;
162
+ let literalNode;
163
+ if (isPathAccess(node.left) && isStringLiteral(node.right)) {
164
+ pathNode = node.left;
165
+ literalNode = node.right;
166
+ }
167
+ else if (isPathAccess(node.right) && isStringLiteral(node.left)) {
168
+ pathNode = node.right;
169
+ literalNode = node.left;
170
+ }
171
+ else {
172
+ return;
173
+ }
174
+ if (!isProtectedValue(literalNode.value))
175
+ return;
176
+ reportWithLowerCaseSuggestion(node, pathNode, literalNode);
177
+ },
178
+ };
179
+ },
180
+ });
@@ -1,24 +1,14 @@
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.requireCsrfProtection = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const DEFAULT_PROTECTED_METHODS = ['post', 'put', 'patch', 'delete'];
11
- /**
12
- * Check if a call is a CSRF middleware usage
13
- */
14
6
  function isCsrfMiddleware(node) {
15
7
  const callee = node.callee;
16
- // app.use(csrf()) or app.use(csurf())
17
8
  if (callee.type === 'Identifier') {
18
9
  const name = callee.name.toLowerCase();
19
10
  return name === 'csrf' || name === 'csurf' || name === 'csrfprotection';
20
11
  }
21
- // lusca.csrf()
22
12
  if (callee.type === 'MemberExpression' &&
23
13
  callee.object.type === 'Identifier' &&
24
14
  callee.object.name === 'lusca' &&
@@ -28,17 +18,10 @@ function isCsrfMiddleware(node) {
28
18
  }
29
19
  return false;
30
20
  }
31
- /**
32
- * Check if route handler has CSRF middleware in its chain
33
- */
34
21
  function hasCsrfInMiddlewareChain(node, sourceCode) {
35
22
  const text = sourceCode.getText(node);
36
- // Check for csrf/csurf in the middleware chain
37
23
  return /\b(csrf|csurf|csrfProtection|csrfMiddleware)\s*\(?\)?/.test(text);
38
24
  }
39
- /**
40
- * Known Express app/router variable names
41
- */
42
25
  const EXPRESS_IDENTIFIERS = new Set([
43
26
  'app',
44
27
  'router',
@@ -47,30 +30,19 @@ const EXPRESS_IDENTIFIERS = new Set([
47
30
  'routes',
48
31
  'express',
49
32
  ]);
50
- /**
51
- * Check if the callee object is likely an Express app or router
52
- * This prevents false positives on non-Express objects
53
- */
54
33
  function isLikelyExpressObject(callee) {
55
34
  const obj = callee.object;
56
- // Direct identifier: app.post(), router.post()
57
35
  if (obj.type === 'Identifier') {
58
- // Check known Express variable names
59
36
  if (EXPRESS_IDENTIFIERS.has(obj.name)) {
60
37
  return true;
61
38
  }
62
- // Skip unknown identifiers to avoid FPs
63
- // Names like 'server', 'customApi', 'controller' are not Express
64
39
  return false;
65
40
  }
66
- // Call expression: express().post(), express.Router().post()
67
41
  if (obj.type === 'CallExpression') {
68
42
  const objCallee = obj.callee;
69
- // express()
70
43
  if (objCallee.type === 'Identifier' && objCallee.name === 'express') {
71
44
  return true;
72
45
  }
73
- // express.Router()
74
46
  if (objCallee.type === 'MemberExpression' &&
75
47
  objCallee.object.type === 'Identifier' &&
76
48
  objCallee.object.name === 'express' &&
@@ -79,7 +51,6 @@ function isLikelyExpressObject(callee) {
79
51
  return true;
80
52
  }
81
53
  }
82
- // Member expression: this.app, this.router - skip to avoid FPs
83
54
  if (obj.type === 'MemberExpression') {
84
55
  return false;
85
56
  }
@@ -157,9 +128,6 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
157
128
  }
158
129
  const sourceCode = context.sourceCode;
159
130
  let hasGlobalCsrf = false;
160
- /**
161
- * Check if route matches ignore patterns
162
- */
163
131
  function shouldIgnoreRoute(routeArg) {
164
132
  if (routeArg.type !== 'Literal' || typeof routeArg.value !== 'string') {
165
133
  return false;
@@ -177,17 +145,14 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
177
145
  return {
178
146
  CallExpression(node) {
179
147
  const callee = node.callee;
180
- // Check for global app.use(csrf()) or app.use(csrfMiddleware)
181
148
  if (callee.type === 'MemberExpression' &&
182
149
  callee.property.type === 'Identifier' &&
183
150
  callee.property.name === 'use') {
184
151
  for (const arg of node.arguments) {
185
- // app.use(csrf())
186
152
  if (arg.type === 'CallExpression' && isCsrfMiddleware(arg)) {
187
153
  hasGlobalCsrf = true;
188
154
  return;
189
155
  }
190
- // app.use(csrfMiddleware) - variable reference
191
156
  if (arg.type === 'Identifier') {
192
157
  const name = arg.name.toLowerCase();
193
158
  if (name.includes('csrf') || name.includes('csurf')) {
@@ -197,32 +162,25 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
197
162
  }
198
163
  }
199
164
  }
200
- // Check for route handlers: app.post(), router.put(), etc.
201
165
  if (callee.type === 'MemberExpression' &&
202
166
  callee.property.type === 'Identifier') {
203
167
  const method = callee.property.name.toLowerCase();
204
168
  if (!protectedMethods.includes(method)) {
205
169
  return;
206
170
  }
207
- // Only flag if this looks like an Express app/router
208
- // This prevents FPs on non-Express objects like server.post(), customApi.post()
209
171
  if (!isLikelyExpressObject(callee)) {
210
172
  return;
211
173
  }
212
- // Skip if global CSRF is already set up
213
174
  if (hasGlobalCsrf) {
214
175
  return;
215
176
  }
216
- // Check if route should be ignored
217
177
  const routeArg = node.arguments[0];
218
178
  if (routeArg && shouldIgnoreRoute(routeArg)) {
219
179
  return;
220
180
  }
221
- // Check if CSRF middleware is in the handler chain
222
181
  if (hasCsrfInMiddlewareChain(node, sourceCode)) {
223
182
  return;
224
183
  }
225
- // Report missing CSRF
226
184
  context.report({
227
185
  node,
228
186
  messageId: 'missingCsrf',
@@ -1,9 +1,4 @@
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.requireExpressBodyParserLimits = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -19,13 +14,7 @@ const DEFAULT_EXCESSIVE_LIMITS = [
19
14
  '100MB',
20
15
  '500MB',
21
16
  ];
22
- /**
23
- * Body parser function names to check
24
- */
25
17
  const BODY_PARSER_METHODS = new Set(['json', 'urlencoded', 'raw', 'text']);
26
- /**
27
- * Check if a property has a limit option
28
- */
29
18
  function getLimitOption(properties) {
30
19
  for (const prop of properties) {
31
20
  if (prop.type === 'Property' &&
@@ -36,9 +25,6 @@ function getLimitOption(properties) {
36
25
  }
37
26
  return null;
38
27
  }
39
- /**
40
- * Check if the limit value is considered excessive
41
- */
42
28
  function isExcessiveLimit(value, excessiveLimits) {
43
29
  if (value.type === 'Literal' && typeof value.value === 'string') {
44
30
  return excessiveLimits.some((limit) => value.value === limit || String(value.value).toLowerCase() === limit.toLowerCase());
@@ -126,14 +112,11 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
126
112
  return {
127
113
  CallExpression(node) {
128
114
  const callee = node.callee;
129
- // Check for express.json(), express.urlencoded(), etc.
130
- // or bodyParser.json(), bodyParser.urlencoded(), etc.
131
115
  if (callee.type !== 'MemberExpression') {
132
116
  return;
133
117
  }
134
118
  const object = callee.object;
135
119
  const property = callee.property;
136
- // Check if it's express.* or bodyParser.*
137
120
  if (object.type !== 'Identifier') {
138
121
  return;
139
122
  }
@@ -146,9 +129,7 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
146
129
  if (!BODY_PARSER_METHODS.has(property.name)) {
147
130
  return;
148
131
  }
149
- // Check arguments
150
132
  const firstArg = node.arguments[0];
151
- // No options provided - missing limit
152
133
  if (!firstArg) {
153
134
  const sourceCode = context.sourceCode;
154
135
  const calleeText = sourceCode.getText(callee);
@@ -159,7 +140,6 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
159
140
  {
160
141
  messageId: 'addLimit',
161
142
  fix: (fixer) => {
162
- // Replace the entire call with options
163
143
  return fixer.replaceText(node, `${calleeText}({ limit: '100kb' })`);
164
144
  },
165
145
  },
@@ -167,11 +147,9 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
167
147
  });
168
148
  return;
169
149
  }
170
- // Options provided but check for limit
171
150
  if (firstArg.type === 'ObjectExpression') {
172
151
  const limitProp = getLimitOption(firstArg.properties);
173
152
  if (!limitProp) {
174
- // No limit in options
175
153
  context.report({
176
154
  node,
177
155
  messageId: 'missingLimit',
@@ -179,7 +157,6 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
179
157
  {
180
158
  messageId: 'addLimit',
181
159
  fix: (fixer) => {
182
- // Add limit to existing options
183
160
  const lastProp = firstArg.properties[firstArg.properties.length - 1];
184
161
  if (lastProp) {
185
162
  return fixer.insertTextAfter(lastProp, ", limit: '100kb'");
@@ -191,7 +168,6 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
191
168
  });
192
169
  return;
193
170
  }
194
- // Check if limit is excessive
195
171
  if (isExcessiveLimit(limitProp.value, excessiveLimits)) {
196
172
  context.report({
197
173
  node: limitProp,
@@ -1,18 +1,9 @@
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.requireHelmet = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /**
11
- * Check if a node is an app.use() call with helmet
12
- */
13
5
  function isHelmetMiddleware(node) {
14
6
  const callee = node.callee;
15
- // Check for app.use(helmet()) or app.use(helmet.contentSecurityPolicy())
16
7
  if (callee.type !== 'MemberExpression') {
17
8
  return false;
18
9
  }
@@ -20,31 +11,24 @@ function isHelmetMiddleware(node) {
20
11
  callee.property.name !== 'use') {
21
12
  return false;
22
13
  }
23
- // Check arguments for helmet usage
24
14
  for (const arg of node.arguments) {
25
15
  if (arg.type === 'CallExpression') {
26
16
  const argCallee = arg.callee;
27
- // helmet()
28
17
  if (argCallee.type === 'Identifier' && argCallee.name === 'helmet') {
29
18
  return true;
30
19
  }
31
- // helmet.contentSecurityPolicy() etc.
32
20
  if (argCallee.type === 'MemberExpression' &&
33
21
  argCallee.object.type === 'Identifier' &&
34
22
  argCallee.object.name === 'helmet') {
35
23
  return true;
36
24
  }
37
25
  }
38
- // app.use(helmet) without call (unlikely but possible)
39
26
  if (arg.type === 'Identifier' && arg.name === 'helmet') {
40
27
  return true;
41
28
  }
42
29
  }
43
30
  return false;
44
31
  }
45
- /**
46
- * Check if middleware is an alternative security headers middleware
47
- */
48
32
  function isAlternativeMiddleware(node, alternatives) {
49
33
  for (const arg of node.arguments) {
50
34
  if (arg.type === 'CallExpression' && arg.callee.type === 'Identifier') {
@@ -123,7 +107,6 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
123
107
  ],
124
108
  create(context, [options]) {
125
109
  const { allowInTests = false, alternativeMiddleware = [], assumeHelmetMiddleware = false } = options;
126
- // Skip entirely if helmet/security headers are assumed to be provided elsewhere
127
110
  if (assumeHelmetMiddleware) {
128
111
  return {};
129
112
  }
@@ -132,21 +115,17 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
132
115
  if (isTestFile) {
133
116
  return {};
134
117
  }
135
- // Track if we've seen express() call and helmet usage
136
118
  let hasExpressApp = false;
137
119
  let hasHelmet = false;
138
120
  let expressAppNode = null;
139
121
  return {
140
- // Detect express() app creation
141
122
  CallExpression(node) {
142
123
  const callee = node.callee;
143
- // Check for express() call
144
124
  if (callee.type === 'Identifier' && callee.name === 'express') {
145
125
  hasExpressApp = true;
146
126
  expressAppNode = node;
147
127
  return;
148
128
  }
149
- // Check for require('express')() pattern
150
129
  if (callee.type === 'CallExpression' &&
151
130
  callee.callee.type === 'Identifier' &&
152
131
  callee.callee.name === 'require') {
@@ -159,18 +138,15 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
159
138
  return;
160
139
  }
161
140
  }
162
- // Check for helmet middleware usage
163
141
  if (isHelmetMiddleware(node)) {
164
142
  hasHelmet = true;
165
143
  return;
166
144
  }
167
- // Check for alternative middleware
168
145
  if (isAlternativeMiddleware(node, alternativeMiddleware)) {
169
146
  hasHelmet = true;
170
147
  return;
171
148
  }
172
149
  },
173
- // Report at the end of the file if express app exists but no helmet
174
150
  'Program:exit'() {
175
151
  if (hasExpressApp && !hasHelmet && expressAppNode) {
176
152
  context.report({
@@ -179,7 +155,7 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
179
155
  suggest: [
180
156
  {
181
157
  messageId: 'addHelmet',
182
- fix: () => null, // Manual fix required - need to add import and app.use()
158
+ fix: () => null,
183
159
  },
184
160
  ],
185
161
  });