eslint-plugin-express-security 0.0.1

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 (37) hide show
  1. package/AGENTS.md +100 -0
  2. package/CHANGELOG.md +51 -0
  3. package/README.md +424 -0
  4. package/package.json +99 -0
  5. package/src/index.d.ts +35 -0
  6. package/src/index.js +144 -0
  7. package/src/index.js.map +1 -0
  8. package/src/rules/no-cors-credentials-wildcard/index.d.ts +5 -0
  9. package/src/rules/no-cors-credentials-wildcard/index.js +142 -0
  10. package/src/rules/no-cors-credentials-wildcard/index.js.map +1 -0
  11. package/src/rules/no-express-unsafe-regex-route/index.d.ts +5 -0
  12. package/src/rules/no-express-unsafe-regex-route/index.js +181 -0
  13. package/src/rules/no-express-unsafe-regex-route/index.js.map +1 -0
  14. package/src/rules/no-graphql-introspection-production/index.d.ts +7 -0
  15. package/src/rules/no-graphql-introspection-production/index.js +161 -0
  16. package/src/rules/no-graphql-introspection-production/index.js.map +1 -0
  17. package/src/rules/no-insecure-cookie-options/index.d.ts +13 -0
  18. package/src/rules/no-insecure-cookie-options/index.js +162 -0
  19. package/src/rules/no-insecure-cookie-options/index.js.map +1 -0
  20. package/src/rules/no-permissive-cors/index.d.ts +9 -0
  21. package/src/rules/no-permissive-cors/index.js +205 -0
  22. package/src/rules/no-permissive-cors/index.js.map +1 -0
  23. package/src/rules/require-csrf-protection/index.d.ts +9 -0
  24. package/src/rules/require-csrf-protection/index.js +240 -0
  25. package/src/rules/require-csrf-protection/index.js.map +1 -0
  26. package/src/rules/require-express-body-parser-limits/index.d.ts +9 -0
  27. package/src/rules/require-express-body-parser-limits/index.js +201 -0
  28. package/src/rules/require-express-body-parser-limits/index.js.map +1 -0
  29. package/src/rules/require-helmet/index.d.ts +9 -0
  30. package/src/rules/require-helmet/index.js +185 -0
  31. package/src/rules/require-helmet/index.js.map +1 -0
  32. package/src/rules/require-rate-limiting/index.d.ts +12 -0
  33. package/src/rules/require-rate-limiting/index.js +142 -0
  34. package/src/rules/require-rate-limiting/index.js.map +1 -0
  35. package/src/types/index.d.ts +27 -0
  36. package/src/types/index.js +3 -0
  37. package/src/types/index.js.map +1 -0
package/src/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * eslint-plugin-express-security
3
+ *
4
+ * A comprehensive security-focused ESLint plugin for Express.js applications
5
+ * with rules for detecting and preventing security vulnerabilities.
6
+ *
7
+ * Features:
8
+ * - LLM-optimized error messages with CWE references
9
+ * - OWASP Top 10 coverage
10
+ * - Express-specific security patterns
11
+ * - Framework-aware middleware detection
12
+ *
13
+ * @see https://github.com/ofri-peretz/eslint#readme
14
+ */
15
+ import { TSESLint } from '@interlace/eslint-devkit';
16
+ /**
17
+ * Collection of all Express security ESLint rules
18
+ */
19
+ export declare const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>>;
20
+ /**
21
+ * ESLint Plugin object
22
+ */
23
+ export declare const plugin: TSESLint.FlatConfig.Plugin;
24
+ /**
25
+ * Preset configurations for Express security rules
26
+ */
27
+ export declare const configs: Record<string, TSESLint.FlatConfig.Config>;
28
+ /**
29
+ * Default export for ESLint plugin
30
+ */
31
+ export default plugin;
32
+ /**
33
+ * Re-export all types from the types barrel
34
+ */
35
+ export type { RequireHelmetOptions, NoPermissiveCorsOptions, RequireCsrfProtectionOptions, NoInsecureCookieOptions, RequireRateLimitingOptions, NoGraphqlIntrospectionProductionOptions, NoCorsCredentialsWildcardOptions, RequireExpressBodyParserLimitsOptions, NoExpressUnsafeRegexRouteOptions, AllExpressSecurityRulesOptions, } from './types/index';
package/src/index.js ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * eslint-plugin-express-security
4
+ *
5
+ * A comprehensive security-focused ESLint plugin for Express.js applications
6
+ * with rules for detecting and preventing security vulnerabilities.
7
+ *
8
+ * Features:
9
+ * - LLM-optimized error messages with CWE references
10
+ * - OWASP Top 10 coverage
11
+ * - Express-specific security patterns
12
+ * - Framework-aware middleware detection
13
+ *
14
+ * @see https://github.com/ofri-peretz/eslint#readme
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.configs = exports.plugin = exports.rules = void 0;
18
+ // Security rules - Headers & CORS
19
+ const require_helmet_1 = require("./rules/require-helmet");
20
+ const no_permissive_cors_1 = require("./rules/no-permissive-cors");
21
+ // Security rules - CSRF & Cookies
22
+ const require_csrf_protection_1 = require("./rules/require-csrf-protection");
23
+ const no_insecure_cookie_options_1 = require("./rules/no-insecure-cookie-options");
24
+ // Security rules - Rate Limiting
25
+ const require_rate_limiting_1 = require("./rules/require-rate-limiting");
26
+ // Security rules - GraphQL
27
+ const no_graphql_introspection_production_1 = require("./rules/no-graphql-introspection-production");
28
+ // Security rules - Critical CORS & DoS
29
+ const no_cors_credentials_wildcard_1 = require("./rules/no-cors-credentials-wildcard");
30
+ const require_express_body_parser_limits_1 = require("./rules/require-express-body-parser-limits");
31
+ const no_express_unsafe_regex_route_1 = require("./rules/no-express-unsafe-regex-route");
32
+ /**
33
+ * Collection of all Express security ESLint rules
34
+ */
35
+ exports.rules = {
36
+ // Headers & CORS
37
+ 'require-helmet': require_helmet_1.requireHelmet,
38
+ 'no-permissive-cors': no_permissive_cors_1.noPermissiveCors,
39
+ // CSRF & Cookies
40
+ 'require-csrf-protection': require_csrf_protection_1.requireCsrfProtection,
41
+ 'no-insecure-cookie-options': no_insecure_cookie_options_1.noInsecureCookieOptions,
42
+ // Rate Limiting
43
+ 'require-rate-limiting': require_rate_limiting_1.requireRateLimiting,
44
+ // GraphQL
45
+ 'no-graphql-introspection-production': no_graphql_introspection_production_1.noGraphqlIntrospectionProduction,
46
+ // Critical CORS & DoS (P0)
47
+ 'no-cors-credentials-wildcard': no_cors_credentials_wildcard_1.noCorsCredentialsWildcard,
48
+ 'require-express-body-parser-limits': require_express_body_parser_limits_1.requireExpressBodyParserLimits,
49
+ 'no-express-unsafe-regex-route': no_express_unsafe_regex_route_1.noExpressUnsafeRegexRoute,
50
+ };
51
+ /**
52
+ * ESLint Plugin object
53
+ */
54
+ exports.plugin = {
55
+ meta: {
56
+ name: 'eslint-plugin-express-security',
57
+ version: '0.0.1',
58
+ },
59
+ rules: exports.rules,
60
+ };
61
+ /**
62
+ * Recommended configuration - balanced security enforcement
63
+ */
64
+ const recommendedRules = {
65
+ // Critical - Security Headers
66
+ 'express-security/require-helmet': 'error',
67
+ 'express-security/no-permissive-cors': 'error',
68
+ // High - CSRF & Cookies
69
+ 'express-security/require-csrf-protection': 'warn',
70
+ 'express-security/no-insecure-cookie-options': 'error',
71
+ // High - DDoS Protection
72
+ 'express-security/require-rate-limiting': 'warn',
73
+ // Medium - GraphQL
74
+ 'express-security/no-graphql-introspection-production': 'warn',
75
+ // Critical - CORS & DoS (P0)
76
+ 'express-security/no-cors-credentials-wildcard': 'error',
77
+ 'express-security/require-express-body-parser-limits': 'warn',
78
+ 'express-security/no-express-unsafe-regex-route': 'error',
79
+ };
80
+ /**
81
+ * Preset configurations for Express security rules
82
+ */
83
+ exports.configs = {
84
+ /**
85
+ * Recommended security configuration
86
+ *
87
+ * Enables all security rules with sensible severity levels
88
+ */
89
+ recommended: {
90
+ plugins: {
91
+ 'express-security': exports.plugin,
92
+ },
93
+ rules: recommendedRules,
94
+ },
95
+ /**
96
+ * Strict security configuration
97
+ *
98
+ * All security rules set to 'error' for maximum protection
99
+ */
100
+ strict: {
101
+ plugins: {
102
+ 'express-security': exports.plugin,
103
+ },
104
+ rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [
105
+ `express-security/${ruleName}`,
106
+ 'error',
107
+ ])),
108
+ },
109
+ /**
110
+ * API security configuration
111
+ *
112
+ * HTTP/API security rules only
113
+ */
114
+ api: {
115
+ plugins: {
116
+ 'express-security': exports.plugin,
117
+ },
118
+ rules: {
119
+ 'express-security/require-helmet': 'error',
120
+ 'express-security/no-permissive-cors': 'error',
121
+ 'express-security/require-csrf-protection': 'error',
122
+ 'express-security/no-insecure-cookie-options': 'error',
123
+ 'express-security/require-rate-limiting': 'error',
124
+ },
125
+ },
126
+ /**
127
+ * GraphQL security configuration
128
+ *
129
+ * GraphQL-specific security rules only
130
+ */
131
+ graphql: {
132
+ plugins: {
133
+ 'express-security': exports.plugin,
134
+ },
135
+ rules: {
136
+ 'express-security/no-graphql-introspection-production': 'error',
137
+ },
138
+ },
139
+ };
140
+ /**
141
+ * Default export for ESLint plugin
142
+ */
143
+ exports.default = exports.plugin;
144
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/eslint-plugin-express-security/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAIH,kCAAkC;AAClC,2DAAuD;AACvD,mEAA8D;AAE9D,kCAAkC;AAClC,6EAAwE;AACxE,mFAA6E;AAE7E,iCAAiC;AACjC,yEAAoE;AAEpE,2BAA2B;AAC3B,qGAA+F;AAE/F,uCAAuC;AACvC,uFAAiF;AACjF,mGAA4F;AAC5F,yFAAkF;AAElF;;GAEG;AACU,QAAA,KAAK,GAGd;IACF,iBAAiB;IACjB,gBAAgB,EAAE,8BAAa;IAC/B,oBAAoB,EAAE,qCAAgB;IAEtC,iBAAiB;IACjB,yBAAyB,EAAE,+CAAqB;IAChD,4BAA4B,EAAE,oDAAuB;IAErD,gBAAgB;IAChB,uBAAuB,EAAE,2CAAmB;IAE5C,UAAU;IACV,qCAAqC,EAAE,sEAAgC;IAEvE,2BAA2B;IAC3B,8BAA8B,EAAE,wDAAyB;IACzD,oCAAoC,EAAE,mEAA8B;IACpE,+BAA+B,EAAE,yDAAyB;CACe,CAAC;AAE5E;;GAEG;AACU,QAAA,MAAM,GAA+B;IAChD,IAAI,EAAE;QACJ,IAAI,EAAE,gCAAgC;QACtC,OAAO,EAAE,OAAO;KACjB;IACD,KAAK,EAAL,aAAK;CAC+B,CAAC;AAEvC;;GAEG;AACH,MAAM,gBAAgB,GAAkD;IACtE,8BAA8B;IA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allowInTests?: boolean;
4
+ }
5
+ export declare const noCorsCredentialsWildcard: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noCorsCredentialsWildcard = void 0;
4
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
+ /**
6
+ * Checks if a configuration object has origin set to '*' or true
7
+ */
8
+ function hasWildcardOrigin(node, sourceCode) {
9
+ const text = sourceCode.getText(node);
10
+ // Check for origin: '*'
11
+ if (/\borigin\s*:\s*['"`]\*['"`]/.test(text)) {
12
+ return true;
13
+ }
14
+ // Check for origin: true (reflects request origin - effectively wildcard)
15
+ if (/\borigin\s*:\s*true\b/.test(text)) {
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+ /**
21
+ * Checks if a configuration object has credentials: true
22
+ */
23
+ function hasCredentialsTrue(node, sourceCode) {
24
+ const text = sourceCode.getText(node);
25
+ return /\bcredentials\s*:\s*true\b/.test(text);
26
+ }
27
+ /**
28
+ * Check if this is a cors() call (standalone or in app.use)
29
+ * Returns the config node only for the appropriate level to avoid double-triggering
30
+ */
31
+ function getCorsConfigNode(node) {
32
+ const callee = node.callee;
33
+ // Standalone cors({...}) call - but skip if parent is app.use()
34
+ if (callee.type === 'Identifier' && callee.name === 'cors') {
35
+ // Check if this cors() is inside app.use() - if so, let app.use() handle it
36
+ const parent = node.parent;
37
+ if (parent &&
38
+ parent.type === 'CallExpression' &&
39
+ parent.callee.type === 'MemberExpression' &&
40
+ parent.callee.property.type === 'Identifier' &&
41
+ parent.callee.property.name === 'use') {
42
+ // Skip - let the app.use() case handle this
43
+ return null;
44
+ }
45
+ if (node.arguments[0]?.type === 'ObjectExpression') {
46
+ return node.arguments[0];
47
+ }
48
+ return null;
49
+ }
50
+ // app.use(cors({...}))
51
+ if (callee.type === 'MemberExpression' &&
52
+ callee.property.type === 'Identifier' &&
53
+ callee.property.name === 'use') {
54
+ const firstArg = node.arguments[0];
55
+ if (firstArg?.type === 'CallExpression' &&
56
+ firstArg.callee.type === 'Identifier' &&
57
+ firstArg.callee.name === 'cors' &&
58
+ firstArg.arguments[0]?.type === 'ObjectExpression') {
59
+ return firstArg.arguments[0];
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+ exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
65
+ name: 'no-cors-credentials-wildcard',
66
+ meta: {
67
+ type: 'problem',
68
+ docs: {
69
+ description: 'Disallow credentials: true with wildcard CORS origin (CVE-2024-25124)',
70
+ },
71
+ hasSuggestions: true,
72
+ messages: {
73
+ credentialsWildcard: (0, eslint_devkit_1.formatLLMMessage)({
74
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
75
+ issueName: 'CORS Credentials with Wildcard Origin',
76
+ cwe: 'CWE-942',
77
+ description: 'Using credentials: true with origin: "*" or origin: true allows any domain to send credentials to your API. This is a critical vulnerability (CVE-2024-25124, CVSS 9.1).',
78
+ severity: 'CRITICAL',
79
+ fix: 'Specify explicit allowed origins: origin: ["https://trusted-domain.com"]',
80
+ documentationLink: 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-25124',
81
+ }),
82
+ useExplicitOrigins: (0, eslint_devkit_1.formatLLMMessage)({
83
+ icon: eslint_devkit_1.MessageIcons.INFO,
84
+ issueName: 'Use Explicit Origins',
85
+ description: 'Replace wildcard with explicit origin whitelist',
86
+ severity: 'LOW',
87
+ fix: 'origin: ["https://your-frontend.com"]',
88
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS',
89
+ }),
90
+ },
91
+ schema: [
92
+ {
93
+ type: 'object',
94
+ properties: {
95
+ allowInTests: {
96
+ type: 'boolean',
97
+ default: false,
98
+ description: 'Allow in test files',
99
+ },
100
+ },
101
+ additionalProperties: false,
102
+ },
103
+ ],
104
+ },
105
+ defaultOptions: [
106
+ {
107
+ allowInTests: false,
108
+ },
109
+ ],
110
+ create(context, [options = {}]) {
111
+ const { allowInTests = false } = options;
112
+ const filename = context.filename;
113
+ const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
114
+ if (isTestFile) {
115
+ return {};
116
+ }
117
+ const sourceCode = context.sourceCode;
118
+ return {
119
+ CallExpression(node) {
120
+ const corsConfigNode = getCorsConfigNode(node);
121
+ if (corsConfigNode) {
122
+ const hasWildcard = hasWildcardOrigin(corsConfigNode, sourceCode);
123
+ const hasCredentials = hasCredentialsTrue(corsConfigNode, sourceCode);
124
+ // Only report if BOTH conditions are met
125
+ if (hasWildcard && hasCredentials) {
126
+ context.report({
127
+ node: corsConfigNode,
128
+ messageId: 'credentialsWildcard',
129
+ suggest: [
130
+ {
131
+ messageId: 'useExplicitOrigins',
132
+ fix: /* c8 ignore next */ () => null,
133
+ },
134
+ ],
135
+ });
136
+ }
137
+ }
138
+ },
139
+ };
140
+ },
141
+ });
142
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-express-security/src/rules/no-cors-credentials-wildcard/index.ts"],"names":[],"mappings":";;;AAWA,4DAIkC;AAWlC;;GAEG;AACH,SAAS,iBAAiB,CACxB,IAA+B,EAC/B,UAA+B;IAE/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC,wBAAwB;IACxB,IAAI,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0EAA0E;IAC1E,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CACzB,IAA+B,EAC/B,UAA+B;IAE/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAA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AY,GAAG,KAAK,EAAE,GAAG,OAAkB,CAAC;QAEpD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,MAAM,UAAU,GACd,YAAY,IAAI,iCAAiC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnE,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,OAAO;YACL,cAAc,CAAC,IAA6B;gBAC1C,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBAE/C,IAAI,cAAc,EAAE,CAAC;oBACnB,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;oBAClE,MAAM,cAAc,GAAG,kBAAkB,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;oBAEtE,yCAAyC;oBACzC,IAAI,WAAW,IAAI,cAAc,EAAE,CAAC;wBAClC,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,cAAc;4BACpB,SAAS,EAAE,qBAAqB;4BAChC,OAAO,EAAE;gCACP;oCACE,SAAS,EAAE,oBAAoB;oCAC/B,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAI;iCACrC;6BACF;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface Options {
2
+ /** Allow in test files. Default: false */
3
+ allowInTests?: boolean;
4
+ }
5
+ export declare const noExpressUnsafeRegexRoute: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
@@ -0,0 +1,181 @@
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
+ /**
6
+ * HTTP method names used for routing
7
+ */
8
+ const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'all', 'use'];
9
+ /**
10
+ * Patterns that indicate potential ReDoS vulnerability
11
+ * These are simplified heuristics - a full ReDoS detector would be more complex
12
+ */
13
+ const VULNERABLE_PATTERNS = [
14
+ // Nested quantifiers: (a+)+, (a*)*
15
+ /\([^)]*[+*][^)]*\)[+*]/,
16
+ // Overlapping alternatives: (a|a)+
17
+ /\([^)]*\|[^)]*\)[+*]/,
18
+ // Repetition of repetition: a++, a**
19
+ /[+*]{2,}/,
20
+ // Greedy patterns with backreferences
21
+ /\([^)]+\)[+*].*\\[1-9]/,
22
+ ];
23
+ /**
24
+ * Route parameter patterns that may cause issues
25
+ */
26
+ const VULNERABLE_PARAM_PATTERNS = [
27
+ // :param+ or :param* - can match multiple segments
28
+ /:[a-zA-Z_][a-zA-Z0-9_]*\+/,
29
+ /:[a-zA-Z_][a-zA-Z0-9_]*\*/,
30
+ ];
31
+ /**
32
+ * Check if a regex pattern is potentially vulnerable to ReDoS
33
+ */
34
+ function isVulnerableRegex(pattern) {
35
+ return VULNERABLE_PATTERNS.some((regex) => regex.test(pattern));
36
+ }
37
+ /**
38
+ * Check if a route string has vulnerable param patterns
39
+ */
40
+ function hasVulnerableParamPattern(route) {
41
+ return VULNERABLE_PARAM_PATTERNS.some((regex) => regex.test(route));
42
+ }
43
+ exports.noExpressUnsafeRegexRoute = (0, eslint_devkit_1.createRule)({
44
+ name: 'no-express-unsafe-regex-route',
45
+ meta: {
46
+ type: 'problem',
47
+ docs: {
48
+ description: 'Disallow ReDoS-vulnerable regular expressions in Express.js route patterns',
49
+ },
50
+ hasSuggestions: true,
51
+ messages: {
52
+ unsafeRegexRoute: (0, eslint_devkit_1.formatLLMMessage)({
53
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
54
+ issueName: 'ReDoS Vulnerable Route Pattern',
55
+ cwe: 'CWE-1333',
56
+ description: 'Route uses a regular expression vulnerable to Regular Expression Denial of Service (ReDoS). Malicious input can cause catastrophic backtracking.',
57
+ severity: 'HIGH',
58
+ fix: 'Simplify the regex pattern. Avoid nested quantifiers like (a+)+ and overlapping alternatives. Consider using a string route with explicit parameters.',
59
+ documentationLink: 'https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS',
60
+ }),
61
+ unsafeParamPattern: (0, eslint_devkit_1.formatLLMMessage)({
62
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
63
+ issueName: 'Unsafe Route Parameter Pattern',
64
+ cwe: 'CWE-1333',
65
+ description: 'Route parameter uses + or * quantifier which can match multiple path segments, potentially causing ReDoS or unexpected behavior.',
66
+ severity: 'MEDIUM',
67
+ fix: 'Use explicit path segments instead of :param+ or :param*. For example: /api/:id/details instead of /api/:path+',
68
+ documentationLink: 'https://expressjs.com/en/guide/routing.html',
69
+ }),
70
+ refactorRoute: (0, eslint_devkit_1.formatLLMMessage)({
71
+ icon: eslint_devkit_1.MessageIcons.INFO,
72
+ issueName: 'Refactor Route',
73
+ description: 'Refactor to use a simpler, non-vulnerable pattern',
74
+ severity: 'LOW',
75
+ fix: 'Use string routes with explicit path segments',
76
+ documentationLink: 'https://expressjs.com/en/guide/routing.html',
77
+ }),
78
+ },
79
+ schema: [
80
+ {
81
+ type: 'object',
82
+ properties: {
83
+ allowInTests: {
84
+ type: 'boolean',
85
+ default: false,
86
+ description: 'Allow in test files',
87
+ },
88
+ },
89
+ additionalProperties: false,
90
+ },
91
+ ],
92
+ },
93
+ defaultOptions: [{ allowInTests: false }],
94
+ create(context, [options = {}]) {
95
+ const { allowInTests = false } = options;
96
+ const filename = context.filename;
97
+ const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
98
+ if (isTestFile) {
99
+ return {};
100
+ }
101
+ return {
102
+ CallExpression(node) {
103
+ const callee = node.callee;
104
+ // Check for app.get(), router.post(), etc.
105
+ /* c8 ignore next 2 */
106
+ if (callee.type !== 'MemberExpression') {
107
+ return;
108
+ }
109
+ const property = callee.property;
110
+ /* c8 ignore next 2 */
111
+ if (property.type !== 'Identifier') {
112
+ return;
113
+ }
114
+ if (!HTTP_METHODS.includes(property.name)) {
115
+ return;
116
+ }
117
+ // Check the route argument (first argument)
118
+ const routeArg = node.arguments[0];
119
+ /* c8 ignore next 2 */
120
+ if (!routeArg) {
121
+ return;
122
+ }
123
+ // Check regex literal routes (e.g., /pattern/)
124
+ if (routeArg.type === 'Literal' && 'regex' in routeArg && routeArg.regex) {
125
+ const regexNode = routeArg;
126
+ const pattern = regexNode.regex.pattern;
127
+ if (isVulnerableRegex(pattern)) {
128
+ context.report({
129
+ node: routeArg,
130
+ messageId: 'unsafeRegexRoute',
131
+ suggest: [
132
+ {
133
+ messageId: 'refactorRoute',
134
+ fix: () => null, // Manual fix required
135
+ },
136
+ ],
137
+ });
138
+ }
139
+ return;
140
+ }
141
+ // Check new RegExp() routes
142
+ if (routeArg.type === 'NewExpression' &&
143
+ routeArg.callee.type === 'Identifier' &&
144
+ routeArg.callee.name === 'RegExp') {
145
+ const patternArg = routeArg.arguments[0];
146
+ if (patternArg && patternArg.type === 'Literal' && typeof patternArg.value === 'string') {
147
+ if (isVulnerableRegex(patternArg.value)) {
148
+ context.report({
149
+ node: routeArg,
150
+ messageId: 'unsafeRegexRoute',
151
+ suggest: [
152
+ {
153
+ messageId: 'refactorRoute',
154
+ fix: () => null,
155
+ },
156
+ ],
157
+ });
158
+ }
159
+ }
160
+ return;
161
+ }
162
+ // Check string routes with vulnerable param patterns
163
+ if (routeArg.type === 'Literal' && typeof routeArg.value === 'string') {
164
+ if (hasVulnerableParamPattern(routeArg.value)) {
165
+ context.report({
166
+ node: routeArg,
167
+ messageId: 'unsafeParamPattern',
168
+ suggest: [
169
+ {
170
+ messageId: 'refactorRoute',
171
+ fix: () => null,
172
+ },
173
+ ],
174
+ });
175
+ }
176
+ }
177
+ },
178
+ };
179
+ },
180
+ });
181
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-express-security/src/rules/no-express-unsafe-regex-route/index.ts"],"names":[],"mappings":";;;AAYA,4DAIkC;AAWlC;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,mBAAmB,GAAG;IAC1B,mCAAmC;IACnC,wBAAwB;IACxB,mCAAmC;IACnC,sBAAsB;IACtB,qCAAqC;IACrC,UAAU;IACV,sCAAsC;IACtC,wBAAwB;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,yBAAyB,GAAG;IAChC,mDAAmD;IACnD,2BAA2B;IAC3B,2BAA2B;CAC5B,CAAC;AAEF;;GAEG;AACH,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;GAEG;AACH,SAAS,yBAAyB,CAAC,KAAa;IAC9C,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC;AAEY,QAAA,yBAAyB,GAAG,IAAA,0BAAU,EAA0B;IAC3E,IAAI,EAAE,+BAA+B;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,4EAA4E;SAC/E;QACD,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE;YACR,gBAAgB,EAAE,IAAA,gCAAgB,EAAC;gBACjC,IAAI,EAAE,4BAAY,CAAC,QAAQ;gBAC3B,SAAS,EAAE,gCAAgC;gBAC3C,GAAG,EAAE,UAAU;gBACf,WAAW,EACT,kJA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QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,EACjC,CAAC;oBACD,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;oBACzC,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;wBACxF,IAAI,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BACxC,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,QAAQ;gCACd,SAAS,EAAE,kBAAkB;gCAC7B,OAAO,EAAE;oCACP;wCACE,SAAS,EAAE,eAAe;wCAC1B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;qCAChB;iCACF;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,qDAAqD;gBACrD,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACtE,IAAI,yBAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC9C,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,QAAQ;4BACd,SAAS,EAAE,oBAAoB;4BAC/B,OAAO,EAAE;gCACP;oCACE,SAAS,EAAE,eAAe;oCAC1B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;iCAChB;6BACF;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface Options {
2
+ /** Allow introspection in test files. Default: true */
3
+ allowInTests?: boolean;
4
+ /** Allow introspection in development. Default: true */
5
+ allowInDevelopment?: boolean;
6
+ }
7
+ export declare const noGraphqlIntrospectionProduction: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;