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,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noClientControlledAuthorization = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const CLIENT_CONTAINERS = new Set([
6
+ 'body',
7
+ 'query',
8
+ 'params',
9
+ 'headers',
10
+ 'cookies',
11
+ ]);
12
+ const REQUEST_RECEIVER = /^(req|request)$/i;
13
+ const AUTHZ_PROPERTIES = new Set([
14
+ 'role',
15
+ 'roles',
16
+ 'admin',
17
+ 'isadmin',
18
+ 'is_admin',
19
+ 'superuser',
20
+ 'issuperuser',
21
+ 'permission',
22
+ 'permissions',
23
+ 'scope',
24
+ 'scopes',
25
+ 'privilege',
26
+ 'privileges',
27
+ 'usertype',
28
+ 'user_type',
29
+ 'accesslevel',
30
+ 'access_level',
31
+ 'acl',
32
+ 'claims',
33
+ 'grants',
34
+ 'userid',
35
+ 'user_id',
36
+ 'ownerid',
37
+ 'owner_id',
38
+ 'owner',
39
+ 'accountid',
40
+ 'account_id',
41
+ 'tenantid',
42
+ 'tenant_id',
43
+ 'orgid',
44
+ 'org_id',
45
+ ]);
46
+ const AUTHZ_HEADER = /^x-.*(role|admin|user|auth|permission|scope|tenant|account|owner)/i;
47
+ function staticPropertyName(node) {
48
+ if (!node.computed && node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
49
+ return node.property.name;
50
+ }
51
+ if (node.computed &&
52
+ node.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
53
+ typeof node.property.value === 'string') {
54
+ return node.property.value;
55
+ }
56
+ return null;
57
+ }
58
+ function clientContainerOf(node) {
59
+ const { object } = node;
60
+ if (object.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
61
+ return null;
62
+ const container = staticPropertyName(object);
63
+ if (!container || !CLIENT_CONTAINERS.has(container))
64
+ return null;
65
+ const root = object.object;
66
+ if (root.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && REQUEST_RECEIVER.test(root.name)) {
67
+ return container;
68
+ }
69
+ if (root.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
70
+ root.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
71
+ REQUEST_RECEIVER.test(root.property.name)) {
72
+ return container;
73
+ }
74
+ return null;
75
+ }
76
+ function isAuthorizationDecision(node) {
77
+ let current = node;
78
+ let parent = node.parent;
79
+ for (let depth = 0; parent && depth < 4; depth += 1) {
80
+ switch (parent.type) {
81
+ case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:
82
+ if (parent.operator === '===' ||
83
+ parent.operator === '==' ||
84
+ parent.operator === '!==' ||
85
+ parent.operator === '!=') {
86
+ return true;
87
+ }
88
+ break;
89
+ case eslint_devkit_1.AST_NODE_TYPES.IfStatement:
90
+ case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:
91
+ if (parent.test === current)
92
+ return true;
93
+ break;
94
+ case eslint_devkit_1.AST_NODE_TYPES.SwitchStatement:
95
+ if (parent.discriminant === current)
96
+ return true;
97
+ break;
98
+ case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:
99
+ if (parent.operator === '??')
100
+ break;
101
+ return true;
102
+ case eslint_devkit_1.AST_NODE_TYPES.UnaryExpression:
103
+ if (parent.operator === '!')
104
+ return true;
105
+ break;
106
+ case eslint_devkit_1.AST_NODE_TYPES.CallExpression:
107
+ if (parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
108
+ parent.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
109
+ (parent.callee.property.name === 'includes' ||
110
+ parent.callee.property.name === 'some')) {
111
+ return true;
112
+ }
113
+ return false;
114
+ default:
115
+ break;
116
+ }
117
+ current = parent;
118
+ parent = parent.parent;
119
+ }
120
+ return false;
121
+ }
122
+ exports.noClientControlledAuthorization = (0, eslint_devkit_1.createRule)({
123
+ name: 'no-client-controlled-authorization',
124
+ meta: {
125
+ type: 'problem',
126
+ docs: {
127
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-client-controlled-authorization.md',
128
+ description: 'Disallow authorization decisions taken on request-supplied role, permission or identity values',
129
+ cwe: 'CWE-863',
130
+ cvss: 8.1,
131
+ confidence: 'medium',
132
+ },
133
+ messages: {
134
+ clientControlledAuthorization: (0, eslint_devkit_1.formatLLMMessage)({
135
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
136
+ issueName: 'Authorization Decided On Client Input (CWE-863)',
137
+ cwe: 'CWE-863',
138
+ cvss: 8.1,
139
+ description: 'The access decision reads {{expression}} — a value the caller sends. The check runs, and passes for anyone who sets the field.',
140
+ severity: 'HIGH',
141
+ fix: 'Read the attribute from the server-side session or verified token instead: req.user.{{property}} / req.auth.{{property}}.',
142
+ documentationLink: 'https://cwe.mitre.org/data/definitions/863.html',
143
+ }),
144
+ },
145
+ schema: [
146
+ {
147
+ type: 'object',
148
+ properties: {
149
+ extraProperties: {
150
+ type: 'array',
151
+ items: { type: 'string' },
152
+ description: 'Extra property names treated as authorization attributes',
153
+ },
154
+ },
155
+ additionalProperties: false,
156
+ },
157
+ ],
158
+ },
159
+ defaultOptions: [{}],
160
+ create(context, [options]) {
161
+ const { extraProperties } = options;
162
+ const extra = new Set((extraProperties ?? []).map((name) => name.toLowerCase()));
163
+ function isAuthorizationAttribute(property, container) {
164
+ const normalized = property.toLowerCase();
165
+ if (AUTHZ_PROPERTIES.has(normalized))
166
+ return true;
167
+ if (extra.has(normalized))
168
+ return true;
169
+ return container === 'headers' && AUTHZ_HEADER.test(property);
170
+ }
171
+ return {
172
+ MemberExpression(node) {
173
+ const property = staticPropertyName(node);
174
+ if (!property)
175
+ return;
176
+ const container = clientContainerOf(node);
177
+ if (!container)
178
+ return;
179
+ if (!isAuthorizationAttribute(property, container))
180
+ return;
181
+ if (!isAuthorizationDecision(node))
182
+ return;
183
+ context.report({
184
+ node,
185
+ messageId: 'clientControlledAuthorization',
186
+ data: {
187
+ expression: context.sourceCode.getText(node),
188
+ property,
189
+ },
190
+ });
191
+ },
192
+ };
193
+ },
194
+ });
@@ -1,50 +1,30 @@
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.noCorsCredentialsWildcard = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- /**
11
- * Checks if a configuration object has origin set to '*' or true
12
- */
13
5
  function hasWildcardOrigin(node, sourceCode) {
14
6
  const text = sourceCode.getText(node);
15
- // Check for origin: '*'
16
7
  if (/\borigin\s*:\s*['"`]\*['"`]/.test(text)) {
17
8
  return true;
18
9
  }
19
- // Check for origin: true (reflects request origin - effectively wildcard)
20
10
  if (/\borigin\s*:\s*true\b/.test(text)) {
21
11
  return true;
22
12
  }
23
13
  return false;
24
14
  }
25
- /**
26
- * Checks if a configuration object has credentials: true
27
- */
28
15
  function hasCredentialsTrue(node, sourceCode) {
29
16
  const text = sourceCode.getText(node);
30
17
  return /\bcredentials\s*:\s*true\b/.test(text);
31
18
  }
32
- /**
33
- * Check if this is a cors() call (standalone or in app.use)
34
- * Returns the config node only for the appropriate level to avoid double-triggering
35
- */
36
19
  function getCorsConfigNode(node) {
37
20
  const callee = node.callee;
38
- // Standalone cors({...}) call - but skip if parent is app.use()
39
21
  if (callee.type === 'Identifier' && callee.name === 'cors') {
40
- // Check if this cors() is inside app.use() - if so, let app.use() handle it
41
22
  const parent = node.parent;
42
23
  if (parent &&
43
24
  parent.type === 'CallExpression' &&
44
25
  parent.callee.type === 'MemberExpression' &&
45
26
  parent.callee.property.type === 'Identifier' &&
46
27
  parent.callee.property.name === 'use') {
47
- // Skip - let the app.use() case handle this
48
28
  return null;
49
29
  }
50
30
  if (node.arguments[0]?.type === 'ObjectExpression') {
@@ -52,7 +32,6 @@ function getCorsConfigNode(node) {
52
32
  }
53
33
  return null;
54
34
  }
55
- // app.use(cors({...}))
56
35
  if (callee.type === 'MemberExpression' &&
57
36
  callee.property.type === 'Identifier' &&
58
37
  callee.property.name === 'use') {
@@ -129,7 +108,6 @@ exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
129
108
  if (corsConfigNode) {
130
109
  const hasWildcard = hasWildcardOrigin(corsConfigNode, sourceCode);
131
110
  const hasCredentials = hasCredentialsTrue(corsConfigNode, sourceCode);
132
- // Only report if BOTH conditions are met
133
111
  if (hasWildcard && hasCredentials) {
134
112
  context.report({
135
113
  node: corsConfigNode,
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noDisabledHelmetProtections = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const PROTECTIONS = {
6
+ contentSecurityPolicy: 'Content-Security-Policy',
7
+ frameguard: 'X-Frame-Options',
8
+ xFrameOptions: 'X-Frame-Options',
9
+ noSniff: 'X-Content-Type-Options',
10
+ xContentTypeOptions: 'X-Content-Type-Options',
11
+ referrerPolicy: 'Referrer-Policy',
12
+ hidePoweredBy: 'X-Powered-By (removal)',
13
+ xPoweredBy: 'X-Powered-By (removal)',
14
+ crossOriginResourcePolicy: 'Cross-Origin-Resource-Policy',
15
+ crossOriginOpenerPolicy: 'Cross-Origin-Opener-Policy',
16
+ };
17
+ function isHelmetCall(node) {
18
+ return (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
19
+ node.callee.name === 'helmet');
20
+ }
21
+ function propertyKeyName(prop) {
22
+ if (prop.computed)
23
+ return null;
24
+ if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier)
25
+ return prop.key.name;
26
+ if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
27
+ typeof prop.key.value === 'string') {
28
+ return prop.key.value;
29
+ }
30
+ return null;
31
+ }
32
+ exports.noDisabledHelmetProtections = (0, eslint_devkit_1.createRule)({
33
+ name: 'no-disabled-helmet-protections',
34
+ meta: {
35
+ type: 'problem',
36
+ hasSuggestions: true,
37
+ docs: {
38
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-disabled-helmet-protections.md',
39
+ description: 'Disallow disabling helmet security-header defaults: contentSecurityPolicy, frameguard/xFrameOptions, noSniff/xContentTypeOptions, referrerPolicy, hidePoweredBy/xPoweredBy, crossOriginResourcePolicy, crossOriginOpenerPolicy',
40
+ cwe: 'CWE-693',
41
+ cvss: 6.5,
42
+ confidence: 'high',
43
+ },
44
+ messages: {
45
+ disabledProtection: (0, eslint_devkit_1.formatLLMMessage)({
46
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
47
+ issueName: 'Helmet Protection Disabled (CWE-693)',
48
+ cwe: 'CWE-693',
49
+ cvss: 6.5,
50
+ description: 'helmet({ {{option}}: false }) stops the {{header}} header from being sent. The middleware is mounted but this protection is off, so the app ships the same exposure as an app with no helmet at all.',
51
+ severity: 'HIGH',
52
+ fix: 'Remove the `{{option}}: false` entry and keep the helmet default. If the header must be customised, pass its options object instead of `false`.',
53
+ documentationLink: 'https://helmetjs.github.io/',
54
+ }),
55
+ restoreDefault: 'Remove `{{option}}: false` and keep the helmet default',
56
+ },
57
+ schema: [
58
+ {
59
+ type: 'object',
60
+ properties: {
61
+ allowDisabled: {
62
+ type: 'array',
63
+ items: { type: 'string' },
64
+ description: 'Helmet option names that may be disabled without a report',
65
+ },
66
+ },
67
+ additionalProperties: false,
68
+ },
69
+ ],
70
+ },
71
+ defaultOptions: [{}],
72
+ create(context, [options]) {
73
+ const { allowDisabled } = options;
74
+ const allowed = new Set(allowDisabled ?? []);
75
+ function removeProperty(fixer, prop) {
76
+ const sourceCode = context.sourceCode;
77
+ const after = sourceCode.getTokenAfter(prop);
78
+ if (after && after.value === ',') {
79
+ return fixer.removeRange([prop.range[0], after.range[1]]);
80
+ }
81
+ const before = sourceCode.getTokenBefore(prop);
82
+ if (before && before.value === ',') {
83
+ return fixer.removeRange([before.range[0], prop.range[1]]);
84
+ }
85
+ return fixer.remove(prop);
86
+ }
87
+ return {
88
+ CallExpression(node) {
89
+ if (!isHelmetCall(node))
90
+ return;
91
+ const config = node.arguments[0];
92
+ if (!config || config.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
93
+ return;
94
+ for (const prop of config.properties) {
95
+ if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
96
+ continue;
97
+ const name = propertyKeyName(prop);
98
+ if (!name)
99
+ continue;
100
+ const header = PROTECTIONS[name];
101
+ if (!header)
102
+ continue;
103
+ if (allowed.has(name))
104
+ continue;
105
+ if (prop.value.type !== eslint_devkit_1.AST_NODE_TYPES.Literal ||
106
+ prop.value.value !== false) {
107
+ continue;
108
+ }
109
+ context.report({
110
+ node: prop,
111
+ messageId: 'disabledProtection',
112
+ data: { option: name, header },
113
+ suggest: [
114
+ {
115
+ messageId: 'restoreDefault',
116
+ data: { option: name },
117
+ fix: (fixer) => removeProperty(fixer, prop),
118
+ },
119
+ ],
120
+ });
121
+ }
122
+ },
123
+ };
124
+ },
125
+ });
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noErrorDetailsInResponse = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ const SEND_METHODS = new Set(['send', 'json', 'end']);
6
+ const ERROR_PARAM_NAME = /^(err|error)$/i;
7
+ exports.noErrorDetailsInResponse = (0, eslint_devkit_1.createRule)({
8
+ name: 'no-error-details-in-response',
9
+ meta: {
10
+ type: 'problem',
11
+ hasSuggestions: false,
12
+ docs: {
13
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-error-details-in-response.md',
14
+ description: 'Disallow sending caught error objects, stacks, or spreads of them in HTTP responses',
15
+ cwe: 'CWE-209',
16
+ cvss: 5.3,
17
+ },
18
+ messages: {
19
+ errorDetailsExposed: (0, eslint_devkit_1.formatLLMMessage)({
20
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
21
+ issueName: 'Error Details Exposed (CWE-209)',
22
+ cwe: 'CWE-209',
23
+ description: 'The HTTP response includes {{detail}}. Stack traces and driver errors leak file paths, dependency versions, query text and hostnames to the caller.',
24
+ severity: 'MEDIUM',
25
+ fix: "Log the error server-side and respond with a generic body: logger.error(err); res.status(500).json({ error: 'Internal Server Error' })",
26
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html',
27
+ }),
28
+ },
29
+ schema: [
30
+ {
31
+ type: 'object',
32
+ properties: {
33
+ allowMessage: {
34
+ type: 'boolean',
35
+ default: true,
36
+ description: 'Allow err.message in responses',
37
+ },
38
+ allowInDev: {
39
+ type: 'boolean',
40
+ default: false,
41
+ description: 'Allow error details inside an if-guard checking NODE_ENV',
42
+ },
43
+ },
44
+ additionalProperties: false,
45
+ },
46
+ ],
47
+ },
48
+ defaultOptions: [{}],
49
+ create(context, [options]) {
50
+ const { allowMessage, allowInDev } = options;
51
+ const messageAllowed = allowMessage ?? true;
52
+ const devAllowed = allowInDev ?? false;
53
+ const sourceCode = context.sourceCode;
54
+ const frames = [];
55
+ function isErrorName(name) {
56
+ return frames.some((frame) => frame.name === name);
57
+ }
58
+ function enterFunction(node) {
59
+ const first = node.params[0];
60
+ if (first !== undefined &&
61
+ first.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
62
+ ERROR_PARAM_NAME.test(first.name)) {
63
+ frames.push({ node, name: first.name });
64
+ }
65
+ }
66
+ function exitFrame(node) {
67
+ if (frames.length > 0 && frames[frames.length - 1].node === node) {
68
+ frames.pop();
69
+ }
70
+ }
71
+ function isResponseSend(node) {
72
+ const callee = node.callee;
73
+ if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
74
+ return false;
75
+ if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
76
+ return false;
77
+ if (!SEND_METHODS.has(callee.property.name))
78
+ return false;
79
+ let obj = callee.object;
80
+ while (obj.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
81
+ obj.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
82
+ obj = obj.callee.object;
83
+ }
84
+ if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
85
+ return false;
86
+ const lower = obj.name.toLowerCase();
87
+ return lower === 'res' || lower === 'response' || lower === 'reply';
88
+ }
89
+ function detailOf(node) {
90
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && isErrorName(node.name)) {
91
+ return `the raw error \`${node.name}\``;
92
+ }
93
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
94
+ !node.computed &&
95
+ node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
96
+ isErrorName(node.object.name) &&
97
+ node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
98
+ if (node.property.name === 'stack') {
99
+ return `\`${node.object.name}.stack\``;
100
+ }
101
+ if (node.property.name === 'message' && !messageAllowed) {
102
+ return `\`${node.object.name}.message\``;
103
+ }
104
+ }
105
+ return null;
106
+ }
107
+ function collectFindings(arg) {
108
+ const direct = detailOf(arg);
109
+ if (direct !== null)
110
+ return [{ node: arg, detail: direct }];
111
+ if (arg.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
112
+ return [];
113
+ const findings = [];
114
+ for (const prop of arg.properties) {
115
+ if (prop.type === eslint_devkit_1.AST_NODE_TYPES.SpreadElement) {
116
+ if (prop.argument.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
117
+ isErrorName(prop.argument.name)) {
118
+ findings.push({
119
+ node: prop,
120
+ detail: `\`{ ...${prop.argument.name} }\` (spread of the raw error)`,
121
+ });
122
+ }
123
+ continue;
124
+ }
125
+ const detail = detailOf(prop.value);
126
+ if (detail !== null)
127
+ findings.push({ node: prop.value, detail });
128
+ }
129
+ return findings;
130
+ }
131
+ function isInDevGuard(node) {
132
+ let current = node.parent;
133
+ while (current != null) {
134
+ if (current.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement &&
135
+ sourceCode.getText(current.test).includes('NODE_ENV')) {
136
+ return true;
137
+ }
138
+ current = current.parent;
139
+ }
140
+ return false;
141
+ }
142
+ return {
143
+ CatchClause(node) {
144
+ if (node.param !== null &&
145
+ node.param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
146
+ frames.push({ node, name: node.param.name });
147
+ }
148
+ },
149
+ 'CatchClause:exit': exitFrame,
150
+ FunctionDeclaration: enterFunction,
151
+ 'FunctionDeclaration:exit': exitFrame,
152
+ FunctionExpression: enterFunction,
153
+ 'FunctionExpression:exit': exitFrame,
154
+ ArrowFunctionExpression: enterFunction,
155
+ 'ArrowFunctionExpression:exit': exitFrame,
156
+ CallExpression(node) {
157
+ if (frames.length === 0)
158
+ return;
159
+ if (!isResponseSend(node))
160
+ return;
161
+ const arg = node.arguments[0];
162
+ if (arg === undefined)
163
+ return;
164
+ if (devAllowed && isInDevGuard(node))
165
+ return;
166
+ for (const finding of collectFindings(arg)) {
167
+ context.report({
168
+ node: finding.node,
169
+ messageId: 'errorDetailsExposed',
170
+ data: { detail: finding.detail },
171
+ });
172
+ }
173
+ },
174
+ };
175
+ },
176
+ });
@@ -1,16 +1,20 @@
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.noExposedDebugEndpoints = void 0;
9
- /**
10
- * @fileoverview Detect debug endpoints without auth in Express applications
11
- */
12
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
5
  const DEFAULT_DEBUG_PATHS = ['/debug', '/__debug__', '/admin', '/_admin', '/test', '/health'];
6
+ const HTTP_METHODS = new Set([
7
+ 'get',
8
+ 'post',
9
+ 'put',
10
+ 'patch',
11
+ 'delete',
12
+ 'head',
13
+ 'options',
14
+ 'all',
15
+ 'use',
16
+ 'route',
17
+ ]);
14
18
  exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
15
19
  name: 'no-exposed-debug-endpoints',
16
20
  meta: {
@@ -57,42 +61,33 @@ exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
57
61
  const debugPaths = options.endpoints || DEFAULT_DEBUG_PATHS;
58
62
  const ignoreFiles = options.ignoreFiles || [];
59
63
  const filename = context.filename;
60
- // Check if current file should be ignored
61
64
  if (ignoreFiles.some(pattern => filename.includes(pattern))) {
62
65
  return {};
63
66
  }
64
- function report(node) {
65
- context.report({ node, messageId: 'violationDetected' });
66
- }
67
- // oxlint-disable-next-line consistent-function-scoping
68
67
  const isExpressRouteCall = (node) => {
69
68
  return (node.callee.type === 'MemberExpression' &&
70
69
  node.callee.object.type === 'Identifier' &&
71
70
  ['app', 'router', 'express'].includes(node.callee.object.name) &&
72
71
  node.callee.property.type === 'Identifier' &&
73
- ['get', 'post', 'use'].includes(node.callee.property.name));
72
+ HTTP_METHODS.has(node.callee.property.name));
74
73
  };
75
74
  return {
76
75
  CallExpression(node) {
77
- if (isExpressRouteCall(node)) {
78
- const pathArg = node.arguments[0];
79
- if (pathArg && pathArg.type === 'Literal' && typeof pathArg.value === 'string') {
80
- const path = pathArg.value.toLowerCase();
81
- if (debugPaths.some(dp => path.includes(dp.toLowerCase()))) {
82
- report(pathArg);
83
- }
84
- }
76
+ if (!isExpressRouteCall(node)) {
77
+ return;
85
78
  }
86
- },
87
- Literal(node) {
88
- if (typeof node.value === 'string') {
89
- const path = node.value.toLowerCase();
90
- if (debugPaths.some(dp => path === dp.toLowerCase())) {
91
- const parent = node.parent;
92
- if (parent && parent.type === 'CallExpression' && isExpressRouteCall(parent) && parent.arguments[0] === node) {
93
- return;
94
- }
95
- report(node);
79
+ const isSettingLookup = node.callee.type === 'MemberExpression' &&
80
+ node.callee.property.type === 'Identifier' &&
81
+ node.callee.property.name === 'get' &&
82
+ node.arguments.length === 1;
83
+ if (isSettingLookup) {
84
+ return;
85
+ }
86
+ const pathArg = node.arguments[0];
87
+ if (pathArg && pathArg.type === 'Literal' && typeof pathArg.value === 'string') {
88
+ const path = pathArg.value.toLowerCase();
89
+ if (debugPaths.some(dp => path.includes(dp.toLowerCase()))) {
90
+ context.report({ node: pathArg, messageId: 'violationDetected' });
96
91
  }
97
92
  }
98
93
  },