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.
- package/AGENTS.md +100 -0
- package/CHANGELOG.md +51 -0
- package/README.md +424 -0
- package/package.json +99 -0
- package/src/index.d.ts +35 -0
- package/src/index.js +144 -0
- package/src/index.js.map +1 -0
- package/src/rules/no-cors-credentials-wildcard/index.d.ts +5 -0
- package/src/rules/no-cors-credentials-wildcard/index.js +142 -0
- package/src/rules/no-cors-credentials-wildcard/index.js.map +1 -0
- package/src/rules/no-express-unsafe-regex-route/index.d.ts +5 -0
- package/src/rules/no-express-unsafe-regex-route/index.js +181 -0
- package/src/rules/no-express-unsafe-regex-route/index.js.map +1 -0
- package/src/rules/no-graphql-introspection-production/index.d.ts +7 -0
- package/src/rules/no-graphql-introspection-production/index.js +161 -0
- package/src/rules/no-graphql-introspection-production/index.js.map +1 -0
- package/src/rules/no-insecure-cookie-options/index.d.ts +13 -0
- package/src/rules/no-insecure-cookie-options/index.js +162 -0
- package/src/rules/no-insecure-cookie-options/index.js.map +1 -0
- package/src/rules/no-permissive-cors/index.d.ts +9 -0
- package/src/rules/no-permissive-cors/index.js +205 -0
- package/src/rules/no-permissive-cors/index.js.map +1 -0
- package/src/rules/require-csrf-protection/index.d.ts +9 -0
- package/src/rules/require-csrf-protection/index.js +240 -0
- package/src/rules/require-csrf-protection/index.js.map +1 -0
- package/src/rules/require-express-body-parser-limits/index.d.ts +9 -0
- package/src/rules/require-express-body-parser-limits/index.js +201 -0
- package/src/rules/require-express-body-parser-limits/index.js.map +1 -0
- package/src/rules/require-helmet/index.d.ts +9 -0
- package/src/rules/require-helmet/index.js +185 -0
- package/src/rules/require-helmet/index.js.map +1 -0
- package/src/rules/require-rate-limiting/index.d.ts +12 -0
- package/src/rules/require-rate-limiting/index.js +142 -0
- package/src/rules/require-rate-limiting/index.js.map +1 -0
- package/src/types/index.d.ts +27 -0
- package/src/types/index.js +3 -0
- package/src/types/index.js.map +1 -0
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Check if introspection is explicitly enabled
|
|
7
|
+
*/
|
|
8
|
+
function hasIntrospectionEnabled(node, sourceCode) {
|
|
9
|
+
const text = sourceCode.getText(node);
|
|
10
|
+
// Check for introspection: true
|
|
11
|
+
if (/\bintrospection\s*:\s*true\b/.test(text)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// Check for no introspection setting (defaults to true in many libraries)
|
|
15
|
+
// We only flag explicit true or missing with warning
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if there's a production guard for introspection
|
|
20
|
+
*/
|
|
21
|
+
function hasProductionGuard(node, sourceCode) {
|
|
22
|
+
const text = sourceCode.getText(node);
|
|
23
|
+
// Check for common production guards
|
|
24
|
+
const productionGuards = [
|
|
25
|
+
/introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]production['"]/,
|
|
26
|
+
/introspection\s*:\s*!?\s*isProd/,
|
|
27
|
+
/introspection\s*:\s*!?\s*isProduction/,
|
|
28
|
+
/introspection\s*:\s*process\.env\.NODE_ENV\s*[!=]==?\s*['"]development['"]/,
|
|
29
|
+
];
|
|
30
|
+
return productionGuards.some((guard) => guard.test(text));
|
|
31
|
+
}
|
|
32
|
+
exports.noGraphqlIntrospectionProduction = (0, eslint_devkit_1.createRule)({
|
|
33
|
+
name: 'no-graphql-introspection-production',
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
docs: {
|
|
37
|
+
description: 'Disallow GraphQL introspection in production environments',
|
|
38
|
+
},
|
|
39
|
+
hasSuggestions: true,
|
|
40
|
+
messages: {
|
|
41
|
+
graphqlIntrospection: (0, eslint_devkit_1.formatLLMMessage)({
|
|
42
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
43
|
+
issueName: 'GraphQL Introspection Enabled',
|
|
44
|
+
cwe: 'CWE-200',
|
|
45
|
+
description: 'GraphQL introspection is enabled. In production, this exposes your entire API schema to attackers.',
|
|
46
|
+
severity: 'MEDIUM',
|
|
47
|
+
fix: "Set introspection: process.env.NODE_ENV !== 'production' or introspection: false",
|
|
48
|
+
documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/GraphQL_Cheat_Sheet.html#introspection-graphiql',
|
|
49
|
+
}),
|
|
50
|
+
disableIntrospection: (0, eslint_devkit_1.formatLLMMessage)({
|
|
51
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
52
|
+
issueName: 'Disable Introspection in Production',
|
|
53
|
+
description: 'Disable GraphQL introspection for production',
|
|
54
|
+
severity: 'LOW',
|
|
55
|
+
fix: "introspection: process.env.NODE_ENV !== 'production'",
|
|
56
|
+
documentationLink: 'https://www.apollographql.com/docs/apollo-server/api/apollo-server/#introspection',
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
schema: [
|
|
60
|
+
{
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
allowInTests: {
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
default: true,
|
|
66
|
+
},
|
|
67
|
+
allowInDevelopment: {
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
default: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
defaultOptions: [
|
|
77
|
+
{
|
|
78
|
+
allowInTests: true,
|
|
79
|
+
allowInDevelopment: true,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
create(context, [options = {}]) {
|
|
83
|
+
const { allowInTests = true } = options;
|
|
84
|
+
const filename = context.filename;
|
|
85
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
86
|
+
if (isTestFile) {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
const sourceCode = context.sourceCode;
|
|
90
|
+
return {
|
|
91
|
+
CallExpression(node) {
|
|
92
|
+
const callee = node.callee;
|
|
93
|
+
// Check for Apollo Server, Express-GraphQL, or similar
|
|
94
|
+
const isGraphQLServer = (callee.type === 'Identifier' &&
|
|
95
|
+
['ApolloServer', 'GraphQLServer', 'createServer'].includes(callee.name)) ||
|
|
96
|
+
(callee.type === 'NewExpression' &&
|
|
97
|
+
callee.callee.type === 'Identifier' &&
|
|
98
|
+
['ApolloServer', 'GraphQLServer'].includes(callee.callee.name));
|
|
99
|
+
// Also check for graphqlHTTP (express-graphql)
|
|
100
|
+
const isExpressGraphQL = callee.type === 'Identifier' && callee.name === 'graphqlHTTP';
|
|
101
|
+
if (!isGraphQLServer && !isExpressGraphQL) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Get the options/config argument
|
|
105
|
+
const configArg = node.arguments[0];
|
|
106
|
+
/* c8 ignore next 2 */
|
|
107
|
+
if (!configArg || configArg.type !== 'ObjectExpression') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Check if there's a production guard
|
|
111
|
+
/* c8 ignore next 2 */
|
|
112
|
+
if (hasProductionGuard(configArg, sourceCode)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Check if introspection is explicitly enabled
|
|
116
|
+
if (hasIntrospectionEnabled(configArg, sourceCode)) {
|
|
117
|
+
context.report({
|
|
118
|
+
node: configArg,
|
|
119
|
+
messageId: 'graphqlIntrospection',
|
|
120
|
+
suggest: [
|
|
121
|
+
{
|
|
122
|
+
messageId: 'disableIntrospection',
|
|
123
|
+
fix: () => null,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
// Also check NewExpression for new ApolloServer({...})
|
|
130
|
+
NewExpression(node) {
|
|
131
|
+
const callee = node.callee;
|
|
132
|
+
/* c8 ignore next 2 */
|
|
133
|
+
if (callee.type !== 'Identifier' ||
|
|
134
|
+
!['ApolloServer', 'GraphQLServer'].includes(callee.name)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const configArg = node.arguments[0];
|
|
138
|
+
/* c8 ignore next 2 */
|
|
139
|
+
if (!configArg || configArg.type !== 'ObjectExpression') {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (hasProductionGuard(configArg, sourceCode)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (hasIntrospectionEnabled(configArg, sourceCode)) {
|
|
146
|
+
context.report({
|
|
147
|
+
node: configArg,
|
|
148
|
+
messageId: 'graphqlIntrospection',
|
|
149
|
+
suggest: [
|
|
150
|
+
{
|
|
151
|
+
messageId: 'disableIntrospection',
|
|
152
|
+
fix: () => null,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-express-security/src/rules/no-graphql-introspection-production/index.ts"],"names":[],"mappings":";;;AASA,4DAIkC;AAclC;;GAEG;AACH,SAAS,uBAAuB,CAC9B,IAA+B,EAC/B,UAA+B;IAE/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC,gCAAgC;IAChC,IAAI,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0EAA0E;IAC1E,qDAAqD;IACrD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;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C,MAAM,CAAC;wBACb,IAAI,EAAE,SAAS;wBACf,SAAS,EAAE,sBAAsB;wBACjC,OAAO,EAAE;4BACP;gCACE,SAAS,EAAE,sBAAsB;gCACjC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;6BAChB;yBACF;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow insecure cookies in test files. Default: false */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Require httpOnly flag. Default: true */
|
|
5
|
+
requireHttpOnly?: boolean;
|
|
6
|
+
/** Require secure flag. Default: true */
|
|
7
|
+
requireSecure?: boolean;
|
|
8
|
+
/** Require sameSite flag. Default: true */
|
|
9
|
+
requireSameSite?: boolean;
|
|
10
|
+
/** Acceptable sameSite values. Default: ['strict', 'lax'] */
|
|
11
|
+
acceptableSameSiteValues?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare const noInsecureCookieOptions: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noInsecureCookieOptions = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
/**
|
|
6
|
+
* Check cookie options object for security flags
|
|
7
|
+
*/
|
|
8
|
+
function checkCookieOptions(node, sourceCode, options) {
|
|
9
|
+
const text = sourceCode.getText(node);
|
|
10
|
+
const issues = [];
|
|
11
|
+
if (options.requireHttpOnly !== false) {
|
|
12
|
+
const hasHttpOnly = /\bhttpOnly\s*:\s*true\b/i.test(text);
|
|
13
|
+
if (!hasHttpOnly) {
|
|
14
|
+
issues.push('missing httpOnly flag (prevents XSS access to cookie)');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (options.requireSecure !== false) {
|
|
18
|
+
const hasSecure = /\bsecure\s*:\s*true\b/i.test(text);
|
|
19
|
+
if (!hasSecure) {
|
|
20
|
+
issues.push('missing secure flag (cookie sent over HTTPS only)');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (options.requireSameSite !== false) {
|
|
24
|
+
const acceptableValues = options.acceptableSameSiteValues || ['strict', 'lax'];
|
|
25
|
+
const sameSiteMatch = text.match(/\bsameSite\s*:\s*['"](\w+)['"]/i);
|
|
26
|
+
if (!sameSiteMatch) {
|
|
27
|
+
issues.push('missing sameSite flag (prevents CSRF)');
|
|
28
|
+
}
|
|
29
|
+
else if (!acceptableValues.includes(sameSiteMatch[1].toLowerCase())) {
|
|
30
|
+
issues.push(`sameSite should be 'strict' or 'lax', not '${sameSiteMatch[1]}'`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { issues, hasSuggestions: issues.length > 0 };
|
|
34
|
+
}
|
|
35
|
+
exports.noInsecureCookieOptions = (0, eslint_devkit_1.createRule)({
|
|
36
|
+
name: 'no-insecure-cookie-options',
|
|
37
|
+
meta: {
|
|
38
|
+
type: 'problem',
|
|
39
|
+
docs: {
|
|
40
|
+
description: 'Require secure cookie flags (httpOnly, secure, sameSite) in Express.js',
|
|
41
|
+
},
|
|
42
|
+
hasSuggestions: true,
|
|
43
|
+
messages: {
|
|
44
|
+
insecureCookie: (0, eslint_devkit_1.formatLLMMessage)({
|
|
45
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
46
|
+
issueName: 'Insecure Cookie Configuration',
|
|
47
|
+
cwe: 'CWE-614',
|
|
48
|
+
description: '{{issues}}',
|
|
49
|
+
severity: 'HIGH',
|
|
50
|
+
fix: 'Set httpOnly: true, secure: true, sameSite: "strict"',
|
|
51
|
+
documentationLink: 'https://owasp.org/www-community/controls/SecureCookieAttribute',
|
|
52
|
+
}),
|
|
53
|
+
addSecureFlags: (0, eslint_devkit_1.formatLLMMessage)({
|
|
54
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
55
|
+
issueName: 'Add Secure Cookie Flags',
|
|
56
|
+
description: 'Add missing security flags to cookie options',
|
|
57
|
+
severity: 'LOW',
|
|
58
|
+
fix: '{ httpOnly: true, secure: true, sameSite: "strict" }',
|
|
59
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
schema: [
|
|
63
|
+
{
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
allowInTests: {
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
default: false,
|
|
69
|
+
},
|
|
70
|
+
requireHttpOnly: {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
default: true,
|
|
73
|
+
},
|
|
74
|
+
requireSecure: {
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
default: true,
|
|
77
|
+
},
|
|
78
|
+
requireSameSite: {
|
|
79
|
+
type: 'boolean',
|
|
80
|
+
default: true,
|
|
81
|
+
},
|
|
82
|
+
acceptableSameSiteValues: {
|
|
83
|
+
type: 'array',
|
|
84
|
+
items: { type: 'string' },
|
|
85
|
+
default: ['strict', 'lax'],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
defaultOptions: [
|
|
93
|
+
{
|
|
94
|
+
allowInTests: false,
|
|
95
|
+
requireHttpOnly: true,
|
|
96
|
+
requireSecure: true,
|
|
97
|
+
requireSameSite: true,
|
|
98
|
+
acceptableSameSiteValues: ['strict', 'lax'],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
create(context, [options = {}]) {
|
|
102
|
+
const { allowInTests = false } = options;
|
|
103
|
+
const filename = context.filename;
|
|
104
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
105
|
+
if (isTestFile) {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
const sourceCode = context.sourceCode;
|
|
109
|
+
return {
|
|
110
|
+
CallExpression(node) {
|
|
111
|
+
const callee = node.callee;
|
|
112
|
+
// Check for res.cookie() calls
|
|
113
|
+
if (callee.type === 'MemberExpression' &&
|
|
114
|
+
callee.property.type === 'Identifier' &&
|
|
115
|
+
callee.property.name === 'cookie') {
|
|
116
|
+
// res.cookie(name, value, options)
|
|
117
|
+
const optionsArg = node.arguments[2];
|
|
118
|
+
// No options provided
|
|
119
|
+
if (!optionsArg) {
|
|
120
|
+
context.report({
|
|
121
|
+
node,
|
|
122
|
+
messageId: 'insecureCookie',
|
|
123
|
+
data: {
|
|
124
|
+
issues: 'Cookie set without options - missing httpOnly, secure, sameSite flags',
|
|
125
|
+
},
|
|
126
|
+
suggest: [
|
|
127
|
+
{
|
|
128
|
+
messageId: 'addSecureFlags',
|
|
129
|
+
fix: (fixer) => {
|
|
130
|
+
const lastArg = node.arguments[node.arguments.length - 1];
|
|
131
|
+
return fixer.insertTextAfter(lastArg, ', { httpOnly: true, secure: true, sameSite: "strict" }');
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// Options is an object expression
|
|
139
|
+
if (optionsArg.type === 'ObjectExpression') {
|
|
140
|
+
const { issues } = checkCookieOptions(optionsArg, sourceCode, options);
|
|
141
|
+
if (issues.length > 0) {
|
|
142
|
+
context.report({
|
|
143
|
+
node: optionsArg,
|
|
144
|
+
messageId: 'insecureCookie',
|
|
145
|
+
data: {
|
|
146
|
+
issues: issues.join('; '),
|
|
147
|
+
},
|
|
148
|
+
suggest: [
|
|
149
|
+
{
|
|
150
|
+
messageId: 'addSecureFlags',
|
|
151
|
+
fix: () => null,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-express-security/src/rules/no-insecure-cookie-options/index.ts"],"names":[],"mappings":";;;AASA,4DAIkC;AAuBlC;;GAEG;AACH,SAAS,kBAAkB,CACzB,IAA+B,EAC/B,UAA+B,EAC/B,OAAgB;IAEhB,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,aAAa,KAAK,KAAK,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACtC,MAAM,gBAAgB,GAAG,OAAO,CAAC,wBAAwB,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/E,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACpE,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACvD,CAAC;aAAM,IAAI,CAAC,gBAAgB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AU,EAAE,CAAC;wBAChB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,gBAAgB;4BAC3B,IAAI,EAAE;gCACJ,MAAM,EACJ,uEAAuE;6BAC1E;4BACD,OAAO,EAAE;gCACP;oCACE,SAAS,EAAE,gBAAgB;oCAC3B,GAAG,EAAE,CAAC,KAAyB,EAAE,EAAE;wCACjC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;wCAC1D,OAAO,KAAK,CAAC,eAAe,CAC1B,OAAO,EACP,wDAAwD,CACzD,CAAC;oCACJ,CAAC;iCACF;6BACF;yBACF,CAAC,CAAC;wBACH,OAAO;oBACT,CAAC;oBAED,kCAAkC;oBAClC,IAAI,UAAU,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;wBAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAkB,CACnC,UAAU,EACV,UAAU,EACV,OAAkB,CACnB,CAAC;wBAEF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BACtB,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,UAAU;gCAChB,SAAS,EAAE,gBAAgB;gCAC3B,IAAI,EAAE;oCACJ,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;iCAC1B;gCACD,OAAO,EAAE;oCACP;wCACE,SAAS,EAAE,gBAAgB;wCAC3B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;qCAChB;iCACF;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow permissive CORS in test files. Default: false */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** Allow origin: true for development. Default: false */
|
|
5
|
+
allowOriginTrue?: boolean;
|
|
6
|
+
/** Allowed origins that should not trigger warnings. Default: [] */
|
|
7
|
+
allowedOrigins?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const noPermissiveCors: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Check if node is a CORS configuration with wildcard or overly permissive origin
|
|
7
|
+
*/
|
|
8
|
+
function isPermissiveCorsConfig(node, sourceCode, options) {
|
|
9
|
+
const text = sourceCode.getText(node);
|
|
10
|
+
// Check for origin: '*'
|
|
11
|
+
if (/\borigin\s*:\s*['"`]\*['"`]/.test(text)) {
|
|
12
|
+
return {
|
|
13
|
+
isPermissive: true,
|
|
14
|
+
reason: "origin: '*' allows any domain to access your API",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// Check for origin: true (reflects request origin)
|
|
18
|
+
if (!options.allowOriginTrue && /\borigin\s*:\s*true\b/.test(text)) {
|
|
19
|
+
return {
|
|
20
|
+
isPermissive: true,
|
|
21
|
+
reason: 'origin: true reflects the request origin, allowing any domain',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Check for credentials: true with permissive origin
|
|
25
|
+
if (/\bcredentials\s*:\s*true\b/.test(text)) {
|
|
26
|
+
// If credentials are enabled, origin cannot be '*' (browser blocks this)
|
|
27
|
+
// but origin: true with credentials is dangerous
|
|
28
|
+
/* c8 ignore next 7 */
|
|
29
|
+
if (/\borigin\s*:\s*true\b/.test(text)) {
|
|
30
|
+
return {
|
|
31
|
+
isPermissive: true,
|
|
32
|
+
reason: 'origin: true with credentials: true allows credential leakage to any domain',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { isPermissive: false, reason: '' };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if this is a standalone cors() call (not inside app.use)
|
|
40
|
+
*/
|
|
41
|
+
function isStandaloneCorsCall(node) {
|
|
42
|
+
const callee = node.callee;
|
|
43
|
+
// cors() or cors({...})
|
|
44
|
+
if (callee.type === 'Identifier' && callee.name === 'cors') {
|
|
45
|
+
// Check if parent is app.use() - if so, skip (handled by isAppUseCors)
|
|
46
|
+
const parent = node.parent;
|
|
47
|
+
if (parent &&
|
|
48
|
+
parent.type === 'CallExpression' &&
|
|
49
|
+
parent.callee.type === 'MemberExpression' &&
|
|
50
|
+
parent.callee.property.type === 'Identifier' &&
|
|
51
|
+
parent.callee.property.name === 'use') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if this is app.use(cors(...))
|
|
60
|
+
*/
|
|
61
|
+
function isAppUseCors(node) {
|
|
62
|
+
const callee = node.callee;
|
|
63
|
+
if (callee.type === 'MemberExpression' &&
|
|
64
|
+
callee.property.type === 'Identifier' &&
|
|
65
|
+
callee.property.name === 'use') {
|
|
66
|
+
// Check if first argument is cors() call
|
|
67
|
+
const firstArg = node.arguments[0];
|
|
68
|
+
if (firstArg &&
|
|
69
|
+
firstArg.type === 'CallExpression' &&
|
|
70
|
+
firstArg.callee.type === 'Identifier' &&
|
|
71
|
+
firstArg.callee.name === 'cors') {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
|
|
78
|
+
name: 'no-permissive-cors',
|
|
79
|
+
meta: {
|
|
80
|
+
type: 'problem',
|
|
81
|
+
docs: {
|
|
82
|
+
description: 'Disallow overly permissive CORS configurations (wildcard origin, origin: true)',
|
|
83
|
+
},
|
|
84
|
+
hasSuggestions: true,
|
|
85
|
+
messages: {
|
|
86
|
+
permissiveCors: (0, eslint_devkit_1.formatLLMMessage)({
|
|
87
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
88
|
+
issueName: 'Permissive CORS Configuration',
|
|
89
|
+
cwe: 'CWE-942',
|
|
90
|
+
description: '{{reason}}',
|
|
91
|
+
severity: 'HIGH',
|
|
92
|
+
fix: 'Specify an explicit whitelist of allowed origins: origin: ["https://trusted-domain.com"]',
|
|
93
|
+
documentationLink: 'https://owasp.org/www-community/attacks/CORS_OriginHeaderScrutiny',
|
|
94
|
+
}),
|
|
95
|
+
useWhitelist: (0, eslint_devkit_1.formatLLMMessage)({
|
|
96
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
97
|
+
issueName: 'Use Origin Whitelist',
|
|
98
|
+
description: 'Replace with explicit origin whitelist',
|
|
99
|
+
severity: 'LOW',
|
|
100
|
+
fix: 'origin: ["https://your-frontend.com", "https://app.your-domain.com"]',
|
|
101
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS',
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
schema: [
|
|
105
|
+
{
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
allowInTests: {
|
|
109
|
+
type: 'boolean',
|
|
110
|
+
default: false,
|
|
111
|
+
description: 'Allow permissive CORS in test files',
|
|
112
|
+
},
|
|
113
|
+
allowOriginTrue: {
|
|
114
|
+
type: 'boolean',
|
|
115
|
+
default: false,
|
|
116
|
+
description: 'Allow origin: true for development',
|
|
117
|
+
},
|
|
118
|
+
allowedOrigins: {
|
|
119
|
+
type: 'array',
|
|
120
|
+
items: { type: 'string' },
|
|
121
|
+
default: [],
|
|
122
|
+
description: 'Allowed origins that should not trigger warnings',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
defaultOptions: [
|
|
130
|
+
{
|
|
131
|
+
allowInTests: false,
|
|
132
|
+
allowOriginTrue: false,
|
|
133
|
+
allowedOrigins: [],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
create(context, [options = {}]) {
|
|
137
|
+
const { allowInTests = false, allowOriginTrue = false, } = options;
|
|
138
|
+
const filename = context.filename;
|
|
139
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
140
|
+
if (isTestFile) {
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
const sourceCode = context.sourceCode;
|
|
144
|
+
return {
|
|
145
|
+
CallExpression(node) {
|
|
146
|
+
// Check for cors({...}) call
|
|
147
|
+
if (isStandaloneCorsCall(node) || isAppUseCors(node)) {
|
|
148
|
+
let corsConfigNode = null;
|
|
149
|
+
// Get the config object
|
|
150
|
+
if (isStandaloneCorsCall(node) && node.arguments[0]?.type === 'ObjectExpression') {
|
|
151
|
+
corsConfigNode = node.arguments[0];
|
|
152
|
+
}
|
|
153
|
+
else if (isAppUseCors(node)) {
|
|
154
|
+
const corsCall = node.arguments[0];
|
|
155
|
+
if (corsCall.arguments[0]?.type === 'ObjectExpression') {
|
|
156
|
+
corsConfigNode = corsCall.arguments[0];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Check for cors() with no arguments - defaults to permissive
|
|
160
|
+
// Handle both standalone cors() and app.use(cors())
|
|
161
|
+
let corsCallNode = null;
|
|
162
|
+
if (isStandaloneCorsCall(node)) {
|
|
163
|
+
corsCallNode = node;
|
|
164
|
+
}
|
|
165
|
+
else if (isAppUseCors(node)) {
|
|
166
|
+
corsCallNode = node.arguments[0];
|
|
167
|
+
}
|
|
168
|
+
if (corsCallNode && corsCallNode.arguments.length === 0) {
|
|
169
|
+
context.report({
|
|
170
|
+
node: corsCallNode,
|
|
171
|
+
messageId: 'permissiveCors',
|
|
172
|
+
data: {
|
|
173
|
+
reason: 'cors() with no options uses permissive defaults',
|
|
174
|
+
},
|
|
175
|
+
suggest: [
|
|
176
|
+
{
|
|
177
|
+
messageId: 'useWhitelist',
|
|
178
|
+
fix: () => null,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (corsConfigNode) {
|
|
185
|
+
const { isPermissive, reason } = isPermissiveCorsConfig(corsConfigNode, sourceCode, { allowOriginTrue });
|
|
186
|
+
if (isPermissive) {
|
|
187
|
+
context.report({
|
|
188
|
+
node: corsConfigNode,
|
|
189
|
+
messageId: 'permissiveCors',
|
|
190
|
+
data: { reason },
|
|
191
|
+
suggest: [
|
|
192
|
+
{
|
|
193
|
+
messageId: 'useWhitelist',
|
|
194
|
+
fix: () => null,
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-express-security/src/rules/no-permissive-cors/index.ts"],"names":[],"mappings":";;;AASA,4DAIkC;AAiBlC;;GAEG;AACH,SAAS,sBAAsB,CAC7B,IAA+B,EAC/B,UAA+B,EAC/B,OAAgB;IAEhB,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC,wBAAwB;IACxB,IAAI,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,OAAO;YACL,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,kDAAkD;SAC3D,CAAC;IACJ,CAAC;IAED,mDAAmD;IACnD,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,C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,EAAE,MAAM,EAAE;gCAChB,OAAO,EAAE;oCACP;wCACE,SAAS,EAAE,cAAc;wCACzB,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;qCAChB;iCACF;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** Allow missing CSRF in test files. Default: false */
|
|
3
|
+
allowInTests?: boolean;
|
|
4
|
+
/** HTTP methods that require CSRF protection. Default: ['post', 'put', 'patch', 'delete'] */
|
|
5
|
+
protectedMethods?: string[];
|
|
6
|
+
/** Route patterns to ignore (e.g., /api/webhook). Default: [] */
|
|
7
|
+
ignorePatterns?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const requireCsrfProtection: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|