eslint-plugin-express-security 1.4.0 → 1.5.1

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 (59) hide show
  1. package/README.md +7 -0
  2. package/package.json +5 -18
  3. package/src/index.d.ts +17 -40
  4. package/src/index.js +26 -66
  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 +0 -26
  11. package/src/rules/no-exposed-debug-endpoints/index.js +0 -19
  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 +0 -31
  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 +0 -40
  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 +1 -26
  23. package/src/rules/no-static-root-exposure/index.js +0 -21
  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 +0 -45
  27. package/src/rules/require-case-insensitive-path-guard/index.js +0 -21
  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 +0 -20
  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 -192
  39. package/src/rules/no-cors-credentials-wildcard/index.d.ts +0 -26
  40. package/src/rules/no-error-details-in-response/index.d.ts +0 -57
  41. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -14
  42. package/src/rules/no-express-unsafe-regex-route/index.d.ts +0 -27
  43. package/src/rules/no-graphql-introspection-production/index.d.ts +0 -26
  44. package/src/rules/no-host-header-in-links/index.d.ts +0 -56
  45. package/src/rules/no-insecure-cookie-options/index.d.ts +0 -39
  46. package/src/rules/no-missing-cors-check/index.d.ts +0 -28
  47. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -30
  48. package/src/rules/no-missing-security-headers/index.d.ts +0 -26
  49. package/src/rules/no-permissive-cors/index.d.ts +0 -28
  50. package/src/rules/no-sensitive-data-in-query/index.d.ts +0 -51
  51. package/src/rules/no-static-root-exposure/index.d.ts +0 -45
  52. package/src/rules/no-user-controlled-redirect/index.d.ts +0 -44
  53. package/src/rules/no-user-controlled-render-locals/index.d.ts +0 -49
  54. package/src/rules/require-case-insensitive-path-guard/index.d.ts +0 -59
  55. package/src/rules/require-csrf-protection/index.d.ts +0 -28
  56. package/src/rules/require-express-body-parser-limits/index.d.ts +0 -31
  57. package/src/rules/require-helmet/index.d.ts +0 -29
  58. package/src/rules/require-query-type-guard/index.d.ts +0 -54
  59. package/src/rules/require-rate-limiting/index.d.ts +0 -31
@@ -1,17 +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.noUserControlledRenderLocals = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /** Request properties that carry whole user-controlled objects. */
11
5
  const USER_SOURCE_PROPS = new Set(['body', 'query', 'params']);
12
- /** Response object names (matched case-insensitively). */
13
6
  const RESPONSE_NAMES = new Set(['res', 'response', 'reply']);
14
- /** Request object names (matched case-insensitively). */
15
7
  const REQUEST_NAMES = new Set(['req', 'request', 'ctx']);
16
8
  exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
17
9
  name: 'no-user-controlled-render-locals',
@@ -63,13 +55,7 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
63
55
  create(context, [options]) {
64
56
  const { allowSanitizers } = options;
65
57
  const sanitizers = new Set(allowSanitizers ?? []);
66
- /**
67
- * Single-assignment tracking keyed by the RESOLVED scope variable, not by
68
- * name — two handlers in the same file can each declare `locals`, and a
69
- * name-keyed map would leak the first one's origin into the second.
70
- */
71
58
  const trackedVars = new Map();
72
- /** The scope variable an identifier resolves to, or null if unresolved. */
73
59
  function resolveVariable(node) {
74
60
  let scope = context.sourceCode.getScope(node);
75
61
  while (scope) {
@@ -80,7 +66,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
80
66
  }
81
67
  return null;
82
68
  }
83
- /** Tracked origin for an identifier, resolved through scope. */
84
69
  function getTracked(node) {
85
70
  const variable = resolveVariable(node);
86
71
  return variable ? trackedVars.get(variable) : undefined;
@@ -88,11 +73,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
88
73
  function isRequestName(name) {
89
74
  return REQUEST_NAMES.has(name.toLowerCase());
90
75
  }
91
- /**
92
- * Returns "req.<prop>" when `node` is a WHOLE user-source object access —
93
- * exactly `<req>.body`, `<req>.query` or `<req>.params` (two levels).
94
- * Field accesses like req.body.title are NOT whole objects.
95
- */
96
76
  function getWholeSource(node) {
97
77
  if (node.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
98
78
  return null;
@@ -101,7 +81,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
101
81
  return null;
102
82
  if (property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
103
83
  return null;
104
- // req[body] reads whatever `body` holds — not the request body.
105
84
  if (node.computed)
106
85
  return null;
107
86
  if (!USER_SOURCE_PROPS.has(property.name))
@@ -110,7 +89,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
110
89
  return null;
111
90
  return `req.${property.name}`;
112
91
  }
113
- /** True when the call's callee name is in the allowSanitizers option. */
114
92
  function isSanitizerCall(node) {
115
93
  const callee = node.callee;
116
94
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
@@ -122,12 +100,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
122
100
  }
123
101
  return false;
124
102
  }
125
- /**
126
- * Returns the origin when `node` would flow a WHOLE user-controlled
127
- * object into render locals: a direct req.body/query/params access, an
128
- * identifier tracked as whole, or a non-sanitizer call that forwards a
129
- * whole source (transform(req.body)).
130
- */
131
103
  function getUnsafeLocalsSource(node) {
132
104
  const direct = getWholeSource(node);
133
105
  if (direct)
@@ -149,11 +121,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
149
121
  }
150
122
  return null;
151
123
  }
152
- /**
153
- * Returns the origin when `node` DERIVES from user input in any way —
154
- * used for the view-name argument, where even a single field
155
- * (req.params.page) enables path traversal.
156
- */
157
124
  function getDerivedSource(node) {
158
125
  const whole = getWholeSource(node);
159
126
  if (whole)
@@ -185,7 +152,6 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
185
152
  }
186
153
  return null;
187
154
  }
188
- /** True when `<res>.render(...)` — response ident + literal .render. */
189
155
  function isRenderCall(node) {
190
156
  const callee = node.callee;
191
157
  if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
@@ -199,15 +165,9 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
199
165
  return false;
200
166
  return RESPONSE_NAMES.has(obj.name.toLowerCase());
201
167
  }
202
- /**
203
- * Suggestion fix: delete a `...req.x` spread element (and its adjoining
204
- * comma) from an object literal.
205
- */
206
168
  function buildRemoveSpreadFix(spread) {
207
169
  return (fixer) => {
208
170
  const sourceCode = context.sourceCode;
209
- // Inside an ObjectExpression a spread always has a token on each side
210
- // ('{' or ',' before; ',' or '}' after), so these casts are safe.
211
171
  const tokenAfter = sourceCode.getTokenAfter(spread);
212
172
  const tokenBefore = sourceCode.getTokenBefore(spread);
213
173
  if (tokenAfter.value === ',') {
@@ -250,14 +210,12 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
250
210
  });
251
211
  }
252
212
  }
253
- /** Records the origin of a single-assignment declaration. */
254
213
  function trackDeclarator(declared, init) {
255
214
  const unsafe = getUnsafeLocalsSource(init);
256
215
  if (unsafe) {
257
216
  trackedVars.set(declared, { source: unsafe, whole: true });
258
217
  return;
259
218
  }
260
- // const locals = { ...req.body } still carries the whole object
261
219
  if (init.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
262
220
  for (const prop of init.properties) {
263
221
  if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.SpreadElement)
@@ -277,14 +235,11 @@ exports.noUserControlledRenderLocals = (0, eslint_devkit_1.createRule)({
277
235
  }
278
236
  return {
279
237
  VariableDeclarator(node) {
280
- // Destructuring (const { title } = req.body) IS field-picking — safe.
281
238
  if (node.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
282
239
  return;
283
240
  const init = node.init;
284
241
  if (!init)
285
242
  return;
286
- // Exactly one variable for an Identifier id — the loop keeps the
287
- // lookup total, with no unreachable null-guard to cover.
288
243
  for (const declared of context.sourceCode.getDeclaredVariables(node)) {
289
244
  trackDeclarator(declared, init);
290
245
  }
@@ -1,15 +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.requireCaseInsensitivePathGuard = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /** Request properties that carry the incoming path. */
11
5
  const PATH_PROPS = new Set(['path', 'url', 'originalUrl']);
12
- /** String methods used as path guards. */
13
6
  const GUARD_METHODS = new Set([
14
7
  'startsWith',
15
8
  'endsWith',
@@ -17,14 +10,7 @@ const GUARD_METHODS = new Set([
17
10
  'indexOf',
18
11
  'match',
19
12
  ]);
20
- /** Equality operators used as path guards. */
21
13
  const EQUALITY_OPS = new Set(['===', '==', '!==', '!=']);
22
- /**
23
- * Lower-cases a path literal and re-quotes it for source output. Prefers the
24
- * repo-idiomatic single quotes, but falls back to `JSON.stringify`'s
25
- * double-quoted, fully-escaped form when the value contains a quote or
26
- * backslash — naive `'${value}'` interpolation emits a syntax error there.
27
- */
28
14
  function quoteLiteral(value) {
29
15
  const json = JSON.stringify(value.toLowerCase());
30
16
  const inner = json.slice(1, -1);
@@ -89,10 +75,6 @@ exports.requireCaseInsensitivePathGuard = (0, eslint_devkit_1.createRule)({
89
75
  const lower = name.toLowerCase();
90
76
  return lower === 'req' || lower === 'request';
91
77
  }
92
- /**
93
- * `req.path`, `request.url`, `req.originalUrl` — a direct, non-computed
94
- * member access on a request identifier.
95
- */
96
78
  function isPathAccess(node) {
97
79
  return (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
98
80
  !node.computed &&
@@ -139,8 +121,6 @@ exports.requireCaseInsensitivePathGuard = (0, eslint_devkit_1.createRule)({
139
121
  return;
140
122
  if (!GUARD_METHODS.has(callee.property.name))
141
123
  return;
142
- // Route registrations (app.get('/admin', ...)) never match here:
143
- // the object must be a req.path-style access, not an app/router object.
144
124
  if (!isPathAccess(callee.object))
145
125
  return;
146
126
  const arg = node.arguments[0];
@@ -148,7 +128,6 @@ exports.requireCaseInsensitivePathGuard = (0, eslint_devkit_1.createRule)({
148
128
  return;
149
129
  if (arg.type !== eslint_devkit_1.AST_NODE_TYPES.Literal)
150
130
  return;
151
- // req.path.match(/^\/admin/) — regex literal guard
152
131
  if ('regex' in arg) {
153
132
  if (arg.regex.flags.includes('i'))
154
133
  return;
@@ -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
  });
@@ -1,13 +1,7 @@
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.requireQueryTypeGuard = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /** String.prototype methods that throw or misbehave on string[] / ParsedQs. */
11
5
  const STRING_METHODS = new Set([
12
6
  'replace',
13
7
  'toLowerCase',
@@ -84,7 +78,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
84
78
  const lower = name.toLowerCase();
85
79
  return lower === 'req' || lower === 'request';
86
80
  }
87
- /** `req.query` / `request.query` — non-computed. */
88
81
  function isReqQuery(node) {
89
82
  return (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
90
83
  !node.computed &&
@@ -93,15 +86,12 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
93
86
  node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
94
87
  node.property.name === 'query');
95
88
  }
96
- /** `req.query.name` or `req.query['x']` — a member on the query object. */
97
89
  function isQueryMember(node) {
98
90
  return (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && isReqQuery(node.object));
99
91
  }
100
- /** Stable key for a query member: source text of its property node. */
101
92
  function propKey(node) {
102
93
  return sourceCode.getText(node.property);
103
94
  }
104
- /** Mark an identifier as proven-string, in the frame that tracks it. */
105
95
  function guardVar(name) {
106
96
  for (let i = frames.length - 1; i >= 0; i--) {
107
97
  if (frames[i].tracked.has(name)) {
@@ -111,7 +101,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
111
101
  }
112
102
  current().guardedVars.add(name);
113
103
  }
114
- /** Mark a typeof / Array.isArray guard target (identifier or query member). */
115
104
  function markGuard(target) {
116
105
  if (target.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
117
106
  guardVar(target.name);
@@ -134,7 +123,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
134
123
  }
135
124
  return null;
136
125
  }
137
- /** `typeof X === 'string'` (either operand order) → X, else null. */
138
126
  function extractTypeofTarget(a, b) {
139
127
  if (a.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression &&
140
128
  a.operator === 'typeof' &&
@@ -144,7 +132,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
144
132
  }
145
133
  return null;
146
134
  }
147
- /** `Array.isArray(...)` call. */
148
135
  function isArrayIsArrayCall(node) {
149
136
  const callee = node.callee;
150
137
  return (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
@@ -153,7 +140,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
153
140
  callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
154
141
  callee.property.name === 'isArray');
155
142
  }
156
- /** Call whose result is a proven-safe string source (coercer / validator). */
157
143
  function isSafeCall(node) {
158
144
  if (node.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression)
159
145
  return false;
@@ -190,8 +176,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
190
176
  const init = node.init;
191
177
  if (!init)
192
178
  return;
193
- // Only a RAW query member taints; String(req.query.x), schema.parse(...)
194
- // and every other init shape is left untracked.
195
179
  if (isQueryMember(init)) {
196
180
  current().tracked.set(node.id.name, init);
197
181
  }
@@ -205,7 +189,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
205
189
  current().tracked.set(node.left.name, node.right);
206
190
  return;
207
191
  }
208
- // v = String(v) / v = schema.parse(v) — proven safe from here on.
209
192
  if (isSafeCall(node.right)) {
210
193
  guardVar(node.left.name);
211
194
  }
@@ -219,7 +202,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
219
202
  markGuard(target);
220
203
  },
221
204
  CallExpression(node) {
222
- // Array.isArray(v) is a guard, not a violation.
223
205
  if (isArrayIsArrayCall(node)) {
224
206
  const arg = node.arguments[0];
225
207
  if (arg)
@@ -235,7 +217,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
235
217
  if (!STRING_METHODS.has(method))
236
218
  return;
237
219
  const obj = callee.object;
238
- // Shape 1: direct member call — req.query.name.replace(...)
239
220
  if (isQueryMember(obj)) {
240
221
  if (isPropGuarded(propKey(obj)))
241
222
  return;
@@ -253,7 +234,6 @@ exports.requireQueryTypeGuard = (0, eslint_devkit_1.createRule)({
253
234
  });
254
235
  return;
255
236
  }
256
- // Shape 2: call on an identifier assigned from a raw query member.
257
237
  if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
258
238
  return;
259
239
  const trackedInit = lookupTracked(obj.name);