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.
- package/package.json +2 -2
- package/src/index.js +1 -113
- package/src/oxlint.js +1 -3
- package/src/rules/no-client-controlled-authorization/index.js +1 -194
- package/src/rules/no-cors-credentials-wildcard/index.js +1 -127
- package/src/rules/no-disabled-helmet-protections/index.js +1 -125
- package/src/rules/no-error-details-in-response/index.js +1 -176
- package/src/rules/no-exposed-debug-endpoints/index.js +1 -96
- package/src/rules/no-express-unsafe-regex-route/index.js +1 -154
- package/src/rules/no-graphql-introspection-production/index.js +1 -143
- package/src/rules/no-host-header-in-links/index.js +1 -235
- package/src/rules/no-idor-resource-access/index.js +1 -126
- package/src/rules/no-insecure-cookie-options/index.js +1 -158
- package/src/rules/no-missing-cors-check/index.js +1 -351
- package/src/rules/no-missing-csrf-protection/index.js +1 -161
- package/src/rules/no-missing-security-headers/index.js +1 -206
- package/src/rules/no-permissive-cors/index.js +1 -185
- package/src/rules/no-permissive-trust-proxy/index.js +1 -106
- package/src/rules/no-sensitive-data-in-query/index.js +1 -182
- package/src/rules/no-static-root-exposure/index.js +1 -267
- package/src/rules/no-unsafe-csp-directives/index.js +1 -264
- package/src/rules/no-user-controlled-redirect/index.js +1 -117
- package/src/rules/no-user-controlled-render-locals/index.js +1 -268
- package/src/rules/require-case-insensitive-path-guard/index.js +1 -180
- package/src/rules/require-csrf-protection/index.js +1 -201
- package/src/rules/require-express-body-parser-limits/index.js +1 -181
- package/src/rules/require-helmet/index.js +1 -166
- package/src/rules/require-query-type-guard/index.js +1 -258
- package/src/rules/require-rate-limiting/index.js +1 -136
- package/src/rules/require-route-authentication/index.js +1 -225
- package/src/rules/require-strict-transport-security/index.js +1 -171
- package/src/types/index.js +1 -2
- package/src/utils/index.js +1 -81
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-express-security",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "ESLint plugin for Express.js security — detects permissive CORS, missing CSRF protection, missing helmet headers, insecure cookies, and GraphQL introspection in production.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"node": ">=18.0.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@interlace/eslint-devkit": "^1.
|
|
79
|
+
"@interlace/eslint-devkit": "^1.10.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
package/src/index.js
CHANGED
|
@@ -1,113 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configs = exports.plugin = exports.rules = void 0;
|
|
4
|
-
exports.rules = {
|
|
5
|
-
get 'require-helmet'() { return require("./rules/require-helmet").requireHelmet; },
|
|
6
|
-
get 'no-permissive-cors'() { return require("./rules/no-permissive-cors").noPermissiveCors; },
|
|
7
|
-
get 'require-csrf-protection'() { return require("./rules/require-csrf-protection").requireCsrfProtection; },
|
|
8
|
-
get 'no-insecure-cookie-options'() { return require("./rules/no-insecure-cookie-options").noInsecureCookieOptions; },
|
|
9
|
-
get 'require-rate-limiting'() { return require("./rules/require-rate-limiting").requireRateLimiting; },
|
|
10
|
-
get 'no-graphql-introspection-production'() { return require("./rules/no-graphql-introspection-production").noGraphqlIntrospectionProduction; },
|
|
11
|
-
get 'no-cors-credentials-wildcard'() { return require("./rules/no-cors-credentials-wildcard").noCorsCredentialsWildcard; },
|
|
12
|
-
get 'require-express-body-parser-limits'() { return require("./rules/require-express-body-parser-limits").requireExpressBodyParserLimits; },
|
|
13
|
-
get 'no-express-unsafe-regex-route'() { return require("./rules/no-express-unsafe-regex-route").noExpressUnsafeRegexRoute; },
|
|
14
|
-
get 'no-exposed-debug-endpoints'() { return require("./rules/no-exposed-debug-endpoints").noExposedDebugEndpoints; },
|
|
15
|
-
get 'no-missing-cors-check'() { return require("./rules/no-missing-cors-check").noMissingCorsCheck; },
|
|
16
|
-
get 'no-missing-csrf-protection'() { return require("./rules/no-missing-csrf-protection").noMissingCsrfProtection; },
|
|
17
|
-
get 'no-missing-security-headers'() { return require("./rules/no-missing-security-headers").noMissingSecurityHeaders; },
|
|
18
|
-
get 'no-user-controlled-redirect'() { return require("./rules/no-user-controlled-redirect").noUserControlledRedirect; },
|
|
19
|
-
get 'no-host-header-in-links'() { return require("./rules/no-host-header-in-links").noHostHeaderInLinks; },
|
|
20
|
-
get 'no-error-details-in-response'() { return require("./rules/no-error-details-in-response").noErrorDetailsInResponse; },
|
|
21
|
-
get 'no-sensitive-data-in-query'() { return require("./rules/no-sensitive-data-in-query").noSensitiveDataInQuery; },
|
|
22
|
-
get 'no-user-controlled-render-locals'() { return require("./rules/no-user-controlled-render-locals").noUserControlledRenderLocals; },
|
|
23
|
-
get 'no-static-root-exposure'() { return require("./rules/no-static-root-exposure").noStaticRootExposure; },
|
|
24
|
-
get 'require-case-insensitive-path-guard'() { return require("./rules/require-case-insensitive-path-guard").requireCaseInsensitivePathGuard; },
|
|
25
|
-
get 'require-query-type-guard'() { return require("./rules/require-query-type-guard").requireQueryTypeGuard; },
|
|
26
|
-
get 'no-disabled-helmet-protections'() { return require("./rules/no-disabled-helmet-protections").noDisabledHelmetProtections; },
|
|
27
|
-
get 'require-strict-transport-security'() { return require("./rules/require-strict-transport-security").requireStrictTransportSecurity; },
|
|
28
|
-
get 'no-unsafe-csp-directives'() { return require("./rules/no-unsafe-csp-directives").noUnsafeCspDirectives; },
|
|
29
|
-
get 'no-permissive-trust-proxy'() { return require("./rules/no-permissive-trust-proxy").noPermissiveTrustProxy; },
|
|
30
|
-
get 'require-route-authentication'() { return require("./rules/require-route-authentication").requireRouteAuthentication; },
|
|
31
|
-
get 'no-client-controlled-authorization'() { return require("./rules/no-client-controlled-authorization").noClientControlledAuthorization; },
|
|
32
|
-
get 'no-idor-resource-access'() { return require("./rules/no-idor-resource-access").noIdorResourceAccess; },
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
exports.plugin = {
|
|
36
|
-
meta: {
|
|
37
|
-
name: 'eslint-plugin-express-security',
|
|
38
|
-
version: '1.5.4',
|
|
39
|
-
},
|
|
40
|
-
rules: exports.rules,
|
|
41
|
-
};
|
|
42
|
-
const recommendedRules = {
|
|
43
|
-
'express-security/require-helmet': 'error',
|
|
44
|
-
'express-security/no-permissive-cors': 'error',
|
|
45
|
-
'express-security/require-csrf-protection': 'warn',
|
|
46
|
-
'express-security/no-insecure-cookie-options': 'error',
|
|
47
|
-
'express-security/require-rate-limiting': 'warn',
|
|
48
|
-
'express-security/no-graphql-introspection-production': 'warn',
|
|
49
|
-
'express-security/no-cors-credentials-wildcard': 'error',
|
|
50
|
-
'express-security/require-express-body-parser-limits': 'warn',
|
|
51
|
-
'express-security/no-express-unsafe-regex-route': 'error',
|
|
52
|
-
'express-security/no-exposed-debug-endpoints': 'error',
|
|
53
|
-
'express-security/no-missing-cors-check': 'warn',
|
|
54
|
-
'express-security/no-missing-csrf-protection': 'warn',
|
|
55
|
-
'express-security/no-missing-security-headers': 'warn',
|
|
56
|
-
'express-security/no-user-controlled-redirect': 'error',
|
|
57
|
-
'express-security/no-host-header-in-links': 'error',
|
|
58
|
-
'express-security/no-error-details-in-response': 'error',
|
|
59
|
-
'express-security/no-sensitive-data-in-query': 'warn',
|
|
60
|
-
'express-security/no-user-controlled-render-locals': 'error',
|
|
61
|
-
'express-security/no-static-root-exposure': 'error',
|
|
62
|
-
'express-security/require-case-insensitive-path-guard': 'warn',
|
|
63
|
-
'express-security/require-query-type-guard': 'warn',
|
|
64
|
-
'express-security/no-disabled-helmet-protections': 'error',
|
|
65
|
-
'express-security/require-strict-transport-security': 'error',
|
|
66
|
-
'express-security/no-unsafe-csp-directives': 'error',
|
|
67
|
-
'express-security/no-permissive-trust-proxy': 'error',
|
|
68
|
-
'express-security/require-route-authentication': 'warn',
|
|
69
|
-
'express-security/no-client-controlled-authorization': 'warn',
|
|
70
|
-
'express-security/no-idor-resource-access': 'warn',
|
|
71
|
-
};
|
|
72
|
-
exports.configs = {
|
|
73
|
-
recommended: {
|
|
74
|
-
plugins: {
|
|
75
|
-
'express-security': exports.plugin,
|
|
76
|
-
},
|
|
77
|
-
rules: recommendedRules,
|
|
78
|
-
},
|
|
79
|
-
strict: {
|
|
80
|
-
plugins: {
|
|
81
|
-
'express-security': exports.plugin,
|
|
82
|
-
},
|
|
83
|
-
rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [
|
|
84
|
-
`express-security/${ruleName}`,
|
|
85
|
-
'error',
|
|
86
|
-
])),
|
|
87
|
-
},
|
|
88
|
-
api: {
|
|
89
|
-
plugins: {
|
|
90
|
-
'express-security': exports.plugin,
|
|
91
|
-
},
|
|
92
|
-
rules: {
|
|
93
|
-
'express-security/require-helmet': 'error',
|
|
94
|
-
'express-security/no-disabled-helmet-protections': 'error',
|
|
95
|
-
'express-security/require-strict-transport-security': 'error',
|
|
96
|
-
'express-security/no-unsafe-csp-directives': 'error',
|
|
97
|
-
'express-security/no-permissive-trust-proxy': 'error',
|
|
98
|
-
'express-security/no-permissive-cors': 'error',
|
|
99
|
-
'express-security/require-csrf-protection': 'error',
|
|
100
|
-
'express-security/no-insecure-cookie-options': 'error',
|
|
101
|
-
'express-security/require-rate-limiting': 'error',
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
graphql: {
|
|
105
|
-
plugins: {
|
|
106
|
-
'express-security': exports.plugin,
|
|
107
|
-
},
|
|
108
|
-
rules: {
|
|
109
|
-
'express-security/no-graphql-introspection-production': 'error',
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
exports.default = exports.plugin;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.configs=exports.plugin=exports.rules=void 0;exports.rules={get"require-helmet"(){return require("./rules/require-helmet").requireHelmet},get"no-permissive-cors"(){return require("./rules/no-permissive-cors").noPermissiveCors},get"require-csrf-protection"(){return require("./rules/require-csrf-protection").requireCsrfProtection},get"no-insecure-cookie-options"(){return require("./rules/no-insecure-cookie-options").noInsecureCookieOptions},get"require-rate-limiting"(){return require("./rules/require-rate-limiting").requireRateLimiting},get"no-graphql-introspection-production"(){return require("./rules/no-graphql-introspection-production").noGraphqlIntrospectionProduction},get"no-cors-credentials-wildcard"(){return require("./rules/no-cors-credentials-wildcard").noCorsCredentialsWildcard},get"require-express-body-parser-limits"(){return require("./rules/require-express-body-parser-limits").requireExpressBodyParserLimits},get"no-express-unsafe-regex-route"(){return require("./rules/no-express-unsafe-regex-route").noExpressUnsafeRegexRoute},get"no-exposed-debug-endpoints"(){return require("./rules/no-exposed-debug-endpoints").noExposedDebugEndpoints},get"no-missing-cors-check"(){return require("./rules/no-missing-cors-check").noMissingCorsCheck},get"no-missing-csrf-protection"(){return require("./rules/no-missing-csrf-protection").noMissingCsrfProtection},get"no-missing-security-headers"(){return require("./rules/no-missing-security-headers").noMissingSecurityHeaders},get"no-user-controlled-redirect"(){return require("./rules/no-user-controlled-redirect").noUserControlledRedirect},get"no-host-header-in-links"(){return require("./rules/no-host-header-in-links").noHostHeaderInLinks},get"no-error-details-in-response"(){return require("./rules/no-error-details-in-response").noErrorDetailsInResponse},get"no-sensitive-data-in-query"(){return require("./rules/no-sensitive-data-in-query").noSensitiveDataInQuery},get"no-user-controlled-render-locals"(){return require("./rules/no-user-controlled-render-locals").noUserControlledRenderLocals},get"no-static-root-exposure"(){return require("./rules/no-static-root-exposure").noStaticRootExposure},get"require-case-insensitive-path-guard"(){return require("./rules/require-case-insensitive-path-guard").requireCaseInsensitivePathGuard},get"require-query-type-guard"(){return require("./rules/require-query-type-guard").requireQueryTypeGuard},get"no-disabled-helmet-protections"(){return require("./rules/no-disabled-helmet-protections").noDisabledHelmetProtections},get"require-strict-transport-security"(){return require("./rules/require-strict-transport-security").requireStrictTransportSecurity},get"no-unsafe-csp-directives"(){return require("./rules/no-unsafe-csp-directives").noUnsafeCspDirectives},get"no-permissive-trust-proxy"(){return require("./rules/no-permissive-trust-proxy").noPermissiveTrustProxy},get"require-route-authentication"(){return require("./rules/require-route-authentication").requireRouteAuthentication},get"no-client-controlled-authorization"(){return require("./rules/no-client-controlled-authorization").noClientControlledAuthorization},get"no-idor-resource-access"(){return require("./rules/no-idor-resource-access").noIdorResourceAccess}};exports.plugin={meta:{name:"eslint-plugin-express-security",version:"1.5.5"},rules:exports.rules};const recommendedRules={"express-security/require-helmet":"error","express-security/no-permissive-cors":"error","express-security/require-csrf-protection":"warn","express-security/no-insecure-cookie-options":"error","express-security/require-rate-limiting":"warn","express-security/no-graphql-introspection-production":"warn","express-security/no-cors-credentials-wildcard":"error","express-security/require-express-body-parser-limits":"warn","express-security/no-express-unsafe-regex-route":"error","express-security/no-exposed-debug-endpoints":"error","express-security/no-missing-cors-check":"warn","express-security/no-missing-csrf-protection":"warn","express-security/no-missing-security-headers":"warn","express-security/no-user-controlled-redirect":"error","express-security/no-host-header-in-links":"error","express-security/no-error-details-in-response":"error","express-security/no-sensitive-data-in-query":"warn","express-security/no-user-controlled-render-locals":"error","express-security/no-static-root-exposure":"error","express-security/require-case-insensitive-path-guard":"warn","express-security/require-query-type-guard":"warn","express-security/no-disabled-helmet-protections":"error","express-security/require-strict-transport-security":"error","express-security/no-unsafe-csp-directives":"error","express-security/no-permissive-trust-proxy":"error","express-security/require-route-authentication":"warn","express-security/no-client-controlled-authorization":"warn","express-security/no-idor-resource-access":"warn"};exports.configs={recommended:{plugins:{"express-security":exports.plugin},rules:recommendedRules},strict:{plugins:{"express-security":exports.plugin},rules:Object.fromEntries(Object.keys(exports.rules).map(ruleName=>[`express-security/${ruleName}`,"error"]))},api:{plugins:{"express-security":exports.plugin},rules:{"express-security/require-helmet":"error","express-security/no-disabled-helmet-protections":"error","express-security/require-strict-transport-security":"error","express-security/no-unsafe-csp-directives":"error","express-security/no-permissive-trust-proxy":"error","express-security/no-permissive-cors":"error","express-security/require-csrf-protection":"error","express-security/no-insecure-cookie-options":"error","express-security/require-rate-limiting":"error"}},graphql:{plugins:{"express-security":exports.plugin},rules:{"express-security/no-graphql-introspection-production":"error"}}};exports.default=exports.plugin;
|
package/src/oxlint.js
CHANGED
|
@@ -1,194 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noClientControlledAuthorization = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const CLIENT_CONTAINERS = new Set([
|
|
6
|
-
'body',
|
|
7
|
-
'query',
|
|
8
|
-
'params',
|
|
9
|
-
'headers',
|
|
10
|
-
'cookies',
|
|
11
|
-
]);
|
|
12
|
-
const REQUEST_RECEIVER = /^(req|request)$/i;
|
|
13
|
-
const AUTHZ_PROPERTIES = new Set([
|
|
14
|
-
'role',
|
|
15
|
-
'roles',
|
|
16
|
-
'admin',
|
|
17
|
-
'isadmin',
|
|
18
|
-
'is_admin',
|
|
19
|
-
'superuser',
|
|
20
|
-
'issuperuser',
|
|
21
|
-
'permission',
|
|
22
|
-
'permissions',
|
|
23
|
-
'scope',
|
|
24
|
-
'scopes',
|
|
25
|
-
'privilege',
|
|
26
|
-
'privileges',
|
|
27
|
-
'usertype',
|
|
28
|
-
'user_type',
|
|
29
|
-
'accesslevel',
|
|
30
|
-
'access_level',
|
|
31
|
-
'acl',
|
|
32
|
-
'claims',
|
|
33
|
-
'grants',
|
|
34
|
-
'userid',
|
|
35
|
-
'user_id',
|
|
36
|
-
'ownerid',
|
|
37
|
-
'owner_id',
|
|
38
|
-
'owner',
|
|
39
|
-
'accountid',
|
|
40
|
-
'account_id',
|
|
41
|
-
'tenantid',
|
|
42
|
-
'tenant_id',
|
|
43
|
-
'orgid',
|
|
44
|
-
'org_id',
|
|
45
|
-
]);
|
|
46
|
-
const AUTHZ_HEADER = /^x-.*(role|admin|user|auth|permission|scope|tenant|account|owner)/i;
|
|
47
|
-
function staticPropertyName(node) {
|
|
48
|
-
if (!node.computed && node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
49
|
-
return node.property.name;
|
|
50
|
-
}
|
|
51
|
-
if (node.computed &&
|
|
52
|
-
node.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
53
|
-
typeof node.property.value === 'string') {
|
|
54
|
-
return node.property.value;
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
function clientContainerOf(node) {
|
|
59
|
-
const { object } = node;
|
|
60
|
-
if (object.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
61
|
-
return null;
|
|
62
|
-
const container = staticPropertyName(object);
|
|
63
|
-
if (!container || !CLIENT_CONTAINERS.has(container))
|
|
64
|
-
return null;
|
|
65
|
-
const root = object.object;
|
|
66
|
-
if (root.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && REQUEST_RECEIVER.test(root.name)) {
|
|
67
|
-
return container;
|
|
68
|
-
}
|
|
69
|
-
if (root.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
70
|
-
root.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
71
|
-
REQUEST_RECEIVER.test(root.property.name)) {
|
|
72
|
-
return container;
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
function isAuthorizationDecision(node) {
|
|
77
|
-
let current = node;
|
|
78
|
-
let parent = node.parent;
|
|
79
|
-
for (let depth = 0; parent && depth < 4; depth += 1) {
|
|
80
|
-
switch (parent.type) {
|
|
81
|
-
case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:
|
|
82
|
-
if (parent.operator === '===' ||
|
|
83
|
-
parent.operator === '==' ||
|
|
84
|
-
parent.operator === '!==' ||
|
|
85
|
-
parent.operator === '!=') {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
case eslint_devkit_1.AST_NODE_TYPES.IfStatement:
|
|
90
|
-
case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:
|
|
91
|
-
if (parent.test === current)
|
|
92
|
-
return true;
|
|
93
|
-
break;
|
|
94
|
-
case eslint_devkit_1.AST_NODE_TYPES.SwitchStatement:
|
|
95
|
-
if (parent.discriminant === current)
|
|
96
|
-
return true;
|
|
97
|
-
break;
|
|
98
|
-
case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:
|
|
99
|
-
if (parent.operator === '??')
|
|
100
|
-
break;
|
|
101
|
-
return true;
|
|
102
|
-
case eslint_devkit_1.AST_NODE_TYPES.UnaryExpression:
|
|
103
|
-
if (parent.operator === '!')
|
|
104
|
-
return true;
|
|
105
|
-
break;
|
|
106
|
-
case eslint_devkit_1.AST_NODE_TYPES.CallExpression:
|
|
107
|
-
if (parent.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
108
|
-
parent.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
109
|
-
(parent.callee.property.name === 'includes' ||
|
|
110
|
-
parent.callee.property.name === 'some')) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
default:
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
current = parent;
|
|
118
|
-
parent = parent.parent;
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
exports.noClientControlledAuthorization = (0, eslint_devkit_1.createRule)({
|
|
123
|
-
name: 'no-client-controlled-authorization',
|
|
124
|
-
meta: {
|
|
125
|
-
type: 'problem',
|
|
126
|
-
docs: {
|
|
127
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-client-controlled-authorization.md',
|
|
128
|
-
description: 'Disallow authorization decisions taken on request-supplied role, permission or identity values',
|
|
129
|
-
cwe: 'CWE-863',
|
|
130
|
-
cvss: 8.1,
|
|
131
|
-
confidence: 'medium',
|
|
132
|
-
},
|
|
133
|
-
messages: {
|
|
134
|
-
clientControlledAuthorization: (0, eslint_devkit_1.formatLLMMessage)({
|
|
135
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
136
|
-
issueName: 'Authorization Decided On Client Input (CWE-863)',
|
|
137
|
-
cwe: 'CWE-863',
|
|
138
|
-
cvss: 8.1,
|
|
139
|
-
description: 'The access decision reads {{expression}} — a value the caller sends. The check runs, and passes for anyone who sets the field.',
|
|
140
|
-
severity: 'HIGH',
|
|
141
|
-
fix: 'Read the attribute from the server-side session or verified token instead: req.user.{{property}} / req.auth.{{property}}.',
|
|
142
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/863.html',
|
|
143
|
-
}),
|
|
144
|
-
},
|
|
145
|
-
schema: [
|
|
146
|
-
{
|
|
147
|
-
type: 'object',
|
|
148
|
-
properties: {
|
|
149
|
-
extraProperties: {
|
|
150
|
-
type: 'array',
|
|
151
|
-
items: { type: 'string' },
|
|
152
|
-
description: 'Extra property names treated as authorization attributes',
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
additionalProperties: false,
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
defaultOptions: [{}],
|
|
160
|
-
create(context, [options]) {
|
|
161
|
-
const { extraProperties } = options;
|
|
162
|
-
const extra = new Set((extraProperties ?? []).map((name) => name.toLowerCase()));
|
|
163
|
-
function isAuthorizationAttribute(property, container) {
|
|
164
|
-
const normalized = property.toLowerCase();
|
|
165
|
-
if (AUTHZ_PROPERTIES.has(normalized))
|
|
166
|
-
return true;
|
|
167
|
-
if (extra.has(normalized))
|
|
168
|
-
return true;
|
|
169
|
-
return container === 'headers' && AUTHZ_HEADER.test(property);
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
MemberExpression(node) {
|
|
173
|
-
const property = staticPropertyName(node);
|
|
174
|
-
if (!property)
|
|
175
|
-
return;
|
|
176
|
-
const container = clientContainerOf(node);
|
|
177
|
-
if (!container)
|
|
178
|
-
return;
|
|
179
|
-
if (!isAuthorizationAttribute(property, container))
|
|
180
|
-
return;
|
|
181
|
-
if (!isAuthorizationDecision(node))
|
|
182
|
-
return;
|
|
183
|
-
context.report({
|
|
184
|
-
node,
|
|
185
|
-
messageId: 'clientControlledAuthorization',
|
|
186
|
-
data: {
|
|
187
|
-
expression: context.sourceCode.getText(node),
|
|
188
|
-
property,
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
},
|
|
194
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noClientControlledAuthorization=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const CLIENT_CONTAINERS=new Set(["body","query","params","headers","cookies"]);const REQUEST_RECEIVER=/^(req|request)$/i;const AUTHZ_PROPERTIES=new Set(["role","roles","admin","isadmin","is_admin","superuser","issuperuser","permission","permissions","scope","scopes","privilege","privileges","usertype","user_type","accesslevel","access_level","acl","claims","grants","userid","user_id","ownerid","owner_id","owner","accountid","account_id","tenantid","tenant_id","orgid","org_id"]);const AUTHZ_HEADER=/^x-.*(role|admin|user|auth|permission|scope|tenant|account|owner)/i;function staticPropertyName(node){if(!node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return node.property.name}if(node.computed&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.property.value==="string"){return node.property.value}return null}function clientContainerOf(node){const{object}=node;if(object.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return null;const container=staticPropertyName(object);if(!container||!CLIENT_CONTAINERS.has(container))return null;const root=object.object;if(root.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&REQUEST_RECEIVER.test(root.name)){return container}if(root.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&root.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&REQUEST_RECEIVER.test(root.property.name)){return container}return null}function isAuthorizationDecision(node){let current=node;let parent=node.parent;for(let depth=0;parent&&depth<4;depth+=1){switch(parent.type){case eslint_devkit_1.AST_NODE_TYPES.BinaryExpression:if(parent.operator==="==="||parent.operator==="=="||parent.operator==="!=="||parent.operator==="!="){return true}break;case eslint_devkit_1.AST_NODE_TYPES.IfStatement:case eslint_devkit_1.AST_NODE_TYPES.ConditionalExpression:if(parent.test===current)return true;break;case eslint_devkit_1.AST_NODE_TYPES.SwitchStatement:if(parent.discriminant===current)return true;break;case eslint_devkit_1.AST_NODE_TYPES.LogicalExpression:if(parent.operator==="??")break;return true;case eslint_devkit_1.AST_NODE_TYPES.UnaryExpression:if(parent.operator==="!")return true;break;case eslint_devkit_1.AST_NODE_TYPES.CallExpression:if(parent.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&parent.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(parent.callee.property.name==="includes"||parent.callee.property.name==="some")){return true}return false;default:break}current=parent;parent=parent.parent}return false}exports.noClientControlledAuthorization=(0,eslint_devkit_1.createRule)({name:"no-client-controlled-authorization",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-client-controlled-authorization.md",description:"Disallow authorization decisions taken on request-supplied role, permission or identity values",cwe:"CWE-863",cvss:8.1,confidence:"medium"},messages:{clientControlledAuthorization:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Authorization Decided On Client Input (CWE-863)",cwe:"CWE-863",cvss:8.1,description:"The access decision reads {{expression}} \u2014 a value the caller sends. The check runs, and passes for anyone who sets the field.",severity:"HIGH",fix:"Read the attribute from the server-side session or verified token instead: req.user.{{property}} / req.auth.{{property}}.",documentationLink:"https://cwe.mitre.org/data/definitions/863.html"})},schema:[{type:"object",properties:{extraProperties:{type:"array",items:{type:"string"},description:"Extra property names treated as authorization attributes"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{extraProperties}=options;const extra=new Set((extraProperties??[]).map(name=>name.toLowerCase()));function isAuthorizationAttribute(property,container){const normalized=property.toLowerCase();if(AUTHZ_PROPERTIES.has(normalized))return true;if(extra.has(normalized))return true;return container==="headers"&&AUTHZ_HEADER.test(property)}return{MemberExpression(node){const property=staticPropertyName(node);if(!property)return;const container=clientContainerOf(node);if(!container)return;if(!isAuthorizationAttribute(property,container))return;if(!isAuthorizationDecision(node))return;context.report({node,messageId:"clientControlledAuthorization",data:{expression:context.sourceCode.getText(node),property}})}}}});
|
|
@@ -1,127 +1 @@
|
|
|
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
|
-
function hasWildcardOrigin(node, sourceCode) {
|
|
6
|
-
const text = sourceCode.getText(node);
|
|
7
|
-
if (/\borigin\s*:\s*['"`]\*['"`]/.test(text)) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
if (/\borigin\s*:\s*true\b/.test(text)) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
function hasCredentialsTrue(node, sourceCode) {
|
|
16
|
-
const text = sourceCode.getText(node);
|
|
17
|
-
return /\bcredentials\s*:\s*true\b/.test(text);
|
|
18
|
-
}
|
|
19
|
-
function getCorsConfigNode(node) {
|
|
20
|
-
const callee = node.callee;
|
|
21
|
-
if (callee.type === 'Identifier' && callee.name === 'cors') {
|
|
22
|
-
const parent = node.parent;
|
|
23
|
-
if (parent &&
|
|
24
|
-
parent.type === 'CallExpression' &&
|
|
25
|
-
parent.callee.type === 'MemberExpression' &&
|
|
26
|
-
parent.callee.property.type === 'Identifier' &&
|
|
27
|
-
parent.callee.property.name === 'use') {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
if (node.arguments[0]?.type === 'ObjectExpression') {
|
|
31
|
-
return node.arguments[0];
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
if (callee.type === 'MemberExpression' &&
|
|
36
|
-
callee.property.type === 'Identifier' &&
|
|
37
|
-
callee.property.name === 'use') {
|
|
38
|
-
const firstArg = node.arguments[0];
|
|
39
|
-
if (firstArg?.type === 'CallExpression' &&
|
|
40
|
-
firstArg.callee.type === 'Identifier' &&
|
|
41
|
-
firstArg.callee.name === 'cors' &&
|
|
42
|
-
firstArg.arguments[0]?.type === 'ObjectExpression') {
|
|
43
|
-
return firstArg.arguments[0];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
exports.noCorsCredentialsWildcard = (0, eslint_devkit_1.createRule)({
|
|
49
|
-
name: 'no-cors-credentials-wildcard',
|
|
50
|
-
meta: {
|
|
51
|
-
type: 'problem',
|
|
52
|
-
docs: {
|
|
53
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-cors-credentials-wildcard.md',
|
|
54
|
-
description: 'Disallow credentials: true with wildcard CORS origin (CVE-2024-25124)',
|
|
55
|
-
cwe: 'CWE-942',
|
|
56
|
-
cvss: 7.5,
|
|
57
|
-
},
|
|
58
|
-
hasSuggestions: true,
|
|
59
|
-
messages: {
|
|
60
|
-
credentialsWildcard: (0, eslint_devkit_1.formatLLMMessage)({
|
|
61
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
62
|
-
issueName: 'CORS Credentials with Wildcard Origin',
|
|
63
|
-
cwe: 'CWE-942',
|
|
64
|
-
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).',
|
|
65
|
-
severity: 'CRITICAL',
|
|
66
|
-
fix: 'Specify explicit allowed origins: origin: ["https://trusted-domain.com"]',
|
|
67
|
-
documentationLink: 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-25124',
|
|
68
|
-
}),
|
|
69
|
-
useExplicitOrigins: (0, eslint_devkit_1.formatLLMMessage)({
|
|
70
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
71
|
-
issueName: 'Use Explicit Origins',
|
|
72
|
-
description: 'Replace wildcard with explicit origin whitelist',
|
|
73
|
-
severity: 'LOW',
|
|
74
|
-
fix: 'origin: ["https://your-frontend.com"]',
|
|
75
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS',
|
|
76
|
-
}),
|
|
77
|
-
},
|
|
78
|
-
schema: [
|
|
79
|
-
{
|
|
80
|
-
type: 'object',
|
|
81
|
-
properties: {
|
|
82
|
-
allowInTests: {
|
|
83
|
-
type: 'boolean',
|
|
84
|
-
default: false,
|
|
85
|
-
description: 'Allow in test files',
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
additionalProperties: false,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
defaultOptions: [
|
|
93
|
-
{
|
|
94
|
-
allowInTests: false,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
create(context, [options]) {
|
|
98
|
-
const { allowInTests = false } = options;
|
|
99
|
-
const filename = context.filename;
|
|
100
|
-
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
101
|
-
if (isTestFile) {
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
const sourceCode = context.sourceCode;
|
|
105
|
-
return {
|
|
106
|
-
CallExpression(node) {
|
|
107
|
-
const corsConfigNode = getCorsConfigNode(node);
|
|
108
|
-
if (corsConfigNode) {
|
|
109
|
-
const hasWildcard = hasWildcardOrigin(corsConfigNode, sourceCode);
|
|
110
|
-
const hasCredentials = hasCredentialsTrue(corsConfigNode, sourceCode);
|
|
111
|
-
if (hasWildcard && hasCredentials) {
|
|
112
|
-
context.report({
|
|
113
|
-
node: corsConfigNode,
|
|
114
|
-
messageId: 'credentialsWildcard',
|
|
115
|
-
suggest: [
|
|
116
|
-
{
|
|
117
|
-
messageId: 'useExplicitOrigins',
|
|
118
|
-
fix: () => null,
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noCorsCredentialsWildcard=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function hasWildcardOrigin(node,sourceCode){const text=sourceCode.getText(node);if(/\borigin\s*:\s*['"`]\*['"`]/.test(text)){return true}if(/\borigin\s*:\s*true\b/.test(text)){return true}return false}function hasCredentialsTrue(node,sourceCode){const text=sourceCode.getText(node);return/\bcredentials\s*:\s*true\b/.test(text)}function getCorsConfigNode(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 null}if(node.arguments[0]?.type==="ObjectExpression"){return node.arguments[0]}return null}if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="use"){const firstArg=node.arguments[0];if(firstArg?.type==="CallExpression"&&firstArg.callee.type==="Identifier"&&firstArg.callee.name==="cors"&&firstArg.arguments[0]?.type==="ObjectExpression"){return firstArg.arguments[0]}}return null}exports.noCorsCredentialsWildcard=(0,eslint_devkit_1.createRule)({name:"no-cors-credentials-wildcard",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-cors-credentials-wildcard.md",description:"Disallow credentials: true with wildcard CORS origin (CVE-2024-25124)",cwe:"CWE-942",cvss:7.5},hasSuggestions:true,messages:{credentialsWildcard:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"CORS Credentials with Wildcard Origin",cwe:"CWE-942",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).',severity:"CRITICAL",fix:'Specify explicit allowed origins: origin: ["https://trusted-domain.com"]',documentationLink:"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-25124"}),useExplicitOrigins:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Explicit Origins",description:"Replace wildcard with explicit origin whitelist",severity:"LOW",fix:'origin: ["https://your-frontend.com"]',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS"})},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{}}const sourceCode=context.sourceCode;return{CallExpression(node){const corsConfigNode=getCorsConfigNode(node);if(corsConfigNode){const hasWildcard=hasWildcardOrigin(corsConfigNode,sourceCode);const hasCredentials=hasCredentialsTrue(corsConfigNode,sourceCode);if(hasWildcard&&hasCredentials){context.report({node:corsConfigNode,messageId:"credentialsWildcard",suggest:[{messageId:"useExplicitOrigins",fix:()=>null}]})}}}}}});
|
|
@@ -1,125 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noDisabledHelmetProtections = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const PROTECTIONS = {
|
|
6
|
-
contentSecurityPolicy: 'Content-Security-Policy',
|
|
7
|
-
frameguard: 'X-Frame-Options',
|
|
8
|
-
xFrameOptions: 'X-Frame-Options',
|
|
9
|
-
noSniff: 'X-Content-Type-Options',
|
|
10
|
-
xContentTypeOptions: 'X-Content-Type-Options',
|
|
11
|
-
referrerPolicy: 'Referrer-Policy',
|
|
12
|
-
hidePoweredBy: 'X-Powered-By (removal)',
|
|
13
|
-
xPoweredBy: 'X-Powered-By (removal)',
|
|
14
|
-
crossOriginResourcePolicy: 'Cross-Origin-Resource-Policy',
|
|
15
|
-
crossOriginOpenerPolicy: 'Cross-Origin-Opener-Policy',
|
|
16
|
-
};
|
|
17
|
-
function isHelmetCall(node) {
|
|
18
|
-
return (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
19
|
-
node.callee.name === 'helmet');
|
|
20
|
-
}
|
|
21
|
-
function propertyKeyName(prop) {
|
|
22
|
-
if (prop.computed)
|
|
23
|
-
return null;
|
|
24
|
-
if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier)
|
|
25
|
-
return prop.key.name;
|
|
26
|
-
if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
27
|
-
typeof prop.key.value === 'string') {
|
|
28
|
-
return prop.key.value;
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
exports.noDisabledHelmetProtections = (0, eslint_devkit_1.createRule)({
|
|
33
|
-
name: 'no-disabled-helmet-protections',
|
|
34
|
-
meta: {
|
|
35
|
-
type: 'problem',
|
|
36
|
-
hasSuggestions: true,
|
|
37
|
-
docs: {
|
|
38
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-disabled-helmet-protections.md',
|
|
39
|
-
description: 'Disallow disabling helmet security-header defaults: contentSecurityPolicy, frameguard/xFrameOptions, noSniff/xContentTypeOptions, referrerPolicy, hidePoweredBy/xPoweredBy, crossOriginResourcePolicy, crossOriginOpenerPolicy',
|
|
40
|
-
cwe: 'CWE-693',
|
|
41
|
-
cvss: 6.5,
|
|
42
|
-
confidence: 'high',
|
|
43
|
-
},
|
|
44
|
-
messages: {
|
|
45
|
-
disabledProtection: (0, eslint_devkit_1.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
47
|
-
issueName: 'Helmet Protection Disabled (CWE-693)',
|
|
48
|
-
cwe: 'CWE-693',
|
|
49
|
-
cvss: 6.5,
|
|
50
|
-
description: 'helmet({ {{option}}: false }) stops the {{header}} header from being sent. The middleware is mounted but this protection is off, so the app ships the same exposure as an app with no helmet at all.',
|
|
51
|
-
severity: 'HIGH',
|
|
52
|
-
fix: 'Remove the `{{option}}: false` entry and keep the helmet default. If the header must be customised, pass its options object instead of `false`.',
|
|
53
|
-
documentationLink: 'https://helmetjs.github.io/',
|
|
54
|
-
}),
|
|
55
|
-
restoreDefault: 'Remove `{{option}}: false` and keep the helmet default',
|
|
56
|
-
},
|
|
57
|
-
schema: [
|
|
58
|
-
{
|
|
59
|
-
type: 'object',
|
|
60
|
-
properties: {
|
|
61
|
-
allowDisabled: {
|
|
62
|
-
type: 'array',
|
|
63
|
-
items: { type: 'string' },
|
|
64
|
-
description: 'Helmet option names that may be disabled without a report',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
additionalProperties: false,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
defaultOptions: [{}],
|
|
72
|
-
create(context, [options]) {
|
|
73
|
-
const { allowDisabled } = options;
|
|
74
|
-
const allowed = new Set(allowDisabled ?? []);
|
|
75
|
-
function removeProperty(fixer, prop) {
|
|
76
|
-
const sourceCode = context.sourceCode;
|
|
77
|
-
const after = sourceCode.getTokenAfter(prop);
|
|
78
|
-
if (after && after.value === ',') {
|
|
79
|
-
return fixer.removeRange([prop.range[0], after.range[1]]);
|
|
80
|
-
}
|
|
81
|
-
const before = sourceCode.getTokenBefore(prop);
|
|
82
|
-
if (before && before.value === ',') {
|
|
83
|
-
return fixer.removeRange([before.range[0], prop.range[1]]);
|
|
84
|
-
}
|
|
85
|
-
return fixer.remove(prop);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
CallExpression(node) {
|
|
89
|
-
if (!isHelmetCall(node))
|
|
90
|
-
return;
|
|
91
|
-
const config = node.arguments[0];
|
|
92
|
-
if (!config || config.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
|
|
93
|
-
return;
|
|
94
|
-
for (const prop of config.properties) {
|
|
95
|
-
if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
|
|
96
|
-
continue;
|
|
97
|
-
const name = propertyKeyName(prop);
|
|
98
|
-
if (!name)
|
|
99
|
-
continue;
|
|
100
|
-
const header = PROTECTIONS[name];
|
|
101
|
-
if (!header)
|
|
102
|
-
continue;
|
|
103
|
-
if (allowed.has(name))
|
|
104
|
-
continue;
|
|
105
|
-
if (prop.value.type !== eslint_devkit_1.AST_NODE_TYPES.Literal ||
|
|
106
|
-
prop.value.value !== false) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
context.report({
|
|
110
|
-
node: prop,
|
|
111
|
-
messageId: 'disabledProtection',
|
|
112
|
-
data: { option: name, header },
|
|
113
|
-
suggest: [
|
|
114
|
-
{
|
|
115
|
-
messageId: 'restoreDefault',
|
|
116
|
-
data: { option: name },
|
|
117
|
-
fix: (fixer) => removeProperty(fixer, prop),
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDisabledHelmetProtections=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const PROTECTIONS={contentSecurityPolicy:"Content-Security-Policy",frameguard:"X-Frame-Options",xFrameOptions:"X-Frame-Options",noSniff:"X-Content-Type-Options",xContentTypeOptions:"X-Content-Type-Options",referrerPolicy:"Referrer-Policy",hidePoweredBy:"X-Powered-By (removal)",xPoweredBy:"X-Powered-By (removal)",crossOriginResourcePolicy:"Cross-Origin-Resource-Policy",crossOriginOpenerPolicy:"Cross-Origin-Opener-Policy"};function isHelmetCall(node){return node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="helmet"}function propertyKeyName(prop){if(prop.computed)return null;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return prop.key.name;if(prop.key.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof prop.key.value==="string"){return prop.key.value}return null}exports.noDisabledHelmetProtections=(0,eslint_devkit_1.createRule)({name:"no-disabled-helmet-protections",meta:{type:"problem",hasSuggestions:true,docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/no-disabled-helmet-protections.md",description:"Disallow disabling helmet security-header defaults: contentSecurityPolicy, frameguard/xFrameOptions, noSniff/xContentTypeOptions, referrerPolicy, hidePoweredBy/xPoweredBy, crossOriginResourcePolicy, crossOriginOpenerPolicy",cwe:"CWE-693",cvss:6.5,confidence:"high"},messages:{disabledProtection:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Helmet Protection Disabled (CWE-693)",cwe:"CWE-693",cvss:6.5,description:"helmet({ {{option}}: false }) stops the {{header}} header from being sent. The middleware is mounted but this protection is off, so the app ships the same exposure as an app with no helmet at all.",severity:"HIGH",fix:"Remove the `{{option}}: false` entry and keep the helmet default. If the header must be customised, pass its options object instead of `false`.",documentationLink:"https://helmetjs.github.io/"}),restoreDefault:"Remove `{{option}}: false` and keep the helmet default"},schema:[{type:"object",properties:{allowDisabled:{type:"array",items:{type:"string"},description:"Helmet option names that may be disabled without a report"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{allowDisabled}=options;const allowed=new Set(allowDisabled??[]);function removeProperty(fixer,prop){const sourceCode=context.sourceCode;const after=sourceCode.getTokenAfter(prop);if(after&&after.value===","){return fixer.removeRange([prop.range[0],after.range[1]])}const before=sourceCode.getTokenBefore(prop);if(before&&before.value===","){return fixer.removeRange([before.range[0],prop.range[1]])}return fixer.remove(prop)}return{CallExpression(node){if(!isHelmetCall(node))return;const config=node.arguments[0];if(!config||config.type!==eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)return;for(const prop of config.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const name=propertyKeyName(prop);if(!name)continue;const header=PROTECTIONS[name];if(!header)continue;if(allowed.has(name))continue;if(prop.value.type!==eslint_devkit_1.AST_NODE_TYPES.Literal||prop.value.value!==false){continue}context.report({node:prop,messageId:"disabledProtection",data:{option:name,header},suggest:[{messageId:"restoreDefault",data:{option:name},fix:fixer=>removeProperty(fixer,prop)}]})}}}}});
|