eslint-plugin-express-security 1.3.1 → 1.3.2

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 CHANGED
@@ -27,7 +27,7 @@ nx lint eslint-plugin-express-security
27
27
  - Use `AST_NODE_TYPES` constants, never string literals for node types
28
28
  - Use `formatLLMMessage()` for all rule error messages
29
29
  - Include CWE, CVSS, OWASP in every security message
30
- - Use `c8 ignore` comments with documented reasons for untestable code
30
+ - Coverage-ignore comments (`c8 ignore`, `v8 ignore`, `istanbul ignore`) are banned — write a test for the branch (synthetic AST / mock context if parser-unreachable) or delete it if dead
31
31
  - Single-pass AST traversal patterns (O(n) complexity)
32
32
  - Detect Express objects through heuristics (variable naming, import analysis)
33
33
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [1.2.3] - 2026-02-08
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
8
+
3
9
  ## 1.3.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  <a href="https://www.npmjs.com/package/eslint-plugin-express-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-express-security.svg" alt="NPM Version" /></a>
11
11
  <a href="https://www.npmjs.com/package/eslint-plugin-express-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-express-security.svg" alt="NPM Downloads" /></a>
12
12
  <a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
13
- <a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=express-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=express-security" alt="Codecov" /></a>
13
+ <a href="https://app.codecov.io/gh/ofri-peretz/eslint/tree/main" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?flag=eslint-plugin-express-security" alt="Codecov" /></a>
14
14
  <a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
15
15
  </p>
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-express-security",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Security-focused ESLint plugin for Express.js applications. Detects insecure cookies, missing security headers, CORS misconfigurations, CSRF vulnerabilities, GraphQL security issues, and more.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -59,7 +59,7 @@ exports.rules = {
59
59
  exports.plugin = {
60
60
  meta: {
61
61
  name: 'eslint-plugin-express-security',
62
- version: '1.3.1',
62
+ version: '1.3.2',
63
63
  },
64
64
  rules: exports.rules,
65
65
  };
@@ -115,7 +115,7 @@ exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
115
115
  allowInTests: false,
116
116
  },
117
117
  ],
118
- create(context, [options = {}]) {
118
+ create(context, [options]) {
119
119
  const { allowInTests = false } = options;
120
120
  const filename = context.filename;
121
121
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -137,7 +137,7 @@ exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
137
137
  suggest: [
138
138
  {
139
139
  messageId: 'useExplicitOrigins',
140
- fix: /* c8 ignore next */ () => null,
140
+ fix: () => null,
141
141
  },
142
142
  ],
143
143
  });
@@ -99,7 +99,7 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
99
99
  ],
100
100
  },
101
101
  defaultOptions: [{ allowInTests: false }],
102
- create(context, [options = {}]) {
102
+ create(context, [options]) {
103
103
  const { allowInTests = false } = options;
104
104
  const filename = context.filename;
105
105
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -110,12 +110,10 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
110
110
  CallExpression(node) {
111
111
  const callee = node.callee;
112
112
  // Check for app.get(), router.post(), etc.
113
- /* c8 ignore next 2 */
114
113
  if (callee.type !== 'MemberExpression') {
115
114
  return;
116
115
  }
117
116
  const property = callee.property;
118
- /* c8 ignore next 2 */
119
117
  if (property.type !== 'Identifier') {
120
118
  return;
121
119
  }
@@ -124,7 +122,6 @@ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
124
122
  }
125
123
  // Check the route argument (first argument)
126
124
  const routeArg = node.arguments[0];
127
- /* c8 ignore next 2 */
128
125
  if (!routeArg) {
129
126
  return;
130
127
  }
@@ -87,7 +87,7 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
87
87
  allowInDevelopment: true,
88
88
  },
89
89
  ],
90
- create(context, [options = {}]) {
90
+ create(context, [options]) {
91
91
  const { allowInTests = true } = options;
92
92
  const filename = context.filename;
93
93
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -111,12 +111,10 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
111
111
  }
112
112
  // Get the options/config argument
113
113
  const configArg = node.arguments[0];
114
- /* c8 ignore next 2 */
115
114
  if (!configArg || configArg.type !== 'ObjectExpression') {
116
115
  return;
117
116
  }
118
117
  // Check if there's a production guard
119
- /* c8 ignore next 2 */
120
118
  if (hasProductionGuard(configArg, sourceCode)) {
121
119
  return;
122
120
  }
@@ -137,13 +135,11 @@ exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
137
135
  // Also check NewExpression for new ApolloServer({...})
138
136
  NewExpression(node) {
139
137
  const callee = node.callee;
140
- /* c8 ignore next 2 */
141
138
  if (callee.type !== 'Identifier' ||
142
139
  !['ApolloServer', 'GraphQLServer'].includes(callee.name)) {
143
140
  return;
144
141
  }
145
142
  const configArg = node.arguments[0];
146
- /* c8 ignore next 2 */
147
143
  if (!configArg || configArg.type !== 'ObjectExpression') {
148
144
  return;
149
145
  }
@@ -11,7 +11,7 @@
11
11
  * @see https://cwe.mitre.org/data/definitions/614.html
12
12
  * @see https://owasp.org/www-community/controls/SecureCookieAttribute
13
13
  */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
14
+ import type { TSESLint, TSESTree } from '@interlace/eslint-devkit';
15
15
  type MessageIds = 'insecureCookie' | 'addSecureFlags';
16
16
  export interface Options {
17
17
  /** Allow insecure cookies in test files. Default: false */
@@ -26,6 +26,13 @@ export interface Options {
26
26
  acceptableSameSiteValues?: string[];
27
27
  }
28
28
  type RuleOptions = [Options?];
29
+ /**
30
+ * Check cookie options object for security flags
31
+ */
32
+ export declare function checkCookieOptions(node: TSESTree.ObjectExpression, sourceCode: TSESLint.SourceCode, options: Options): {
33
+ issues: string[];
34
+ hasSuggestions: boolean;
35
+ };
29
36
  export declare const noInsecureCookieOptions: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
30
37
  name: string;
31
38
  };
@@ -6,6 +6,7 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noInsecureCookieOptions = void 0;
9
+ exports.checkCookieOptions = checkCookieOptions;
9
10
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
11
  /**
11
12
  * Check cookie options object for security flags
@@ -106,7 +107,7 @@ exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
106
107
  acceptableSameSiteValues: ['strict', 'lax'],
107
108
  },
108
109
  ],
109
- create(context, [options = {}]) {
110
+ create(context, [options]) {
110
111
  const { allowInTests = false } = options;
111
112
  const filename = context.filename;
112
113
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -95,7 +95,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
95
95
  ignorePatterns: [],
96
96
  },
97
97
  ],
98
- create(context, [options = {}]) {
98
+ create(context, [options]) {
99
99
  const { allowInTests = false, trustedLibraries: corsTrustedLibraries = [], ignorePatterns = [], } = options;
100
100
  const trustedLibraries = corsTrustedLibraries;
101
101
  const filename = context.filename;
@@ -300,8 +300,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
300
300
  if (current.type === 'Program' || current.type === 'FunctionDeclaration' || current.type === 'FunctionExpression' || current.type === 'ArrowFunctionExpression') {
301
301
  // Search for variable declarations in this scope
302
302
  const scopeBody = current.type === 'Program' ? current.body :
303
- (current.type === 'FunctionDeclaration' || current.type === 'FunctionExpression' || current.type === 'ArrowFunctionExpression') ?
304
- (current.body.type === 'BlockStatement' ? current.body.body : []) : [];
303
+ (current.body.type === 'BlockStatement' ? current.body.body : []);
305
304
  for (const stmt of scopeBody) {
306
305
  if (stmt.type === 'VariableDeclaration') {
307
306
  for (const declarator of stmt.declarations) {
@@ -111,7 +111,7 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
111
111
  ignorePatterns: [],
112
112
  },
113
113
  ],
114
- create(context, [options = {}]) {
114
+ create(context, [options]) {
115
115
  const { allowInTests = false, csrfMiddlewarePatterns, protectedMethods: customProtectedMethods, ignorePatterns = [], } = options;
116
116
  const csrfPatterns = csrfMiddlewarePatterns && csrfMiddlewarePatterns.length > 0
117
117
  ? csrfMiddlewarePatterns
@@ -167,12 +167,10 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
167
167
  {
168
168
  messageId: 'addCsrfValidation',
169
169
  fix(fixer) {
170
- // Add CSRF middleware after the first argument (path)
171
- const firstArg = node.arguments[0];
172
- if (firstArg) {
173
- return fixer.insertTextAfter(firstArg, ', csrf()');
174
- }
175
- return null;
170
+ // Add CSRF middleware after the first argument (path).
171
+ // arguments[0] always exists: the arguments.length < 2
172
+ // guard above returns before reporting.
173
+ return fixer.insertTextAfter(node.arguments[0], ', csrf()');
176
174
  },
177
175
  },
178
176
  ],
@@ -70,9 +70,8 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
70
70
  collectHeaders(astNode.expression);
71
71
  }
72
72
  }
73
- if (scopeNode) {
74
- collectHeaders(scopeNode);
75
- }
73
+ // scopeNode is always set at this point (function scope or program fallback)
74
+ collectHeaders(scopeNode);
76
75
  // Return missing headers
77
76
  return requiredHeaders.filter(header => !setHeaders.has(header));
78
77
  }
@@ -148,8 +147,8 @@ exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
148
147
  ignoreInTests: true,
149
148
  },
150
149
  ],
151
- create(context, [options = {}]) {
152
- const { requiredHeaders = DEFAULT_REQUIRED_HEADERS, ignoreInTests = true, } = options || {};
150
+ create(context, [options]) {
151
+ const { requiredHeaders = DEFAULT_REQUIRED_HEADERS, ignoreInTests = true, } = options;
153
152
  const filename = context.filename;
154
153
  const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
155
154
  if (isTestFile) {
@@ -30,7 +30,6 @@ function isPermissiveCorsConfig(node, sourceCode, options) {
30
30
  if (/\bcredentials\s*:\s*true\b/.test(text)) {
31
31
  // If credentials are enabled, origin cannot be '*' (browser blocks this)
32
32
  // but origin: true with credentials is dangerous
33
- /* c8 ignore next 7 */
34
33
  if (/\borigin\s*:\s*true\b/.test(text)) {
35
34
  return {
36
35
  isPermissive: true,
@@ -141,7 +140,7 @@ exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
141
140
  allowedOrigins: [],
142
141
  },
143
142
  ],
144
- create(context, [options = {}]) {
143
+ create(context, [options]) {
145
144
  const { allowInTests = false, allowOriginTrue = false, } = options;
146
145
  const filename = context.filename;
147
146
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -170,7 +169,8 @@ exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
170
169
  if (isStandaloneCorsCall(node)) {
171
170
  corsCallNode = node;
172
171
  }
173
- else if (isAppUseCors(node)) {
172
+ else {
173
+ // Guaranteed app.use(cors(...)) by the isAppUseCors guard above
174
174
  corsCallNode = node.arguments[0];
175
175
  }
176
176
  if (corsCallNode && corsCallNode.arguments.length === 0) {
@@ -52,9 +52,10 @@ exports.noUserControlledRedirect = (0, eslint_devkit_1.createRule)({
52
52
  ],
53
53
  },
54
54
  defaultOptions: [{}],
55
- create(context, [options = {}]) {
56
- const extraResNames = new Set(options.responseObjects ?? []);
57
- const extraReqNames = new Set(options.requestObjects ?? []);
55
+ create(context, [options]) {
56
+ const { responseObjects, requestObjects } = options;
57
+ const extraResNames = new Set(responseObjects ?? []);
58
+ const extraReqNames = new Set(requestObjects ?? []);
58
59
  /**
59
60
  * Returns true if `node` is a member expression whose root object is a
60
61
  * known response object name and whose property is a redirect method.
@@ -61,7 +61,6 @@ function isLikelyExpressObject(callee) {
61
61
  }
62
62
  // Skip unknown identifiers to avoid FPs
63
63
  // Names like 'server', 'customApi', 'controller' are not Express
64
- /* c8 ignore next */
65
64
  return false;
66
65
  }
67
66
  // Call expression: express().post(), express.Router().post()
@@ -82,10 +81,8 @@ function isLikelyExpressObject(callee) {
82
81
  }
83
82
  // Member expression: this.app, this.router - skip to avoid FPs
84
83
  if (obj.type === 'MemberExpression') {
85
- /* c8 ignore next */
86
84
  return false;
87
85
  }
88
- /* c8 ignore next */
89
86
  return false;
90
87
  }
91
88
  exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
@@ -151,7 +148,7 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
151
148
  ignorePatterns: [],
152
149
  },
153
150
  ],
154
- create(context, [options = {}]) {
151
+ create(context, [options]) {
155
152
  const { allowInTests = false, protectedMethods = DEFAULT_PROTECTED_METHODS, ignorePatterns = [], } = options;
156
153
  const filename = context.filename;
157
154
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -173,7 +170,6 @@ exports.requireCsrfProtection = (0, eslint_devkit_1.createRule)({
173
170
  return new RegExp(pattern).test(route);
174
171
  }
175
172
  catch {
176
- /* c8 ignore next */
177
173
  return route.includes(pattern);
178
174
  }
179
175
  });
@@ -116,7 +116,7 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
116
116
  excessiveLimits: DEFAULT_EXCESSIVE_LIMITS,
117
117
  },
118
118
  ],
119
- create(context, [options = {}]) {
119
+ create(context, [options]) {
120
120
  const { allowInTests = false, excessiveLimits = DEFAULT_EXCESSIVE_LIMITS, } = options;
121
121
  const filename = context.filename;
122
122
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -134,14 +134,12 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
134
134
  const object = callee.object;
135
135
  const property = callee.property;
136
136
  // Check if it's express.* or bodyParser.*
137
- /* c8 ignore next 2 */
138
137
  if (object.type !== 'Identifier') {
139
138
  return;
140
139
  }
141
140
  if (object.name !== 'express' && object.name !== 'bodyParser') {
142
141
  return;
143
142
  }
144
- /* c8 ignore next 2 */
145
143
  if (property.type !== 'Identifier') {
146
144
  return;
147
145
  }
@@ -186,7 +184,6 @@ exports.requireExpressBodyParserLimits = (0, eslint_devkit_1.createRule)({
186
184
  if (lastProp) {
187
185
  return fixer.insertTextAfter(lastProp, ", limit: '100kb'");
188
186
  }
189
- /* c8 ignore next */
190
187
  return null;
191
188
  },
192
189
  },
@@ -36,7 +36,6 @@ function isHelmetMiddleware(node) {
36
36
  }
37
37
  }
38
38
  // app.use(helmet) without call (unlikely but possible)
39
- /* c8 ignore next 3 */
40
39
  if (arg.type === 'Identifier' && arg.name === 'helmet') {
41
40
  return true;
42
41
  }
@@ -53,7 +52,6 @@ function isAlternativeMiddleware(node, alternatives) {
53
52
  return true;
54
53
  }
55
54
  }
56
- /* c8 ignore next 3 */
57
55
  if (arg.type === 'Identifier' && alternatives.includes(arg.name)) {
58
56
  return true;
59
57
  }
@@ -123,7 +121,7 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
123
121
  assumeHelmetMiddleware: false,
124
122
  },
125
123
  ],
126
- create(context, [options = {}]) {
124
+ create(context, [options]) {
127
125
  const { allowInTests = false, alternativeMiddleware = [], assumeHelmetMiddleware = false } = options;
128
126
  // Skip entirely if helmet/security headers are assumed to be provided elsewhere
129
127
  if (assumeHelmetMiddleware) {
@@ -149,7 +147,6 @@ exports.requireHelmet = (0, eslint_devkit_1.createRule)({
149
147
  return;
150
148
  }
151
149
  // Check for require('express')() pattern
152
- /* c8 ignore next 15 */
153
150
  if (callee.type === 'CallExpression' &&
154
151
  callee.callee.type === 'Identifier' &&
155
152
  callee.callee.name === 'require') {
@@ -24,8 +24,8 @@ function isRateLimitMiddleware(node, alternatives) {
24
24
  for (const arg of node.arguments) {
25
25
  // rateLimit() or limiter()
26
26
  if (arg.type === 'CallExpression' && arg.callee.type === 'Identifier') {
27
- if (allPatterns.some((p) => arg.callee.type === 'Identifier' &&
28
- arg.callee.name.toLowerCase().includes(p.toLowerCase()))) {
27
+ const calleeName = arg.callee.name.toLowerCase();
28
+ if (allPatterns.some((p) => calleeName.includes(p.toLowerCase()))) {
29
29
  return true;
30
30
  }
31
31
  }
@@ -98,7 +98,7 @@ exports.requireRateLimiting = (0, eslint_devkit_1.createRule)({
98
98
  assumeRateLimiting: false,
99
99
  },
100
100
  ],
101
- create(context, [options = {}]) {
101
+ create(context, [options]) {
102
102
  const { allowInTests = false, alternativeMiddleware = [], assumeRateLimiting = false } = options;
103
103
  // Skip entirely if rate limiting is assumed (provided by infrastructure)
104
104
  if (assumeRateLimiting) {