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,176 +1 @@
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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noErrorDetailsInResponse=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const SEND_METHODS=new Set(["send","json","end"]);const ERROR_PARAM_NAME=/^(err|error)$/i;exports.noErrorDetailsInResponse=(0,eslint_devkit_1.createRule)({name:"no-error-details-in-response",meta:{type:"problem",hasSuggestions:false,docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-error-details-in-response.md",description:"Disallow sending caught error objects, stacks, or spreads of them in HTTP responses",cwe:"CWE-209",cvss:5.3},messages:{errorDetailsExposed:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Error Details Exposed (CWE-209)",cwe:"CWE-209",description:"The HTTP response includes {{detail}}. Stack traces and driver errors leak file paths, dependency versions, query text and hostnames to the caller.",severity:"MEDIUM",fix:"Log the error server-side and respond with a generic body: logger.error(err); res.status(500).json({ error: 'Internal Server Error' })",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html"})},schema:[{type:"object",properties:{allowMessage:{type:"boolean",default:true,description:"Allow err.message in responses"},allowInDev:{type:"boolean",default:false,description:"Allow error details inside an if-guard checking NODE_ENV"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{allowMessage,allowInDev}=options;const messageAllowed=allowMessage??true;const devAllowed=allowInDev??false;const sourceCode=context.sourceCode;const frames=[];function isErrorName(name){return frames.some(frame=>frame.name===name)}function enterFunction(node){const first=node.params[0];if(first!==void 0&&first.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&ERROR_PARAM_NAME.test(first.name)){frames.push({node,name:first.name})}}function exitFrame(node){if(frames.length>0&&frames[frames.length-1].node===node){frames.pop()}}function isResponseSend(node){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(!SEND_METHODS.has(callee.property.name))return false;let obj=callee.object;while(obj.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression&&obj.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){obj=obj.callee.object}if(obj.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;const lower=obj.name.toLowerCase();return lower==="res"||lower==="response"||lower==="reply"}function detailOf(node){if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isErrorName(node.name)){return`the raw error \`${node.name}\``}if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&!node.computed&&node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isErrorName(node.object.name)&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){if(node.property.name==="stack"){return`\`${node.object.name}.stack\``}if(node.property.name==="message"&&!messageAllowed){return`\`${node.object.name}.message\``}}return null}function collectFindings(arg){const direct=detailOf(arg);if(direct!==null)return[{node:arg,detail:direct}];if(arg.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)return[];const findings=[];for(const prop of arg.properties){if(prop.type===eslint_devkit_1.AST_NODE_TYPES.SpreadElement){if(prop.argument.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&isErrorName(prop.argument.name)){findings.push({node:prop,detail:`\`{ ...${prop.argument.name} }\` (spread of the raw error)`})}continue}const detail=detailOf(prop.value);if(detail!==null)findings.push({node:prop.value,detail})}return findings}function isInDevGuard(node){let current=node.parent;while(current!=null){if(current.type===eslint_devkit_1.AST_NODE_TYPES.IfStatement&&sourceCode.getText(current.test).includes("NODE_ENV")){return true}current=current.parent}return false}return{CatchClause(node){if(node.param!==null&&node.param.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){frames.push({node,name:node.param.name})}},"CatchClause:exit":exitFrame,FunctionDeclaration:enterFunction,"FunctionDeclaration:exit":exitFrame,FunctionExpression:enterFunction,"FunctionExpression:exit":exitFrame,ArrowFunctionExpression:enterFunction,"ArrowFunctionExpression:exit":exitFrame,CallExpression(node){if(frames.length===0)return;if(!isResponseSend(node))return;const arg=node.arguments[0];if(arg===void 0)return;if(devAllowed&&isInDevGuard(node))return;for(const finding of collectFindings(arg)){context.report({node:finding.node,messageId:"errorDetailsExposed",data:{detail:finding.detail}})}}}}});
@@ -1,96 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noExposedDebugEndpoints = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
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
- ]);
18
- exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
19
- name: 'no-exposed-debug-endpoints',
20
- meta: {
21
- type: 'problem',
22
- docs: {
23
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-exposed-debug-endpoints.md',
24
- description: 'Detect debug endpoints without auth in Express applications',
25
- cwe: 'CWE-489',
26
- cvss: 7.5,
27
- },
28
- messages: {
29
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
30
- icon: eslint_devkit_1.MessageIcons.SECURITY,
31
- issueName: 'Exposed Debug Endpoint',
32
- cwe: 'CWE-489',
33
- description: 'Debug endpoint exposed without authentication',
34
- severity: 'HIGH',
35
- fix: 'Remove debug endpoints from production or add authentication',
36
- documentationLink: 'https://cwe.mitre.org/data/definitions/489.html',
37
- })
38
- },
39
- schema: [
40
- {
41
- type: 'object',
42
- properties: {
43
- endpoints: {
44
- type: 'array',
45
- items: { type: 'string' },
46
- description: 'Custom list of debug/admin endpoints to flag'
47
- },
48
- ignoreFiles: {
49
- type: 'array',
50
- items: { type: 'string' },
51
- description: 'List of files or patterns to ignore'
52
- }
53
- },
54
- additionalProperties: false
55
- }
56
- ],
57
- },
58
- defaultOptions: [{}],
59
- create(context) {
60
- const options = context.options[0] || {};
61
- const debugPaths = options.endpoints || DEFAULT_DEBUG_PATHS;
62
- const ignoreFiles = options.ignoreFiles || [];
63
- const filename = context.filename;
64
- if (ignoreFiles.some(pattern => filename.includes(pattern))) {
65
- return {};
66
- }
67
- const isExpressRouteCall = (node) => {
68
- return (node.callee.type === 'MemberExpression' &&
69
- node.callee.object.type === 'Identifier' &&
70
- ['app', 'router', 'express'].includes(node.callee.object.name) &&
71
- node.callee.property.type === 'Identifier' &&
72
- HTTP_METHODS.has(node.callee.property.name));
73
- };
74
- return {
75
- CallExpression(node) {
76
- if (!isExpressRouteCall(node)) {
77
- return;
78
- }
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' });
91
- }
92
- }
93
- },
94
- };
95
- },
96
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExposedDebugEndpoints=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DEFAULT_DEBUG_PATHS=["/debug","/__debug__","/admin","/_admin","/test","/health"];const HTTP_METHODS=new Set(["get","post","put","patch","delete","head","options","all","use","route"]);exports.noExposedDebugEndpoints=(0,eslint_devkit_1.createRule)({name:"no-exposed-debug-endpoints",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-exposed-debug-endpoints.md",description:"Detect debug endpoints without auth in Express applications",cwe:"CWE-489",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Exposed Debug Endpoint",cwe:"CWE-489",description:"Debug endpoint exposed without authentication",severity:"HIGH",fix:"Remove debug endpoints from production or add authentication",documentationLink:"https://cwe.mitre.org/data/definitions/489.html"})},schema:[{type:"object",properties:{endpoints:{type:"array",items:{type:"string"},description:"Custom list of debug/admin endpoints to flag"},ignoreFiles:{type:"array",items:{type:"string"},description:"List of files or patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{}],create(context){const options=context.options[0]||{};const debugPaths=options.endpoints||DEFAULT_DEBUG_PATHS;const ignoreFiles=options.ignoreFiles||[];const filename=context.filename;if(ignoreFiles.some(pattern=>filename.includes(pattern))){return{}}const isExpressRouteCall=node=>{return node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&["app","router","express"].includes(node.callee.object.name)&&node.callee.property.type==="Identifier"&&HTTP_METHODS.has(node.callee.property.name)};return{CallExpression(node){if(!isExpressRouteCall(node)){return}const isSettingLookup=node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="get"&&node.arguments.length===1;if(isSettingLookup){return}const pathArg=node.arguments[0];if(pathArg&&pathArg.type==="Literal"&&typeof pathArg.value==="string"){const path=pathArg.value.toLowerCase();if(debugPaths.some(dp=>path.includes(dp.toLowerCase()))){context.report({node:pathArg,messageId:"violationDetected"})}}}}}});
@@ -1,154 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noExpressUnsafeRegexRoute = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const HTTP_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all', 'use']);
6
- const VULNERABLE_PATTERNS = [
7
- /\([^)]*[+*][^)]*\)[+*]/,
8
- /\([^)]*\|[^)]*\)[+*]/,
9
- /[+*]{2,}/,
10
- /\([^)]+\)[+*].*\\[1-9]/,
11
- ];
12
- const VULNERABLE_PARAM_PATTERNS = [
13
- /:[a-zA-Z_][a-zA-Z0-9_]*\+/,
14
- /:[a-zA-Z_][a-zA-Z0-9_]*\*/,
15
- ];
16
- function isVulnerableRegex(pattern) {
17
- return VULNERABLE_PATTERNS.some((regex) => regex.test(pattern));
18
- }
19
- function hasVulnerableParamPattern(route) {
20
- return VULNERABLE_PARAM_PATTERNS.some((regex) => regex.test(route));
21
- }
22
- exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
23
- name: 'no-express-unsafe-regex-route',
24
- meta: {
25
- type: 'problem',
26
- docs: {
27
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-express-unsafe-regex-route.md',
28
- description: 'Disallow ReDoS-vulnerable regular expressions in Express.js route patterns',
29
- cwe: 'CWE-1333',
30
- cvss: 7.5,
31
- },
32
- hasSuggestions: true,
33
- messages: {
34
- unsafeRegexRoute: (0, eslint_devkit_1.formatLLMMessage)({
35
- icon: eslint_devkit_1.MessageIcons.SECURITY,
36
- issueName: 'ReDoS Vulnerable Route Pattern',
37
- cwe: 'CWE-1333',
38
- description: 'Route uses a regular expression vulnerable to Regular Expression Denial of Service (ReDoS). Malicious input can cause catastrophic backtracking.',
39
- severity: 'HIGH',
40
- fix: 'Simplify the regex pattern. Avoid nested quantifiers like (a+)+ and overlapping alternatives. Consider using a string route with explicit parameters.',
41
- documentationLink: 'https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS',
42
- }),
43
- unsafeParamPattern: (0, eslint_devkit_1.formatLLMMessage)({
44
- icon: eslint_devkit_1.MessageIcons.SECURITY,
45
- issueName: 'Unsafe Route Parameter Pattern',
46
- cwe: 'CWE-1333',
47
- description: 'Route parameter uses + or * quantifier which can match multiple path segments, potentially causing ReDoS or unexpected behavior.',
48
- severity: 'MEDIUM',
49
- fix: 'Use explicit path segments instead of :param+ or :param*. For example: /api/:id/details instead of /api/:path+',
50
- documentationLink: 'https://expressjs.com/en/guide/routing.html',
51
- }),
52
- refactorRoute: (0, eslint_devkit_1.formatLLMMessage)({
53
- icon: eslint_devkit_1.MessageIcons.INFO,
54
- issueName: 'Refactor Route',
55
- description: 'Refactor to use a simpler, non-vulnerable pattern',
56
- severity: 'LOW',
57
- fix: 'Use string routes with explicit path segments',
58
- documentationLink: 'https://expressjs.com/en/guide/routing.html',
59
- }),
60
- },
61
- schema: [
62
- {
63
- type: 'object',
64
- properties: {
65
- allowInTests: {
66
- type: 'boolean',
67
- default: false,
68
- description: 'Allow in test files',
69
- },
70
- },
71
- additionalProperties: false,
72
- },
73
- ],
74
- },
75
- defaultOptions: [{ allowInTests: false }],
76
- create(context, [options]) {
77
- const { allowInTests = false } = options;
78
- const filename = context.filename;
79
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
80
- if (isTestFile) {
81
- return {};
82
- }
83
- return {
84
- CallExpression(node) {
85
- const callee = node.callee;
86
- if (callee.type !== 'MemberExpression') {
87
- return;
88
- }
89
- const property = callee.property;
90
- if (property.type !== 'Identifier') {
91
- return;
92
- }
93
- if (!HTTP_METHODS.has(property.name)) {
94
- return;
95
- }
96
- const routeArg = node.arguments[0];
97
- if (!routeArg) {
98
- return;
99
- }
100
- if (routeArg.type === 'Literal' && 'regex' in routeArg && routeArg.regex) {
101
- const regexNode = routeArg;
102
- const pattern = regexNode.regex.pattern;
103
- if (isVulnerableRegex(pattern)) {
104
- context.report({
105
- node: routeArg,
106
- messageId: 'unsafeRegexRoute',
107
- suggest: [
108
- {
109
- messageId: 'refactorRoute',
110
- fix: () => null,
111
- },
112
- ],
113
- });
114
- }
115
- return;
116
- }
117
- if (routeArg.type === 'NewExpression' &&
118
- routeArg.callee.type === 'Identifier' &&
119
- routeArg.callee.name === 'RegExp') {
120
- const patternArg = routeArg.arguments[0];
121
- if (patternArg && patternArg.type === 'Literal' && typeof patternArg.value === 'string') {
122
- if (isVulnerableRegex(patternArg.value)) {
123
- context.report({
124
- node: routeArg,
125
- messageId: 'unsafeRegexRoute',
126
- suggest: [
127
- {
128
- messageId: 'refactorRoute',
129
- fix: () => null,
130
- },
131
- ],
132
- });
133
- }
134
- }
135
- return;
136
- }
137
- if (routeArg.type === 'Literal' && typeof routeArg.value === 'string') {
138
- if (hasVulnerableParamPattern(routeArg.value)) {
139
- context.report({
140
- node: routeArg,
141
- messageId: 'unsafeParamPattern',
142
- suggest: [
143
- {
144
- messageId: 'refactorRoute',
145
- fix: () => null,
146
- },
147
- ],
148
- });
149
- }
150
- }
151
- },
152
- };
153
- },
154
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noExpressUnsafeRegexRoute=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const HTTP_METHODS=new Set(["get","post","put","patch","delete","all","use"]);const VULNERABLE_PATTERNS=[/\([^)]*[+*][^)]*\)[+*]/,/\([^)]*\|[^)]*\)[+*]/,/[+*]{2,}/,/\([^)]+\)[+*].*\\[1-9]/];const VULNERABLE_PARAM_PATTERNS=[/:[a-zA-Z_][a-zA-Z0-9_]*\+/,/:[a-zA-Z_][a-zA-Z0-9_]*\*/];function isVulnerableRegex(pattern){return VULNERABLE_PATTERNS.some(regex=>regex.test(pattern))}function hasVulnerableParamPattern(route){return VULNERABLE_PARAM_PATTERNS.some(regex=>regex.test(route))}exports.noExpressUnsafeRegexRoute=(0,eslint_devkit_1.createRule)({name:"no-express-unsafe-regex-route",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-express-unsafe-regex-route.md",description:"Disallow ReDoS-vulnerable regular expressions in Express.js route patterns",cwe:"CWE-1333",cvss:7.5},hasSuggestions:true,messages:{unsafeRegexRoute:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"ReDoS Vulnerable Route Pattern",cwe:"CWE-1333",description:"Route uses a regular expression vulnerable to Regular Expression Denial of Service (ReDoS). Malicious input can cause catastrophic backtracking.",severity:"HIGH",fix:"Simplify the regex pattern. Avoid nested quantifiers like (a+)+ and overlapping alternatives. Consider using a string route with explicit parameters.",documentationLink:"https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS"}),unsafeParamPattern:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe Route Parameter Pattern",cwe:"CWE-1333",description:"Route parameter uses + or * quantifier which can match multiple path segments, potentially causing ReDoS or unexpected behavior.",severity:"MEDIUM",fix:"Use explicit path segments instead of :param+ or :param*. For example: /api/:id/details instead of /api/:path+",documentationLink:"https://expressjs.com/en/guide/routing.html"}),refactorRoute:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Refactor Route",description:"Refactor to use a simpler, non-vulnerable pattern",severity:"LOW",fix:"Use string routes with explicit path segments",documentationLink:"https://expressjs.com/en/guide/routing.html"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow in test files"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false}],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{}}return{CallExpression(node){const callee=node.callee;if(callee.type!=="MemberExpression"){return}const property=callee.property;if(property.type!=="Identifier"){return}if(!HTTP_METHODS.has(property.name)){return}const routeArg=node.arguments[0];if(!routeArg){return}if(routeArg.type==="Literal"&&"regex"in routeArg&&routeArg.regex){const regexNode=routeArg;const pattern=regexNode.regex.pattern;if(isVulnerableRegex(pattern)){context.report({node:routeArg,messageId:"unsafeRegexRoute",suggest:[{messageId:"refactorRoute",fix:()=>null}]})}return}if(routeArg.type==="NewExpression"&&routeArg.callee.type==="Identifier"&&routeArg.callee.name==="RegExp"){const patternArg=routeArg.arguments[0];if(patternArg&&patternArg.type==="Literal"&&typeof patternArg.value==="string"){if(isVulnerableRegex(patternArg.value)){context.report({node:routeArg,messageId:"unsafeRegexRoute",suggest:[{messageId:"refactorRoute",fix:()=>null}]})}}return}if(routeArg.type==="Literal"&&typeof routeArg.value==="string"){if(hasVulnerableParamPattern(routeArg.value)){context.report({node:routeArg,messageId:"unsafeParamPattern",suggest:[{messageId:"refactorRoute",fix:()=>null}]})}}}}}});
@@ -1,143 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noGraphqlIntrospectionProduction = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- function hasIntrospectionEnabled(node, sourceCode) {
6
- const text = sourceCode.getText(node);
7
- if (/\bintrospection\s*:\s*true\b/.test(text)) {
8
- return true;
9
- }
10
- return false;
11
- }
12
- function hasProductionGuard(node, sourceCode) {
13
- const text = sourceCode.getText(node);
14
- const productionGuards = [
15
- /introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]production['"]/,
16
- /introspection\s*:\s*!?\s*isProd/,
17
- /introspection\s*:\s*!?\s*isProduction/,
18
- /introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]development['"]/,
19
- ];
20
- return productionGuards.some((guard) => guard.test(text));
21
- }
22
- exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
23
- name: 'no-graphql-introspection-production',
24
- meta: {
25
- type: 'problem',
26
- docs: {
27
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-graphql-introspection-production.md',
28
- description: 'Disallow GraphQL introspection in production environments',
29
- cwe: 'CWE-200',
30
- cvss: 5,
31
- },
32
- hasSuggestions: true,
33
- messages: {
34
- graphqlIntrospection: (0, eslint_devkit_1.formatLLMMessage)({
35
- icon: eslint_devkit_1.MessageIcons.SECURITY,
36
- issueName: 'GraphQL Introspection Enabled',
37
- cwe: 'CWE-200',
38
- description: 'GraphQL introspection is enabled. In production, this exposes your entire API schema to attackers.',
39
- severity: 'MEDIUM',
40
- fix: "Set introspection: process.env.NODE_ENV !== 'production' or introspection: false",
41
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/GraphQL_Cheat_Sheet.html#introspection-graphiql',
42
- }),
43
- disableIntrospection: (0, eslint_devkit_1.formatLLMMessage)({
44
- icon: eslint_devkit_1.MessageIcons.INFO,
45
- issueName: 'Disable Introspection in Production',
46
- description: 'Disable GraphQL introspection for production',
47
- severity: 'LOW',
48
- fix: "introspection: process.env.NODE_ENV !== 'production'",
49
- documentationLink: 'https://www.apollographql.com/docs/apollo-server/api/apollo-server/#introspection',
50
- }),
51
- },
52
- schema: [
53
- {
54
- type: 'object',
55
- properties: {
56
- allowInTests: {
57
- type: 'boolean',
58
- default: true,
59
- },
60
- allowInDevelopment: {
61
- type: 'boolean',
62
- default: true, description: 'Allow introspection when the code is guarded by a development check'
63
- },
64
- },
65
- additionalProperties: false,
66
- },
67
- ],
68
- },
69
- defaultOptions: [
70
- {
71
- allowInTests: true,
72
- allowInDevelopment: true,
73
- },
74
- ],
75
- create(context, [options]) {
76
- const { allowInTests = true } = options;
77
- const filename = context.filename;
78
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
79
- if (isTestFile) {
80
- return {};
81
- }
82
- const sourceCode = context.sourceCode;
83
- return {
84
- CallExpression(node) {
85
- const callee = node.callee;
86
- const isGraphQLServer = (callee.type === 'Identifier' &&
87
- ['ApolloServer', 'GraphQLServer', 'createServer'].includes(callee.name)) ||
88
- (callee.type === 'NewExpression' &&
89
- callee.callee.type === 'Identifier' &&
90
- ['ApolloServer', 'GraphQLServer'].includes(callee.callee.name));
91
- const isExpressGraphQL = callee.type === 'Identifier' && callee.name === 'graphqlHTTP';
92
- if (!isGraphQLServer && !isExpressGraphQL) {
93
- return;
94
- }
95
- const configArg = node.arguments[0];
96
- if (!configArg || configArg.type !== 'ObjectExpression') {
97
- return;
98
- }
99
- if (hasProductionGuard(configArg, sourceCode)) {
100
- return;
101
- }
102
- if (hasIntrospectionEnabled(configArg, sourceCode)) {
103
- context.report({
104
- node: configArg,
105
- messageId: 'graphqlIntrospection',
106
- suggest: [
107
- {
108
- messageId: 'disableIntrospection',
109
- fix: () => null,
110
- },
111
- ],
112
- });
113
- }
114
- },
115
- NewExpression(node) {
116
- const callee = node.callee;
117
- if (callee.type !== 'Identifier' ||
118
- !['ApolloServer', 'GraphQLServer'].includes(callee.name)) {
119
- return;
120
- }
121
- const configArg = node.arguments[0];
122
- if (!configArg || configArg.type !== 'ObjectExpression') {
123
- return;
124
- }
125
- if (hasProductionGuard(configArg, sourceCode)) {
126
- return;
127
- }
128
- if (hasIntrospectionEnabled(configArg, sourceCode)) {
129
- context.report({
130
- node: configArg,
131
- messageId: 'graphqlIntrospection',
132
- suggest: [
133
- {
134
- messageId: 'disableIntrospection',
135
- fix: () => null,
136
- },
137
- ],
138
- });
139
- }
140
- },
141
- };
142
- },
143
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noGraphqlIntrospectionProduction=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function hasIntrospectionEnabled(node,sourceCode){const text=sourceCode.getText(node);if(/\bintrospection\s*:\s*true\b/.test(text)){return true}return false}function hasProductionGuard(node,sourceCode){const text=sourceCode.getText(node);const productionGuards=[/introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]production['"]/,/introspection\s*:\s*!?\s*isProd/,/introspection\s*:\s*!?\s*isProduction/,/introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]development['"]/];return productionGuards.some(guard=>guard.test(text))}exports.noGraphqlIntrospectionProduction=(0,eslint_devkit_1.createRule)({name:"no-graphql-introspection-production",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-graphql-introspection-production.md",description:"Disallow GraphQL introspection in production environments",cwe:"CWE-200",cvss:5},hasSuggestions:true,messages:{graphqlIntrospection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"GraphQL Introspection Enabled",cwe:"CWE-200",description:"GraphQL introspection is enabled. In production, this exposes your entire API schema to attackers.",severity:"MEDIUM",fix:"Set introspection: process.env.NODE_ENV !== 'production' or introspection: false",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/GraphQL_Cheat_Sheet.html#introspection-graphiql"}),disableIntrospection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Disable Introspection in Production",description:"Disable GraphQL introspection for production",severity:"LOW",fix:"introspection: process.env.NODE_ENV !== 'production'",documentationLink:"https://www.apollographql.com/docs/apollo-server/api/apollo-server/#introspection"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true},allowInDevelopment:{type:"boolean",default:true,description:"Allow introspection when the code is guarded by a development check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:true,allowInDevelopment:true}],create(context,[options]){const{allowInTests=true}=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;const isGraphQLServer=callee.type==="Identifier"&&["ApolloServer","GraphQLServer","createServer"].includes(callee.name)||callee.type==="NewExpression"&&callee.callee.type==="Identifier"&&["ApolloServer","GraphQLServer"].includes(callee.callee.name);const isExpressGraphQL=callee.type==="Identifier"&&callee.name==="graphqlHTTP";if(!isGraphQLServer&&!isExpressGraphQL){return}const configArg=node.arguments[0];if(!configArg||configArg.type!=="ObjectExpression"){return}if(hasProductionGuard(configArg,sourceCode)){return}if(hasIntrospectionEnabled(configArg,sourceCode)){context.report({node:configArg,messageId:"graphqlIntrospection",suggest:[{messageId:"disableIntrospection",fix:()=>null}]})}},NewExpression(node){const callee=node.callee;if(callee.type!=="Identifier"||!["ApolloServer","GraphQLServer"].includes(callee.name)){return}const configArg=node.arguments[0];if(!configArg||configArg.type!=="ObjectExpression"){return}if(hasProductionGuard(configArg,sourceCode)){return}if(hasIntrospectionEnabled(configArg,sourceCode)){context.report({node:configArg,messageId:"graphqlIntrospection",suggest:[{messageId:"disableIntrospection",fix:()=>null}]})}}}}});