eslint-plugin-express-security 1.5.4 → 1.5.5

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 (33) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -113
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/no-client-controlled-authorization/index.js +1 -194
  5. package/src/rules/no-cors-credentials-wildcard/index.js +1 -127
  6. package/src/rules/no-disabled-helmet-protections/index.js +1 -125
  7. package/src/rules/no-error-details-in-response/index.js +1 -176
  8. package/src/rules/no-exposed-debug-endpoints/index.js +1 -96
  9. package/src/rules/no-express-unsafe-regex-route/index.js +1 -154
  10. package/src/rules/no-graphql-introspection-production/index.js +1 -143
  11. package/src/rules/no-host-header-in-links/index.js +1 -235
  12. package/src/rules/no-idor-resource-access/index.js +1 -126
  13. package/src/rules/no-insecure-cookie-options/index.js +1 -158
  14. package/src/rules/no-missing-cors-check/index.js +1 -351
  15. package/src/rules/no-missing-csrf-protection/index.js +1 -161
  16. package/src/rules/no-missing-security-headers/index.js +1 -206
  17. package/src/rules/no-permissive-cors/index.js +1 -185
  18. package/src/rules/no-permissive-trust-proxy/index.js +1 -106
  19. package/src/rules/no-sensitive-data-in-query/index.js +1 -182
  20. package/src/rules/no-static-root-exposure/index.js +1 -267
  21. package/src/rules/no-unsafe-csp-directives/index.js +1 -264
  22. package/src/rules/no-user-controlled-redirect/index.js +1 -117
  23. package/src/rules/no-user-controlled-render-locals/index.js +1 -268
  24. package/src/rules/require-case-insensitive-path-guard/index.js +1 -180
  25. package/src/rules/require-csrf-protection/index.js +1 -201
  26. package/src/rules/require-express-body-parser-limits/index.js +1 -181
  27. package/src/rules/require-helmet/index.js +1 -166
  28. package/src/rules/require-query-type-guard/index.js +1 -258
  29. package/src/rules/require-rate-limiting/index.js +1 -136
  30. package/src/rules/require-route-authentication/index.js +1 -225
  31. package/src/rules/require-strict-transport-security/index.js +1 -171
  32. package/src/types/index.js +1 -2
  33. package/src/utils/index.js +1 -81
@@ -1,235 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noHostHeaderInLinks = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const HOST_HEADER_NAMES = new Set(['host', 'x-forwarded-host']);
6
- const HOST_GETTER_METHODS = new Set(['get', 'header']);
7
- exports.noHostHeaderInLinks = (0, eslint_devkit_1.createRule)({
8
- name: 'no-host-header-in-links',
9
- meta: {
10
- type: 'problem',
11
- hasSuggestions: true,
12
- docs: {
13
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-host-header-in-links.md',
14
- description: 'Disallow building absolute URLs (reset/verification links) from the Host or X-Forwarded-Host request header',
15
- cwe: 'CWE-640',
16
- cvss: 8.1,
17
- },
18
- messages: {
19
- hostHeaderInLink: (0, eslint_devkit_1.formatLLMMessage)({
20
- icon: eslint_devkit_1.MessageIcons.SECURITY,
21
- issueName: 'Host-Header Poisoning (CWE-640)',
22
- cwe: 'CWE-640',
23
- description: 'A URL is built from {{source}}, which the client controls. Reset/verification links built this way can be redirected to an attacker-owned host, leaking the token.',
24
- severity: 'HIGH',
25
- fix: 'Build absolute links from a server-side constant (e.g. process.env.PUBLIC_ORIGIN), never from request headers.',
26
- documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
27
- }),
28
- useConfiguredOrigin: (0, eslint_devkit_1.formatLLMMessage)({
29
- icon: eslint_devkit_1.MessageIcons.INFO,
30
- issueName: 'Use a configured origin',
31
- description: 'Replace the header-derived host with a deployment constant such as process.env.PUBLIC_ORIGIN',
32
- severity: 'LOW',
33
- fix: "const origin = process.env.PUBLIC_ORIGIN; // 'https://app.example.com'",
34
- documentationLink: 'https://cwe.mitre.org/data/definitions/640.html',
35
- }),
36
- },
37
- schema: [
38
- {
39
- type: 'object',
40
- properties: {
41
- allowedHosts: {
42
- type: 'array',
43
- items: { type: 'string' },
44
- description: 'Trusted literal hosts — an if-guard comparing against one of these suppresses the report',
45
- },
46
- checkMailCallees: {
47
- type: 'array',
48
- items: { type: 'string' },
49
- description: 'Callee names treated as mail-send sinks (default: ["sendMail", "send"])',
50
- },
51
- },
52
- additionalProperties: false,
53
- },
54
- ],
55
- },
56
- defaultOptions: [{}],
57
- create(context, [options]) {
58
- const { allowedHosts, checkMailCallees } = options;
59
- const allowed = allowedHosts ?? [];
60
- const mailCallees = new Set(checkMailCallees ?? ['sendMail', 'send']);
61
- const sourceCode = context.sourceCode;
62
- const hostVars = new Map();
63
- function isRequestIdent(name) {
64
- const lower = name.toLowerCase();
65
- return lower === 'req' || lower === 'request' || lower === 'ctx';
66
- }
67
- function propName(node) {
68
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && !node.computed) {
69
- return node.property.name;
70
- }
71
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
72
- typeof node.property.value === 'string') {
73
- return node.property.value;
74
- }
75
- return null;
76
- }
77
- function getHostHeaderSource(node) {
78
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.LogicalExpression) {
79
- return (getHostHeaderSource(node.left) ?? getHostHeaderSource(node.right));
80
- }
81
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
82
- const callee = node.callee;
83
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
84
- callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
85
- HOST_GETTER_METHODS.has(callee.property.name) &&
86
- callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
87
- isRequestIdent(callee.object.name)) {
88
- const arg = node.arguments[0];
89
- if (arg !== undefined &&
90
- arg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
91
- typeof arg.value === 'string' &&
92
- HOST_HEADER_NAMES.has(arg.value.toLowerCase())) {
93
- return `req.${callee.property.name}('${arg.value}')`;
94
- }
95
- }
96
- return null;
97
- }
98
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
99
- const obj = node.object;
100
- if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
101
- obj.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
102
- obj.property.name === 'headers' &&
103
- obj.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
104
- isRequestIdent(obj.object.name)) {
105
- const name = propName(node);
106
- if (name !== null && HOST_HEADER_NAMES.has(name.toLowerCase())) {
107
- return `req.headers['${name}']`;
108
- }
109
- }
110
- }
111
- return null;
112
- }
113
- function resolveHostSource(node) {
114
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
115
- let scope = sourceCode.getScope(node);
116
- while (scope) {
117
- const variable = scope.variables.find((v) => v.name === node.name);
118
- if (variable)
119
- return hostVars.get(variable) ?? null;
120
- scope = scope.upper;
121
- }
122
- return null;
123
- }
124
- return getHostHeaderSource(node);
125
- }
126
- function isUrlish(text) {
127
- return text.includes('://') || text.startsWith('//');
128
- }
129
- function isInMailCall(node) {
130
- let current = node.parent;
131
- while (current != null) {
132
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
133
- const callee = current.callee;
134
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
135
- mailCallees.has(callee.name)) {
136
- return true;
137
- }
138
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
139
- callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
140
- mailCallees.has(callee.property.name)) {
141
- return true;
142
- }
143
- }
144
- current = current.parent;
145
- }
146
- return false;
147
- }
148
- function isValidatedByAllowlist(node) {
149
- if (allowed.length === 0)
150
- return false;
151
- let current = node.parent;
152
- while (current != null) {
153
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement) {
154
- const testText = sourceCode.getText(current.test);
155
- if (allowed.some((host) => testText.includes(host)))
156
- return true;
157
- }
158
- current = current.parent;
159
- }
160
- return false;
161
- }
162
- function reportHostUse(node, source) {
163
- if (isValidatedByAllowlist(node))
164
- return;
165
- context.report({
166
- node,
167
- messageId: 'hostHeaderInLink',
168
- data: { source },
169
- suggest: [{ messageId: 'useConfiguredOrigin', fix: () => null }],
170
- });
171
- }
172
- return {
173
- VariableDeclarator(node) {
174
- if (node.id.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || node.init == null) {
175
- return;
176
- }
177
- const source = getHostHeaderSource(node.init);
178
- if (source === null)
179
- return;
180
- for (const variable of sourceCode.getDeclaredVariables(node)) {
181
- hostVars.set(variable, source);
182
- }
183
- },
184
- TemplateLiteral(node) {
185
- const urlish = node.quasis.some((q) => isUrlish(q.value.raw));
186
- for (const expr of node.expressions) {
187
- const source = resolveHostSource(expr);
188
- if (source !== null && (urlish || isInMailCall(node))) {
189
- reportHostUse(expr, source);
190
- }
191
- }
192
- },
193
- BinaryExpression(node) {
194
- if (node.operator !== '+')
195
- return;
196
- if (node.parent.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression &&
197
- node.parent.operator === '+') {
198
- return;
199
- }
200
- const operands = [];
201
- const stack = [node];
202
- while (stack.length > 0) {
203
- const current = stack.pop();
204
- if (current.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression &&
205
- current.operator === '+') {
206
- stack.push(current.left, current.right);
207
- }
208
- else {
209
- operands.push(current);
210
- }
211
- }
212
- let urlish = false;
213
- let hostNode = null;
214
- let hostSource = null;
215
- for (const operand of operands) {
216
- if (operand.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
217
- typeof operand.value === 'string' &&
218
- isUrlish(operand.value)) {
219
- urlish = true;
220
- }
221
- if (hostSource === null) {
222
- const source = resolveHostSource(operand);
223
- if (source !== null) {
224
- hostSource = source;
225
- hostNode = operand;
226
- }
227
- }
228
- }
229
- if (hostNode !== null && (urlish || isInMailCall(node))) {
230
- reportHostUse(hostNode, hostSource);
231
- }
232
- },
233
- };
234
- },
235
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHostHeaderInLinks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const HOST_HEADER_NAMES=new Set(["host","x-forwarded-host"]);const HOST_GETTER_METHODS=new Set(["get","header"]);exports.noHostHeaderInLinks=(0,eslint_devkit_1.createRule)({name:"no-host-header-in-links",meta:{type:"problem",hasSuggestions:true,docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-host-header-in-links.md",description:"Disallow building absolute URLs (reset/verification links) from the Host or X-Forwarded-Host request header",cwe:"CWE-640",cvss:8.1},messages:{hostHeaderInLink:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Host-Header Poisoning (CWE-640)",cwe:"CWE-640",description:"A URL is built from {{source}}, which the client controls. Reset/verification links built this way can be redirected to an attacker-owned host, leaking the token.",severity:"HIGH",fix:"Build absolute links from a server-side constant (e.g. process.env.PUBLIC_ORIGIN), never from request headers.",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"}),useConfiguredOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use a configured origin",description:"Replace the header-derived host with a deployment constant such as process.env.PUBLIC_ORIGIN",severity:"LOW",fix:"const origin = process.env.PUBLIC_ORIGIN; // 'https://app.example.com'",documentationLink:"https://cwe.mitre.org/data/definitions/640.html"})},schema:[{type:"object",properties:{allowedHosts:{type:"array",items:{type:"string"},description:"Trusted literal hosts \u2014 an if-guard comparing against one of these suppresses the report"},checkMailCallees:{type:"array",items:{type:"string"},description:'Callee names treated as mail-send sinks (default: ["sendMail", "send"])'}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{allowedHosts,checkMailCallees}=options;const allowed=allowedHosts??[];const mailCallees=new Set(checkMailCallees??["sendMail","send"]);const sourceCode=context.sourceCode;const hostVars=new Map;function isRequestIdent(name){const lower=name.toLowerCase();return lower==="req"||lower==="request"||lower==="ctx"}function propName(node){if(node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&!node.computed){return node.property.name}if(node.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.property.value==="string"){return node.property.value}return null}function getHostHeaderSource(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.LogicalExpression){return getHostHeaderSource(node.left)??getHostHeaderSource(node.right)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const callee=node.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&HOST_GETTER_METHODS.has(callee.property.name)&&callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isRequestIdent(callee.object.name)){const arg=node.arguments[0];if(arg!==void 0&&arg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof arg.value==="string"&&HOST_HEADER_NAMES.has(arg.value.toLowerCase())){return`req.${callee.property.name}('${arg.value}')`}}return null}if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){const obj=node.object;if(obj.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&obj.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&obj.property.name==="headers"&&obj.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isRequestIdent(obj.object.name)){const name=propName(node);if(name!==null&&HOST_HEADER_NAMES.has(name.toLowerCase())){return`req.headers['${name}']`}}}return null}function resolveHostSource(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){let scope=sourceCode.getScope(node);while(scope){const variable=scope.variables.find(v=>v.name===node.name);if(variable)return hostVars.get(variable)??null;scope=scope.upper}return null}return getHostHeaderSource(node)}function isUrlish(text){return text.includes("://")||text.startsWith("//")}function isInMailCall(node){let current=node.parent;while(current!=null){if(current.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const callee=current.callee;if(callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&mailCallees.has(callee.name)){return true}if(callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&mailCallees.has(callee.property.name)){return true}}current=current.parent}return false}function isValidatedByAllowlist(node){if(allowed.length===0)return false;let current=node.parent;while(current!=null){if(current.type===eslint_devkit_1.AST_NODE_TYPES.IfStatement){const testText=sourceCode.getText(current.test);if(allowed.some(host=>testText.includes(host)))return true}current=current.parent}return false}function reportHostUse(node,source){if(isValidatedByAllowlist(node))return;context.report({node,messageId:"hostHeaderInLink",data:{source},suggest:[{messageId:"useConfiguredOrigin",fix:()=>null}]})}return{VariableDeclarator(node){if(node.id.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||node.init==null){return}const source=getHostHeaderSource(node.init);if(source===null)return;for(const variable of sourceCode.getDeclaredVariables(node)){hostVars.set(variable,source)}},TemplateLiteral(node){const urlish=node.quasis.some(q=>isUrlish(q.value.raw));for(const expr of node.expressions){const source=resolveHostSource(expr);if(source!==null&&(urlish||isInMailCall(node))){reportHostUse(expr,source)}}},BinaryExpression(node){if(node.operator!=="+")return;if(node.parent.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&node.parent.operator==="+"){return}const operands=[];const stack=[node];while(stack.length>0){const current=stack.pop();if(current.type===eslint_devkit_1.AST_NODE_TYPES.BinaryExpression&&current.operator==="+"){stack.push(current.left,current.right)}else{operands.push(current)}}let urlish=false;let hostNode=null;let hostSource=null;for(const operand of operands){if(operand.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof operand.value==="string"&&isUrlish(operand.value)){urlish=true}if(hostSource===null){const source=resolveHostSource(operand);if(source!==null){hostSource=source;hostNode=operand}}}if(hostNode!==null&&(urlish||isInMailCall(node))){reportHostUse(hostNode,hostSource)}}}}});
@@ -1,126 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noIdorResourceAccess = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const utils_1 = require("../../utils");
6
- const DEFAULT_LOOKUP_METHODS = [
7
- 'findById',
8
- 'findByPk',
9
- 'findOne',
10
- 'findUnique',
11
- 'findFirst',
12
- 'findByIdAndUpdate',
13
- 'findByIdAndDelete',
14
- 'findByIdAndRemove',
15
- 'getById',
16
- 'deleteOne',
17
- 'deleteById',
18
- 'updateOne',
19
- 'replaceOne',
20
- ];
21
- const REQUEST_PARAM = /^(req|request)$/i;
22
- function isHandlerFunction(node) {
23
- if (node.type !== eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration &&
24
- node.type !== eslint_devkit_1.AST_NODE_TYPES.FunctionExpression &&
25
- node.type !== eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression) {
26
- return false;
27
- }
28
- return node.params.some((param) => param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && REQUEST_PARAM.test(param.name));
29
- }
30
- function isRequestKeyArgument(arg) {
31
- if ((0, utils_1.isClientRequestMember)(arg))
32
- return true;
33
- if (arg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
34
- let found = false;
35
- (0, utils_1.walk)(arg, (child) => {
36
- if (found)
37
- return;
38
- if ((0, utils_1.isClientRequestMember)(child))
39
- found = true;
40
- });
41
- return found;
42
- }
43
- return false;
44
- }
45
- exports.noIdorResourceAccess = (0, eslint_devkit_1.createRule)({
46
- name: 'no-idor-resource-access',
47
- meta: {
48
- type: 'problem',
49
- docs: {
50
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-idor-resource-access.md',
51
- description: 'Disallow fetching a resource by a request-supplied key in a handler with no principal in scope',
52
- cwe: 'CWE-639',
53
- cvss: 7.5,
54
- confidence: 'medium',
55
- },
56
- messages: {
57
- unscopedResourceLookup: (0, eslint_devkit_1.formatLLMMessage)({
58
- icon: eslint_devkit_1.MessageIcons.SECURITY,
59
- issueName: 'Resource Fetched By Client-Supplied Key (CWE-639)',
60
- cwe: 'CWE-639',
61
- cvss: 7.5,
62
- description: '{{method}}() is keyed on {{key}} and nothing in this handler ties the lookup to the caller. Incrementing the id in the URL returns another tenant’s record.',
63
- severity: 'HIGH',
64
- fix: "Scope the query to the principal — {{method}}({ _id: {{key}}, owner: req.user.id }) — or verify ownership on the loaded document before responding.",
65
- documentationLink: 'https://cwe.mitre.org/data/definitions/639.html',
66
- }),
67
- },
68
- schema: [
69
- {
70
- type: 'object',
71
- properties: {
72
- lookupMethods: {
73
- type: 'array',
74
- items: { type: 'string' },
75
- description: 'Lookup methods treated as a fetch-by-key',
76
- },
77
- },
78
- additionalProperties: false,
79
- },
80
- ],
81
- },
82
- defaultOptions: [{}],
83
- create(context, [options]) {
84
- const { lookupMethods } = options;
85
- const lookups = new Set(lookupMethods ?? DEFAULT_LOOKUP_METHODS);
86
- function enclosingHandler(node) {
87
- let current = node.parent;
88
- while (current) {
89
- if (isHandlerFunction(current))
90
- return current;
91
- current = current.parent;
92
- }
93
- return null;
94
- }
95
- return {
96
- CallExpression(node) {
97
- const callee = node.callee;
98
- if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
99
- return;
100
- if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
101
- return;
102
- if (callee.computed)
103
- return;
104
- const method = callee.property.name;
105
- if (!lookups.has(method))
106
- return;
107
- const keyArg = node.arguments.find((arg) => isRequestKeyArgument(arg));
108
- if (!keyArg)
109
- return;
110
- const handler = enclosingHandler(node);
111
- if (!handler)
112
- return;
113
- if ((0, utils_1.readsPrincipal)(handler))
114
- return;
115
- context.report({
116
- node,
117
- messageId: 'unscopedResourceLookup',
118
- data: {
119
- method,
120
- key: context.sourceCode.getText(keyArg),
121
- },
122
- });
123
- },
124
- };
125
- },
126
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noIdorResourceAccess=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const utils_1=require("../../utils");const DEFAULT_LOOKUP_METHODS=["findById","findByPk","findOne","findUnique","findFirst","findByIdAndUpdate","findByIdAndDelete","findByIdAndRemove","getById","deleteOne","deleteById","updateOne","replaceOne"];const REQUEST_PARAM=/^(req|request)$/i;function isHandlerFunction(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration&&node.type!==eslint_devkit_1.AST_NODE_TYPES.FunctionExpression&&node.type!==eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression){return false}return node.params.some(param=>param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&REQUEST_PARAM.test(param.name))}function isRequestKeyArgument(arg){if((0,utils_1.isClientRequestMember)(arg))return true;if(arg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){let found=false;(0,utils_1.walk)(arg,child=>{if(found)return;if((0,utils_1.isClientRequestMember)(child))found=true});return found}return false}exports.noIdorResourceAccess=(0,eslint_devkit_1.createRule)({name:"no-idor-resource-access",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-idor-resource-access.md",description:"Disallow fetching a resource by a request-supplied key in a handler with no principal in scope",cwe:"CWE-639",cvss:7.5,confidence:"medium"},messages:{unscopedResourceLookup:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Resource Fetched By Client-Supplied Key (CWE-639)",cwe:"CWE-639",cvss:7.5,description:"{{method}}() is keyed on {{key}} and nothing in this handler ties the lookup to the caller. Incrementing the id in the URL returns another tenant\u2019s record.",severity:"HIGH",fix:"Scope the query to the principal \u2014 {{method}}({ _id: {{key}}, owner: req.user.id }) \u2014 or verify ownership on the loaded document before responding.",documentationLink:"https://cwe.mitre.org/data/definitions/639.html"})},schema:[{type:"object",properties:{lookupMethods:{type:"array",items:{type:"string"},description:"Lookup methods treated as a fetch-by-key"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{lookupMethods}=options;const lookups=new Set(lookupMethods??DEFAULT_LOOKUP_METHODS);function enclosingHandler(node){let current=node.parent;while(current){if(isHandlerFunction(current))return current;current=current.parent}return null}return{CallExpression(node){const callee=node.callee;if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return;if(callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return;if(callee.computed)return;const method=callee.property.name;if(!lookups.has(method))return;const keyArg=node.arguments.find(arg=>isRequestKeyArgument(arg));if(!keyArg)return;const handler=enclosingHandler(node);if(!handler)return;if((0,utils_1.readsPrincipal)(handler))return;context.report({node,messageId:"unscopedResourceLookup",data:{method,key:context.sourceCode.getText(keyArg)}})}}}});
@@ -1,158 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noInsecureCookieOptions = void 0;
4
- exports.checkCookieOptions = checkCookieOptions;
5
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
6
- function checkCookieOptions(node, sourceCode, options) {
7
- const text = sourceCode.getText(node);
8
- const issues = [];
9
- if (options.requireHttpOnly !== false) {
10
- const hasHttpOnly = /\bhttpOnly\s*:\s*true\b/i.test(text);
11
- if (!hasHttpOnly) {
12
- issues.push('missing httpOnly flag (prevents XSS access to cookie)');
13
- }
14
- }
15
- if (options.requireSecure !== false) {
16
- const hasSecure = /\bsecure\s*:\s*true\b/i.test(text);
17
- if (!hasSecure) {
18
- issues.push('missing secure flag (cookie sent over HTTPS only)');
19
- }
20
- }
21
- if (options.requireSameSite !== false) {
22
- const acceptableValues = options.acceptableSameSiteValues || ['strict', 'lax'];
23
- const sameSiteMatch = text.match(/\bsameSite\s*:\s*['"](\w+)['"]/i);
24
- if (!sameSiteMatch) {
25
- issues.push('missing sameSite flag (prevents CSRF)');
26
- }
27
- else if (!acceptableValues.includes(sameSiteMatch[1].toLowerCase())) {
28
- issues.push(`sameSite should be 'strict' or 'lax', not '${sameSiteMatch[1]}'`);
29
- }
30
- }
31
- return { issues, hasSuggestions: issues.length > 0 };
32
- }
33
- exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
34
- name: 'no-insecure-cookie-options',
35
- meta: {
36
- type: 'problem',
37
- docs: {
38
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-insecure-cookie-options.md',
39
- description: 'Require secure cookie flags (httpOnly, secure, sameSite) in Express.js',
40
- cwe: 'CWE-614',
41
- cvss: 5.3,
42
- },
43
- hasSuggestions: true,
44
- messages: {
45
- insecureCookie: (0, eslint_devkit_1.formatLLMMessage)({
46
- icon: eslint_devkit_1.MessageIcons.SECURITY,
47
- issueName: 'Insecure Cookie Configuration',
48
- cwe: 'CWE-614',
49
- description: '{{issues}}',
50
- severity: 'HIGH',
51
- fix: 'Set httpOnly: true, secure: true, sameSite: "strict"',
52
- documentationLink: 'https://owasp.org/www-community/controls/SecureCookieAttribute',
53
- }),
54
- addSecureFlags: (0, eslint_devkit_1.formatLLMMessage)({
55
- icon: eslint_devkit_1.MessageIcons.INFO,
56
- issueName: 'Add Secure Cookie Flags',
57
- description: 'Add missing security flags to cookie options',
58
- severity: 'LOW',
59
- fix: '{ httpOnly: true, secure: true, sameSite: "strict" }',
60
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
61
- }),
62
- },
63
- schema: [
64
- {
65
- type: 'object',
66
- properties: {
67
- allowInTests: {
68
- type: 'boolean',
69
- default: false,
70
- },
71
- requireHttpOnly: {
72
- type: 'boolean',
73
- default: true,
74
- },
75
- requireSecure: {
76
- type: 'boolean',
77
- default: true,
78
- },
79
- requireSameSite: {
80
- type: 'boolean',
81
- default: true,
82
- },
83
- acceptableSameSiteValues: {
84
- type: 'array',
85
- items: { type: 'string' },
86
- default: ['strict', 'lax'],
87
- },
88
- },
89
- additionalProperties: false,
90
- },
91
- ],
92
- },
93
- defaultOptions: [
94
- {
95
- allowInTests: false,
96
- requireHttpOnly: true,
97
- requireSecure: true,
98
- requireSameSite: true,
99
- acceptableSameSiteValues: ['strict', 'lax'],
100
- },
101
- ],
102
- create(context, [options]) {
103
- const { allowInTests = false } = options;
104
- const filename = context.filename;
105
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
106
- if (isTestFile) {
107
- return {};
108
- }
109
- const sourceCode = context.sourceCode;
110
- return {
111
- CallExpression(node) {
112
- const callee = node.callee;
113
- if (callee.type === 'MemberExpression' &&
114
- callee.property.type === 'Identifier' &&
115
- callee.property.name === 'cookie') {
116
- const optionsArg = node.arguments[2];
117
- if (!optionsArg) {
118
- context.report({
119
- node,
120
- messageId: 'insecureCookie',
121
- data: {
122
- issues: 'Cookie set without options - missing httpOnly, secure, sameSite flags',
123
- },
124
- suggest: [
125
- {
126
- messageId: 'addSecureFlags',
127
- fix: (fixer) => {
128
- const lastArg = node.arguments[node.arguments.length - 1];
129
- return fixer.insertTextAfter(lastArg, ', { httpOnly: true, secure: true, sameSite: "strict" }');
130
- },
131
- },
132
- ],
133
- });
134
- return;
135
- }
136
- if (optionsArg.type === 'ObjectExpression') {
137
- const { issues } = checkCookieOptions(optionsArg, sourceCode, options);
138
- if (issues.length > 0) {
139
- context.report({
140
- node: optionsArg,
141
- messageId: 'insecureCookie',
142
- data: {
143
- issues: issues.join('; '),
144
- },
145
- suggest: [
146
- {
147
- messageId: 'addSecureFlags',
148
- fix: () => null,
149
- },
150
- ],
151
- });
152
- }
153
- }
154
- }
155
- },
156
- };
157
- },
158
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInsecureCookieOptions=void 0;exports.checkCookieOptions=checkCookieOptions;const eslint_devkit_1=require("@interlace/eslint-devkit");function checkCookieOptions(node,sourceCode,options){const text=sourceCode.getText(node);const issues=[];if(options.requireHttpOnly!==false){const hasHttpOnly=/\bhttpOnly\s*:\s*true\b/i.test(text);if(!hasHttpOnly){issues.push("missing httpOnly flag (prevents XSS access to cookie)")}}if(options.requireSecure!==false){const hasSecure=/\bsecure\s*:\s*true\b/i.test(text);if(!hasSecure){issues.push("missing secure flag (cookie sent over HTTPS only)")}}if(options.requireSameSite!==false){const acceptableValues=options.acceptableSameSiteValues||["strict","lax"];const sameSiteMatch=text.match(/\bsameSite\s*:\s*['"](\w+)['"]/i);if(!sameSiteMatch){issues.push("missing sameSite flag (prevents CSRF)")}else if(!acceptableValues.includes(sameSiteMatch[1].toLowerCase())){issues.push(`sameSite should be 'strict' or 'lax', not '${sameSiteMatch[1]}'`)}}return{issues,hasSuggestions:issues.length>0}}exports.noInsecureCookieOptions=(0,eslint_devkit_1.createRule)({name:"no-insecure-cookie-options",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-insecure-cookie-options.md",description:"Require secure cookie flags (httpOnly, secure, sameSite) in Express.js",cwe:"CWE-614",cvss:5.3},hasSuggestions:true,messages:{insecureCookie:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure Cookie Configuration",cwe:"CWE-614",description:"{{issues}}",severity:"HIGH",fix:'Set httpOnly: true, secure: true, sameSite: "strict"',documentationLink:"https://owasp.org/www-community/controls/SecureCookieAttribute"}),addSecureFlags:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Secure Cookie Flags",description:"Add missing security flags to cookie options",severity:"LOW",fix:'{ httpOnly: true, secure: true, sameSite: "strict" }',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false},requireHttpOnly:{type:"boolean",default:true},requireSecure:{type:"boolean",default:true},requireSameSite:{type:"boolean",default:true},acceptableSameSiteValues:{type:"array",items:{type:"string"},default:["strict","lax"]}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,requireHttpOnly:true,requireSecure:true,requireSameSite:true,acceptableSameSiteValues:["strict","lax"]}],create(context,[options]){const{allowInTests=false}=options;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const sourceCode=context.sourceCode;return{CallExpression(node){const callee=node.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="cookie"){const optionsArg=node.arguments[2];if(!optionsArg){context.report({node,messageId:"insecureCookie",data:{issues:"Cookie set without options - missing httpOnly, secure, sameSite flags"},suggest:[{messageId:"addSecureFlags",fix:fixer=>{const lastArg=node.arguments[node.arguments.length-1];return fixer.insertTextAfter(lastArg,', { httpOnly: true, secure: true, sameSite: "strict" }')}}]});return}if(optionsArg.type==="ObjectExpression"){const{issues}=checkCookieOptions(optionsArg,sourceCode,options);if(issues.length>0){context.report({node:optionsArg,messageId:"insecureCookie",data:{issues:issues.join("; ")},suggest:[{messageId:"addSecureFlags",fix:()=>null}]})}}}}}}});