eslint-plugin-express-security 1.5.4 → 1.5.6

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 (34) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/index.js +1 -113
  4. package/src/oxlint.js +1 -3
  5. package/src/rules/no-client-controlled-authorization/index.js +1 -194
  6. package/src/rules/no-cors-credentials-wildcard/index.js +1 -127
  7. package/src/rules/no-disabled-helmet-protections/index.js +1 -125
  8. package/src/rules/no-error-details-in-response/index.js +1 -176
  9. package/src/rules/no-exposed-debug-endpoints/index.js +1 -96
  10. package/src/rules/no-express-unsafe-regex-route/index.js +1 -154
  11. package/src/rules/no-graphql-introspection-production/index.js +1 -143
  12. package/src/rules/no-host-header-in-links/index.js +1 -235
  13. package/src/rules/no-idor-resource-access/index.js +1 -126
  14. package/src/rules/no-insecure-cookie-options/index.js +1 -158
  15. package/src/rules/no-missing-cors-check/index.js +1 -351
  16. package/src/rules/no-missing-csrf-protection/index.js +1 -161
  17. package/src/rules/no-missing-security-headers/index.js +1 -206
  18. package/src/rules/no-permissive-cors/index.js +1 -185
  19. package/src/rules/no-permissive-trust-proxy/index.js +1 -106
  20. package/src/rules/no-sensitive-data-in-query/index.js +1 -182
  21. package/src/rules/no-static-root-exposure/index.js +1 -267
  22. package/src/rules/no-unsafe-csp-directives/index.js +1 -264
  23. package/src/rules/no-user-controlled-redirect/index.js +1 -117
  24. package/src/rules/no-user-controlled-render-locals/index.js +1 -268
  25. package/src/rules/require-case-insensitive-path-guard/index.js +1 -180
  26. package/src/rules/require-csrf-protection/index.js +1 -201
  27. package/src/rules/require-express-body-parser-limits/index.js +1 -181
  28. package/src/rules/require-helmet/index.js +1 -166
  29. package/src/rules/require-query-type-guard/index.js +1 -258
  30. package/src/rules/require-rate-limiting/index.js +1 -136
  31. package/src/rules/require-route-authentication/index.js +1 -225
  32. package/src/rules/require-strict-transport-security/index.js +1 -171
  33. package/src/types/index.js +1 -2
  34. package/src/utils/index.js +1 -81
@@ -1,206 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noMissingSecurityHeaders = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const DEFAULT_REQUIRED_HEADERS = [
7
- 'Content-Security-Policy',
8
- 'X-Frame-Options',
9
- 'X-Content-Type-Options',
10
- ];
11
- const HEADER_METHODS = new Set(['setHeader', 'header', 'set']);
12
- const RESPONSE_RECEIVER = /^(res|resp|response|reply)$/i;
13
- function isResponseHeaderCall(node) {
14
- const { callee } = node;
15
- if (callee.type !== 'MemberExpression' ||
16
- callee.property.type !== 'Identifier' ||
17
- !HEADER_METHODS.has(callee.property.name)) {
18
- return false;
19
- }
20
- const { object } = callee;
21
- if (object.type === 'Identifier') {
22
- return RESPONSE_RECEIVER.test(object.name);
23
- }
24
- if (object.type === 'MemberExpression' && object.property.type === 'Identifier') {
25
- return RESPONSE_RECEIVER.test(object.property.name);
26
- }
27
- return false;
28
- }
29
- function extractHeaderName(node) {
30
- if (node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
31
- return String(node.arguments[0].value);
32
- }
33
- return null;
34
- }
35
- function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
36
- const setHeaders = new Set();
37
- let current = node;
38
- let scopeNode = null;
39
- while (current) {
40
- if (current.type === 'FunctionDeclaration' ||
41
- current.type === 'FunctionExpression' ||
42
- current.type === 'ArrowFunctionExpression') {
43
- scopeNode = current;
44
- break;
45
- }
46
- current = current.parent ?? null;
47
- }
48
- if (!scopeNode) {
49
- scopeNode = context.sourceCode.ast;
50
- }
51
- function collectHeaders(astNode) {
52
- if (astNode.type === 'CallExpression' && isResponseHeaderCall(astNode)) {
53
- const headerName = extractHeaderName(astNode);
54
- if (headerName) {
55
- setHeaders.add(headerName);
56
- }
57
- }
58
- if (astNode.type === 'Program' && astNode.body) {
59
- astNode.body.forEach(collectHeaders);
60
- }
61
- else if ((astNode.type === 'FunctionDeclaration' ||
62
- astNode.type === 'FunctionExpression' ||
63
- astNode.type === 'ArrowFunctionExpression') && astNode.body) {
64
- collectHeaders(astNode.body);
65
- }
66
- else if (astNode.type === 'BlockStatement' && astNode.body) {
67
- astNode.body.forEach(collectHeaders);
68
- }
69
- else if (astNode.type === 'ExpressionStatement' && astNode.expression) {
70
- collectHeaders(astNode.expression);
71
- }
72
- }
73
- collectHeaders(scopeNode);
74
- return requiredHeaders.filter(header => !setHeaders.has(header));
75
- }
76
- exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
77
- name: 'no-missing-security-headers',
78
- meta: {
79
- type: 'problem',
80
- deprecated: true,
81
- replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
82
- docs: {
83
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-security-headers.md',
84
- description: 'Detects missing security headers in HTTP responses',
85
- cwe: 'CWE-693',
86
- cvss: 7.5,
87
- },
88
- hasSuggestions: true,
89
- messages: {
90
- missingSecurityHeader: (0, eslint_devkit_1.formatLLMMessage)({
91
- icon: eslint_devkit_1.MessageIcons.SECURITY,
92
- issueName: 'Missing security headers',
93
- cwe: 'CWE-693',
94
- description: 'Missing security headers: {{headers}}',
95
- severity: 'HIGH',
96
- fix: 'Set security headers: Content-Security-Policy, X-Frame-Options, X-Content-Type-Options',
97
- documentationLink: 'https://owasp.org/www-project-secure-headers/',
98
- }),
99
- addSecurityHeaders: (0, eslint_devkit_1.formatLLMMessage)({
100
- icon: eslint_devkit_1.MessageIcons.INFO,
101
- issueName: 'Add Security Headers',
102
- description: 'Add security headers middleware',
103
- severity: 'LOW',
104
- fix: 'Add Content-Security-Policy, X-Frame-Options headers',
105
- documentationLink: 'https://owasp.org/www-project-secure-headers/',
106
- }),
107
- useMiddleware: (0, eslint_devkit_1.formatLLMMessage)({
108
- icon: eslint_devkit_1.MessageIcons.INFO,
109
- issueName: 'Use Helmet',
110
- description: 'Use helmet.js for security headers',
111
- severity: 'LOW',
112
- fix: 'app.use(helmet())',
113
- documentationLink: 'https://helmetjs.github.io/',
114
- }),
115
- setHeader: (0, eslint_devkit_1.formatLLMMessage)({
116
- icon: eslint_devkit_1.MessageIcons.INFO,
117
- issueName: 'Set Headers',
118
- description: 'Set security headers manually',
119
- severity: 'LOW',
120
- fix: 'res.setHeader("X-Frame-Options", "DENY")',
121
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers',
122
- }),
123
- },
124
- schema: [
125
- {
126
- type: 'object',
127
- properties: {
128
- requiredHeaders: {
129
- type: 'array',
130
- items: { type: 'string' },
131
- default: DEFAULT_REQUIRED_HEADERS,
132
- },
133
- ignoreInTests: {
134
- type: 'boolean',
135
- default: true,
136
- },
137
- },
138
- additionalProperties: false,
139
- },
140
- ],
141
- },
142
- defaultOptions: [
143
- {
144
- requiredHeaders: DEFAULT_REQUIRED_HEADERS,
145
- ignoreInTests: true,
146
- },
147
- ],
148
- create(context, [options]) {
149
- const { requiredHeaders = DEFAULT_REQUIRED_HEADERS, ignoreInTests = true, } = options;
150
- const filename = context.filename;
151
- const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
152
- if (isTestFile) {
153
- return {};
154
- }
155
- const reportedScopes = new Set();
156
- function getScopeKey(node) {
157
- let current = node;
158
- while (current) {
159
- if (current.type === 'FunctionDeclaration' ||
160
- current.type === 'FunctionExpression' ||
161
- current.type === 'ArrowFunctionExpression') {
162
- return `${current.range?.[0]}-${current.range?.[1]}`;
163
- }
164
- current = current.parent ?? null;
165
- }
166
- return 'program';
167
- }
168
- function checkCallExpression(node) {
169
- if (!isResponseHeaderCall(node)) {
170
- return;
171
- }
172
- const scopeKey = getScopeKey(node);
173
- if (reportedScopes.has(scopeKey)) {
174
- return;
175
- }
176
- const missing = checkFunctionForSecurityHeaders(node, requiredHeaders, context);
177
- reportedScopes.add(scopeKey);
178
- if (missing.length > 0) {
179
- context.report({
180
- node,
181
- messageId: 'missingSecurityHeader',
182
- data: {
183
- headers: missing.join(', '),
184
- },
185
- suggest: [
186
- {
187
- messageId: 'addSecurityHeaders',
188
- fix: () => null,
189
- },
190
- {
191
- messageId: 'useMiddleware',
192
- fix: () => null,
193
- },
194
- {
195
- messageId: 'setHeader',
196
- fix: () => null,
197
- },
198
- ],
199
- });
200
- }
201
- }
202
- return {
203
- CallExpression: checkCallExpression,
204
- };
205
- },
206
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingSecurityHeaders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DEFAULT_REQUIRED_HEADERS=["Content-Security-Policy","X-Frame-Options","X-Content-Type-Options"];const HEADER_METHODS=new Set(["setHeader","header","set"]);const RESPONSE_RECEIVER=/^(res|resp|response|reply)$/i;function isResponseHeaderCall(node){const{callee}=node;if(callee.type!=="MemberExpression"||callee.property.type!=="Identifier"||!HEADER_METHODS.has(callee.property.name)){return false}const{object}=callee;if(object.type==="Identifier"){return RESPONSE_RECEIVER.test(object.name)}if(object.type==="MemberExpression"&&object.property.type==="Identifier"){return RESPONSE_RECEIVER.test(object.property.name)}return false}function extractHeaderName(node){if(node.arguments.length>0&&node.arguments[0].type==="Literal"){return String(node.arguments[0].value)}return null}function checkFunctionForSecurityHeaders(node,requiredHeaders,context){const setHeaders=new Set;let current=node;let scopeNode=null;while(current){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){scopeNode=current;break}current=current.parent??null}if(!scopeNode){scopeNode=context.sourceCode.ast}function collectHeaders(astNode){if(astNode.type==="CallExpression"&&isResponseHeaderCall(astNode)){const headerName=extractHeaderName(astNode);if(headerName){setHeaders.add(headerName)}}if(astNode.type==="Program"&&astNode.body){astNode.body.forEach(collectHeaders)}else if((astNode.type==="FunctionDeclaration"||astNode.type==="FunctionExpression"||astNode.type==="ArrowFunctionExpression")&&astNode.body){collectHeaders(astNode.body)}else if(astNode.type==="BlockStatement"&&astNode.body){astNode.body.forEach(collectHeaders)}else if(astNode.type==="ExpressionStatement"&&astNode.expression){collectHeaders(astNode.expression)}}collectHeaders(scopeNode);return requiredHeaders.filter(header=>!setHeaders.has(header))}exports.noMissingSecurityHeaders=(0,eslint_devkit_2.createRule)({name:"no-missing-security-headers",meta:{type:"problem",deprecated:true,replacedBy:["@see eslint-plugin-express-security/require-helmet"],docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-security-headers.md",description:"Detects missing security headers in HTTP responses",cwe:"CWE-693",cvss:7.5},hasSuggestions:true,messages:{missingSecurityHeader:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing security headers",cwe:"CWE-693",description:"Missing security headers: {{headers}}",severity:"HIGH",fix:"Set security headers: Content-Security-Policy, X-Frame-Options, X-Content-Type-Options",documentationLink:"https://owasp.org/www-project-secure-headers/"}),addSecurityHeaders:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Security Headers",description:"Add security headers middleware",severity:"LOW",fix:"Add Content-Security-Policy, X-Frame-Options headers",documentationLink:"https://owasp.org/www-project-secure-headers/"}),useMiddleware:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Helmet",description:"Use helmet.js for security headers",severity:"LOW",fix:"app.use(helmet())",documentationLink:"https://helmetjs.github.io/"}),setHeader:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Set Headers",description:"Set security headers manually",severity:"LOW",fix:'res.setHeader("X-Frame-Options", "DENY")',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers"})},schema:[{type:"object",properties:{requiredHeaders:{type:"array",items:{type:"string"},default:DEFAULT_REQUIRED_HEADERS},ignoreInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{requiredHeaders:DEFAULT_REQUIRED_HEADERS,ignoreInTests:true}],create(context,[options]){const{requiredHeaders=DEFAULT_REQUIRED_HEADERS,ignoreInTests=true}=options;const filename=context.filename;const isTestFile=ignoreInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const reportedScopes=new Set;function getScopeKey(node){let current=node;while(current){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){return`${current.range?.[0]}-${current.range?.[1]}`}current=current.parent??null}return"program"}function checkCallExpression(node){if(!isResponseHeaderCall(node)){return}const scopeKey=getScopeKey(node);if(reportedScopes.has(scopeKey)){return}const missing=checkFunctionForSecurityHeaders(node,requiredHeaders,context);reportedScopes.add(scopeKey);if(missing.length>0){context.report({node,messageId:"missingSecurityHeader",data:{headers:missing.join(", ")},suggest:[{messageId:"addSecurityHeaders",fix:()=>null},{messageId:"useMiddleware",fix:()=>null},{messageId:"setHeader",fix:()=>null}]})}}return{CallExpression:checkCallExpression}}});
@@ -1,185 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noPermissiveCors = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- function isPermissiveCorsConfig(node, sourceCode, options) {
6
- const text = sourceCode.getText(node);
7
- if (/\borigin\s*:\s*['"`]\*['"`]/.test(text)) {
8
- return {
9
- isPermissive: true,
10
- reason: "origin: '*' allows any domain to access your API",
11
- };
12
- }
13
- if (!options.allowOriginTrue && /\borigin\s*:\s*true\b/.test(text)) {
14
- return {
15
- isPermissive: true,
16
- reason: 'origin: true reflects the request origin, allowing any domain',
17
- };
18
- }
19
- if (/\bcredentials\s*:\s*true\b/.test(text)) {
20
- if (/\borigin\s*:\s*true\b/.test(text)) {
21
- return {
22
- isPermissive: true,
23
- reason: 'origin: true with credentials: true allows credential leakage to any domain',
24
- };
25
- }
26
- }
27
- return { isPermissive: false, reason: '' };
28
- }
29
- function isStandaloneCorsCall(node) {
30
- const callee = node.callee;
31
- if (callee.type === 'Identifier' && callee.name === 'cors') {
32
- const parent = node.parent;
33
- if (parent &&
34
- parent.type === 'CallExpression' &&
35
- parent.callee.type === 'MemberExpression' &&
36
- parent.callee.property.type === 'Identifier' &&
37
- parent.callee.property.name === 'use') {
38
- return false;
39
- }
40
- return true;
41
- }
42
- return false;
43
- }
44
- function isAppUseCors(node) {
45
- const callee = node.callee;
46
- if (callee.type === 'MemberExpression' &&
47
- callee.property.type === 'Identifier' &&
48
- callee.property.name === 'use') {
49
- const firstArg = node.arguments[0];
50
- if (firstArg &&
51
- firstArg.type === 'CallExpression' &&
52
- firstArg.callee.type === 'Identifier' &&
53
- firstArg.callee.name === 'cors') {
54
- return true;
55
- }
56
- }
57
- return false;
58
- }
59
- exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
60
- name: 'no-permissive-cors',
61
- meta: {
62
- type: 'problem',
63
- docs: {
64
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-permissive-cors.md',
65
- description: 'Disallow overly permissive CORS configurations (wildcard origin, origin: true)',
66
- cwe: 'CWE-942',
67
- cvss: 7.5,
68
- },
69
- hasSuggestions: true,
70
- messages: {
71
- permissiveCors: (0, eslint_devkit_1.formatLLMMessage)({
72
- icon: eslint_devkit_1.MessageIcons.SECURITY,
73
- issueName: 'Permissive CORS Configuration',
74
- cwe: 'CWE-942',
75
- description: '{{reason}}',
76
- severity: 'HIGH',
77
- fix: 'Specify an explicit whitelist of allowed origins: origin: ["https://trusted-domain.com"]',
78
- documentationLink: 'https://owasp.org/www-community/attacks/CORS_OriginHeaderScrutiny',
79
- }),
80
- useWhitelist: (0, eslint_devkit_1.formatLLMMessage)({
81
- icon: eslint_devkit_1.MessageIcons.INFO,
82
- issueName: 'Use Origin Whitelist',
83
- description: 'Replace with explicit origin whitelist',
84
- severity: 'LOW',
85
- fix: 'origin: ["https://your-frontend.com", "https://app.your-domain.com"]',
86
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS',
87
- }),
88
- },
89
- schema: [
90
- {
91
- type: 'object',
92
- properties: {
93
- allowInTests: {
94
- type: 'boolean',
95
- default: false,
96
- description: 'Allow permissive CORS in test files',
97
- },
98
- allowOriginTrue: {
99
- type: 'boolean',
100
- default: false,
101
- description: 'Allow origin: true for development',
102
- },
103
- allowedOrigins: {
104
- type: 'array',
105
- items: { type: 'string' },
106
- default: [],
107
- description: 'Allowed origins that should not trigger warnings',
108
- },
109
- },
110
- additionalProperties: false,
111
- },
112
- ],
113
- },
114
- defaultOptions: [
115
- {
116
- allowInTests: false,
117
- allowOriginTrue: false,
118
- allowedOrigins: [],
119
- },
120
- ],
121
- create(context, [options]) {
122
- const { allowInTests = false, allowOriginTrue = false, } = options;
123
- const filename = context.filename;
124
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
125
- if (isTestFile) {
126
- return {};
127
- }
128
- const sourceCode = context.sourceCode;
129
- return {
130
- CallExpression(node) {
131
- if (isStandaloneCorsCall(node) || isAppUseCors(node)) {
132
- let corsConfigNode = null;
133
- if (isStandaloneCorsCall(node) && node.arguments[0]?.type === 'ObjectExpression') {
134
- corsConfigNode = node.arguments[0];
135
- }
136
- else if (isAppUseCors(node)) {
137
- const corsCall = node.arguments[0];
138
- if (corsCall.arguments[0]?.type === 'ObjectExpression') {
139
- corsConfigNode = corsCall.arguments[0];
140
- }
141
- }
142
- let corsCallNode = null;
143
- if (isStandaloneCorsCall(node)) {
144
- corsCallNode = node;
145
- }
146
- else {
147
- corsCallNode = node.arguments[0];
148
- }
149
- if (corsCallNode && corsCallNode.arguments.length === 0) {
150
- context.report({
151
- node: corsCallNode,
152
- messageId: 'permissiveCors',
153
- data: {
154
- reason: 'cors() with no options uses permissive defaults',
155
- },
156
- suggest: [
157
- {
158
- messageId: 'useWhitelist',
159
- fix: () => null,
160
- },
161
- ],
162
- });
163
- return;
164
- }
165
- if (corsConfigNode) {
166
- const { isPermissive, reason } = isPermissiveCorsConfig(corsConfigNode, sourceCode, { allowOriginTrue });
167
- if (isPermissive) {
168
- context.report({
169
- node: corsConfigNode,
170
- messageId: 'permissiveCors',
171
- data: { reason },
172
- suggest: [
173
- {
174
- messageId: 'useWhitelist',
175
- fix: () => null,
176
- },
177
- ],
178
- });
179
- }
180
- }
181
- }
182
- },
183
- };
184
- },
185
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCors=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function isPermissiveCorsConfig(node,sourceCode,options){const text=sourceCode.getText(node);if(/\borigin\s*:\s*['"`]\*['"`]/.test(text)){return{isPermissive:true,reason:"origin: '*' allows any domain to access your API"}}if(!options.allowOriginTrue&&/\borigin\s*:\s*true\b/.test(text)){return{isPermissive:true,reason:"origin: true reflects the request origin, allowing any domain"}}if(/\bcredentials\s*:\s*true\b/.test(text)){if(/\borigin\s*:\s*true\b/.test(text)){return{isPermissive:true,reason:"origin: true with credentials: true allows credential leakage to any domain"}}}return{isPermissive:false,reason:""}}function isStandaloneCorsCall(node){const callee=node.callee;if(callee.type==="Identifier"&&callee.name==="cors"){const parent=node.parent;if(parent&&parent.type==="CallExpression"&&parent.callee.type==="MemberExpression"&&parent.callee.property.type==="Identifier"&&parent.callee.property.name==="use"){return false}return true}return false}function isAppUseCors(node){const callee=node.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="use"){const firstArg=node.arguments[0];if(firstArg&&firstArg.type==="CallExpression"&&firstArg.callee.type==="Identifier"&&firstArg.callee.name==="cors"){return true}}return false}exports.noPermissiveCors=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-permissive-cors.md",description:"Disallow overly permissive CORS configurations (wildcard origin, origin: true)",cwe:"CWE-942",cvss:7.5},hasSuggestions:true,messages:{permissiveCors:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Permissive CORS Configuration",cwe:"CWE-942",description:"{{reason}}",severity:"HIGH",fix:'Specify an explicit whitelist of allowed origins: origin: ["https://trusted-domain.com"]',documentationLink:"https://owasp.org/www-community/attacks/CORS_OriginHeaderScrutiny"}),useWhitelist:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Origin Whitelist",description:"Replace with explicit origin whitelist",severity:"LOW",fix:'origin: ["https://your-frontend.com", "https://app.your-domain.com"]',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow permissive CORS in test files"},allowOriginTrue:{type:"boolean",default:false,description:"Allow origin: true for development"},allowedOrigins:{type:"array",items:{type:"string"},default:[],description:"Allowed origins that should not trigger warnings"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,allowOriginTrue:false,allowedOrigins:[]}],create(context,[options]){const{allowInTests=false,allowOriginTrue=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){if(isStandaloneCorsCall(node)||isAppUseCors(node)){let corsConfigNode=null;if(isStandaloneCorsCall(node)&&node.arguments[0]?.type==="ObjectExpression"){corsConfigNode=node.arguments[0]}else if(isAppUseCors(node)){const corsCall=node.arguments[0];if(corsCall.arguments[0]?.type==="ObjectExpression"){corsConfigNode=corsCall.arguments[0]}}let corsCallNode=null;if(isStandaloneCorsCall(node)){corsCallNode=node}else{corsCallNode=node.arguments[0]}if(corsCallNode&&corsCallNode.arguments.length===0){context.report({node:corsCallNode,messageId:"permissiveCors",data:{reason:"cors() with no options uses permissive defaults"},suggest:[{messageId:"useWhitelist",fix:()=>null}]});return}if(corsConfigNode){const{isPermissive,reason}=isPermissiveCorsConfig(corsConfigNode,sourceCode,{allowOriginTrue});if(isPermissive){context.report({node:corsConfigNode,messageId:"permissiveCors",data:{reason},suggest:[{messageId:"useWhitelist",fix:()=>null}]})}}}}}}});
@@ -1,106 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noPermissiveTrustProxy = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const TRUST_PROXY = 'trust proxy';
6
- const APP_RECEIVER = /^(app|server|router|express)$/i;
7
- function isAppMethodCall(node, method) {
8
- const callee = node.callee;
9
- if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
10
- return false;
11
- if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
12
- return false;
13
- if (callee.computed)
14
- return false;
15
- if (callee.property.name !== method)
16
- return false;
17
- if (callee.object.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
18
- return false;
19
- return APP_RECEIVER.test(callee.object.name);
20
- }
21
- function isTrustProxyLiteral(node) {
22
- return (node !== undefined &&
23
- node.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
24
- node.value === TRUST_PROXY);
25
- }
26
- exports.noPermissiveTrustProxy = (0, eslint_devkit_1.createRule)({
27
- name: 'no-permissive-trust-proxy',
28
- meta: {
29
- type: 'problem',
30
- hasSuggestions: true,
31
- docs: {
32
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-permissive-trust-proxy.md',
33
- description: "Disallow unconditional 'trust proxy' — it makes req.ip client-controlled",
34
- cwe: 'CWE-348',
35
- cvss: 5.3,
36
- confidence: 'high',
37
- },
38
- messages: {
39
- permissiveTrustProxy: (0, eslint_devkit_1.formatLLMMessage)({
40
- icon: eslint_devkit_1.MessageIcons.SECURITY,
41
- issueName: 'Unconditional Proxy Trust (CWE-348)',
42
- cwe: 'CWE-348',
43
- cvss: 5.3,
44
- description: "'trust proxy' is enabled unconditionally, so Express takes the left-most X-Forwarded-For entry as req.ip. A client can send any address it likes — rate-limit buckets, IP allowlists and audit logs all follow the forged value.",
45
- severity: 'MEDIUM',
46
- fix: "Set the number of proxies you actually run behind — app.set('trust proxy', {{hops}}) — or a subnet/'loopback'/predicate that names them.",
47
- documentationLink: 'https://expressjs.com/en/guide/behind-proxies.html',
48
- }),
49
- useHopCount: "Trust exactly {{hops}} proxy hop(s) instead",
50
- },
51
- schema: [
52
- {
53
- type: 'object',
54
- properties: {
55
- hopCount: {
56
- type: 'number',
57
- minimum: 1,
58
- description: 'Number of reverse proxies used in the suggested fix',
59
- },
60
- },
61
- additionalProperties: false,
62
- },
63
- ],
64
- },
65
- defaultOptions: [{}],
66
- create(context, [options]) {
67
- const { hopCount } = options;
68
- const hops = hopCount ?? 1;
69
- function report(node, replacement) {
70
- context.report({
71
- node,
72
- messageId: 'permissiveTrustProxy',
73
- data: { hops: String(hops) },
74
- suggest: [
75
- {
76
- messageId: 'useHopCount',
77
- data: { hops: String(hops) },
78
- fix: (fixer) => fixer.replaceText(node, replacement),
79
- },
80
- ],
81
- });
82
- }
83
- return {
84
- CallExpression(node) {
85
- if (isAppMethodCall(node, 'enable')) {
86
- if (!isTrustProxyLiteral(node.arguments[0]))
87
- return;
88
- const receiver = context.sourceCode.getText(node.callee.object);
89
- report(node, `${receiver}.set('trust proxy', ${hops})`);
90
- return;
91
- }
92
- if (!isAppMethodCall(node, 'set'))
93
- return;
94
- if (!isTrustProxyLiteral(node.arguments[0]))
95
- return;
96
- const value = node.arguments[1];
97
- if (!value ||
98
- value.type !== eslint_devkit_1.AST_NODE_TYPES.Literal ||
99
- value.value !== true) {
100
- return;
101
- }
102
- report(value, String(hops));
103
- },
104
- };
105
- },
106
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveTrustProxy=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const TRUST_PROXY="trust proxy";const APP_RECEIVER=/^(app|server|router|express)$/i;function isAppMethodCall(node,method){const callee=node.callee;if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;if(callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(callee.computed)return false;if(callee.property.name!==method)return false;if(callee.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;return APP_RECEIVER.test(callee.object.name)}function isTrustProxyLiteral(node){return node!==void 0&&node.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&node.value===TRUST_PROXY}exports.noPermissiveTrustProxy=(0,eslint_devkit_1.createRule)({name:"no-permissive-trust-proxy",meta:{type:"problem",hasSuggestions:true,docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-permissive-trust-proxy.md",description:"Disallow unconditional 'trust proxy' \u2014 it makes req.ip client-controlled",cwe:"CWE-348",cvss:5.3,confidence:"high"},messages:{permissiveTrustProxy:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unconditional Proxy Trust (CWE-348)",cwe:"CWE-348",cvss:5.3,description:"'trust proxy' is enabled unconditionally, so Express takes the left-most X-Forwarded-For entry as req.ip. A client can send any address it likes \u2014 rate-limit buckets, IP allowlists and audit logs all follow the forged value.",severity:"MEDIUM",fix:"Set the number of proxies you actually run behind \u2014 app.set('trust proxy', {{hops}}) \u2014 or a subnet/'loopback'/predicate that names them.",documentationLink:"https://expressjs.com/en/guide/behind-proxies.html"}),useHopCount:"Trust exactly {{hops}} proxy hop(s) instead"},schema:[{type:"object",properties:{hopCount:{type:"number",minimum:1,description:"Number of reverse proxies used in the suggested fix"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{hopCount}=options;const hops=hopCount??1;function report(node,replacement){context.report({node,messageId:"permissiveTrustProxy",data:{hops:String(hops)},suggest:[{messageId:"useHopCount",data:{hops:String(hops)},fix:fixer=>fixer.replaceText(node,replacement)}]})}return{CallExpression(node){if(isAppMethodCall(node,"enable")){if(!isTrustProxyLiteral(node.arguments[0]))return;const receiver=context.sourceCode.getText(node.callee.object);report(node,`${receiver}.set('trust proxy', ${hops})`);return}if(!isAppMethodCall(node,"set"))return;if(!isTrustProxyLiteral(node.arguments[0]))return;const value=node.arguments[1];if(!value||value.type!==eslint_devkit_1.AST_NODE_TYPES.Literal||value.value!==true){return}report(value,String(hops))}}}});