eslint-plugin-express-security 1.5.3 → 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 -3
- package/src/index.js +1 -140
- 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,8 +76,7 @@
|
|
|
76
76
|
"node": ">=18.0.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"
|
|
80
|
-
"@interlace/eslint-devkit": "^1.7.0"
|
|
79
|
+
"@interlace/eslint-devkit": "^1.10.0"
|
|
81
80
|
},
|
|
82
81
|
"peerDependencies": {
|
|
83
82
|
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
package/src/index.js
CHANGED
|
@@ -1,140 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configs = exports.plugin = exports.rules = void 0;
|
|
4
|
-
const require_helmet_1 = require("./rules/require-helmet");
|
|
5
|
-
const no_permissive_cors_1 = require("./rules/no-permissive-cors");
|
|
6
|
-
const require_csrf_protection_1 = require("./rules/require-csrf-protection");
|
|
7
|
-
const no_insecure_cookie_options_1 = require("./rules/no-insecure-cookie-options");
|
|
8
|
-
const require_rate_limiting_1 = require("./rules/require-rate-limiting");
|
|
9
|
-
const no_graphql_introspection_production_1 = require("./rules/no-graphql-introspection-production");
|
|
10
|
-
const no_cors_credentials_wildcard_1 = require("./rules/no-cors-credentials-wildcard");
|
|
11
|
-
const require_express_body_parser_limits_1 = require("./rules/require-express-body-parser-limits");
|
|
12
|
-
const no_express_unsafe_regex_route_1 = require("./rules/no-express-unsafe-regex-route");
|
|
13
|
-
const no_exposed_debug_endpoints_1 = require("./rules/no-exposed-debug-endpoints");
|
|
14
|
-
const no_missing_cors_check_1 = require("./rules/no-missing-cors-check");
|
|
15
|
-
const no_missing_csrf_protection_1 = require("./rules/no-missing-csrf-protection");
|
|
16
|
-
const no_missing_security_headers_1 = require("./rules/no-missing-security-headers");
|
|
17
|
-
const no_user_controlled_redirect_1 = require("./rules/no-user-controlled-redirect");
|
|
18
|
-
const no_host_header_in_links_1 = require("./rules/no-host-header-in-links");
|
|
19
|
-
const no_error_details_in_response_1 = require("./rules/no-error-details-in-response");
|
|
20
|
-
const no_sensitive_data_in_query_1 = require("./rules/no-sensitive-data-in-query");
|
|
21
|
-
const no_user_controlled_render_locals_1 = require("./rules/no-user-controlled-render-locals");
|
|
22
|
-
const no_static_root_exposure_1 = require("./rules/no-static-root-exposure");
|
|
23
|
-
const require_case_insensitive_path_guard_1 = require("./rules/require-case-insensitive-path-guard");
|
|
24
|
-
const require_query_type_guard_1 = require("./rules/require-query-type-guard");
|
|
25
|
-
const no_disabled_helmet_protections_1 = require("./rules/no-disabled-helmet-protections");
|
|
26
|
-
const require_strict_transport_security_1 = require("./rules/require-strict-transport-security");
|
|
27
|
-
const no_unsafe_csp_directives_1 = require("./rules/no-unsafe-csp-directives");
|
|
28
|
-
const no_permissive_trust_proxy_1 = require("./rules/no-permissive-trust-proxy");
|
|
29
|
-
const require_route_authentication_1 = require("./rules/require-route-authentication");
|
|
30
|
-
const no_client_controlled_authorization_1 = require("./rules/no-client-controlled-authorization");
|
|
31
|
-
const no_idor_resource_access_1 = require("./rules/no-idor-resource-access");
|
|
32
|
-
exports.rules = {
|
|
33
|
-
'require-helmet': require_helmet_1.requireHelmet,
|
|
34
|
-
'no-permissive-cors': no_permissive_cors_1.noPermissiveCors,
|
|
35
|
-
'require-csrf-protection': require_csrf_protection_1.requireCsrfProtection,
|
|
36
|
-
'no-insecure-cookie-options': no_insecure_cookie_options_1.noInsecureCookieOptions,
|
|
37
|
-
'require-rate-limiting': require_rate_limiting_1.requireRateLimiting,
|
|
38
|
-
'no-graphql-introspection-production': no_graphql_introspection_production_1.noGraphqlIntrospectionProduction,
|
|
39
|
-
'no-cors-credentials-wildcard': no_cors_credentials_wildcard_1.noCorsCredentialsWildcard,
|
|
40
|
-
'require-express-body-parser-limits': require_express_body_parser_limits_1.requireExpressBodyParserLimits,
|
|
41
|
-
'no-express-unsafe-regex-route': no_express_unsafe_regex_route_1.noExpressUnsafeRegexRoute,
|
|
42
|
-
'no-exposed-debug-endpoints': no_exposed_debug_endpoints_1.noExposedDebugEndpoints,
|
|
43
|
-
'no-missing-cors-check': no_missing_cors_check_1.noMissingCorsCheck,
|
|
44
|
-
'no-missing-csrf-protection': no_missing_csrf_protection_1.noMissingCsrfProtection,
|
|
45
|
-
'no-missing-security-headers': no_missing_security_headers_1.noMissingSecurityHeaders,
|
|
46
|
-
'no-user-controlled-redirect': no_user_controlled_redirect_1.noUserControlledRedirect,
|
|
47
|
-
'no-host-header-in-links': no_host_header_in_links_1.noHostHeaderInLinks,
|
|
48
|
-
'no-error-details-in-response': no_error_details_in_response_1.noErrorDetailsInResponse,
|
|
49
|
-
'no-sensitive-data-in-query': no_sensitive_data_in_query_1.noSensitiveDataInQuery,
|
|
50
|
-
'no-user-controlled-render-locals': no_user_controlled_render_locals_1.noUserControlledRenderLocals,
|
|
51
|
-
'no-static-root-exposure': no_static_root_exposure_1.noStaticRootExposure,
|
|
52
|
-
'require-case-insensitive-path-guard': require_case_insensitive_path_guard_1.requireCaseInsensitivePathGuard,
|
|
53
|
-
'require-query-type-guard': require_query_type_guard_1.requireQueryTypeGuard,
|
|
54
|
-
'no-disabled-helmet-protections': no_disabled_helmet_protections_1.noDisabledHelmetProtections,
|
|
55
|
-
'require-strict-transport-security': require_strict_transport_security_1.requireStrictTransportSecurity,
|
|
56
|
-
'no-unsafe-csp-directives': no_unsafe_csp_directives_1.noUnsafeCspDirectives,
|
|
57
|
-
'no-permissive-trust-proxy': no_permissive_trust_proxy_1.noPermissiveTrustProxy,
|
|
58
|
-
'require-route-authentication': require_route_authentication_1.requireRouteAuthentication,
|
|
59
|
-
'no-client-controlled-authorization': no_client_controlled_authorization_1.noClientControlledAuthorization,
|
|
60
|
-
'no-idor-resource-access': no_idor_resource_access_1.noIdorResourceAccess,
|
|
61
|
-
};
|
|
62
|
-
exports.plugin = {
|
|
63
|
-
meta: {
|
|
64
|
-
name: 'eslint-plugin-express-security',
|
|
65
|
-
version: '1.5.3',
|
|
66
|
-
},
|
|
67
|
-
rules: exports.rules,
|
|
68
|
-
};
|
|
69
|
-
const recommendedRules = {
|
|
70
|
-
'express-security/require-helmet': 'error',
|
|
71
|
-
'express-security/no-permissive-cors': 'error',
|
|
72
|
-
'express-security/require-csrf-protection': 'warn',
|
|
73
|
-
'express-security/no-insecure-cookie-options': 'error',
|
|
74
|
-
'express-security/require-rate-limiting': 'warn',
|
|
75
|
-
'express-security/no-graphql-introspection-production': 'warn',
|
|
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
|
-
'express-security/no-exposed-debug-endpoints': 'error',
|
|
80
|
-
'express-security/no-missing-cors-check': 'warn',
|
|
81
|
-
'express-security/no-missing-csrf-protection': 'warn',
|
|
82
|
-
'express-security/no-missing-security-headers': 'warn',
|
|
83
|
-
'express-security/no-user-controlled-redirect': 'error',
|
|
84
|
-
'express-security/no-host-header-in-links': 'error',
|
|
85
|
-
'express-security/no-error-details-in-response': 'error',
|
|
86
|
-
'express-security/no-sensitive-data-in-query': 'warn',
|
|
87
|
-
'express-security/no-user-controlled-render-locals': 'error',
|
|
88
|
-
'express-security/no-static-root-exposure': 'error',
|
|
89
|
-
'express-security/require-case-insensitive-path-guard': 'warn',
|
|
90
|
-
'express-security/require-query-type-guard': 'warn',
|
|
91
|
-
'express-security/no-disabled-helmet-protections': 'error',
|
|
92
|
-
'express-security/require-strict-transport-security': 'error',
|
|
93
|
-
'express-security/no-unsafe-csp-directives': 'error',
|
|
94
|
-
'express-security/no-permissive-trust-proxy': 'error',
|
|
95
|
-
'express-security/require-route-authentication': 'warn',
|
|
96
|
-
'express-security/no-client-controlled-authorization': 'warn',
|
|
97
|
-
'express-security/no-idor-resource-access': 'warn',
|
|
98
|
-
};
|
|
99
|
-
exports.configs = {
|
|
100
|
-
recommended: {
|
|
101
|
-
plugins: {
|
|
102
|
-
'express-security': exports.plugin,
|
|
103
|
-
},
|
|
104
|
-
rules: recommendedRules,
|
|
105
|
-
},
|
|
106
|
-
strict: {
|
|
107
|
-
plugins: {
|
|
108
|
-
'express-security': exports.plugin,
|
|
109
|
-
},
|
|
110
|
-
rules: Object.fromEntries(Object.keys(exports.rules).map((ruleName) => [
|
|
111
|
-
`express-security/${ruleName}`,
|
|
112
|
-
'error',
|
|
113
|
-
])),
|
|
114
|
-
},
|
|
115
|
-
api: {
|
|
116
|
-
plugins: {
|
|
117
|
-
'express-security': exports.plugin,
|
|
118
|
-
},
|
|
119
|
-
rules: {
|
|
120
|
-
'express-security/require-helmet': 'error',
|
|
121
|
-
'express-security/no-disabled-helmet-protections': 'error',
|
|
122
|
-
'express-security/require-strict-transport-security': 'error',
|
|
123
|
-
'express-security/no-unsafe-csp-directives': 'error',
|
|
124
|
-
'express-security/no-permissive-trust-proxy': 'error',
|
|
125
|
-
'express-security/no-permissive-cors': 'error',
|
|
126
|
-
'express-security/require-csrf-protection': 'error',
|
|
127
|
-
'express-security/no-insecure-cookie-options': 'error',
|
|
128
|
-
'express-security/require-rate-limiting': 'error',
|
|
129
|
-
},
|
|
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
|
-
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)}]})}}}}});
|