eslint-plugin-express-security 1.5.4 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/index.js +1 -113
  4. package/src/oxlint.js +1 -3
  5. package/src/rules/no-client-controlled-authorization/index.js +1 -194
  6. package/src/rules/no-cors-credentials-wildcard/index.js +1 -127
  7. package/src/rules/no-disabled-helmet-protections/index.js +1 -125
  8. package/src/rules/no-error-details-in-response/index.js +1 -176
  9. package/src/rules/no-exposed-debug-endpoints/index.js +1 -96
  10. package/src/rules/no-express-unsafe-regex-route/index.js +1 -154
  11. package/src/rules/no-graphql-introspection-production/index.js +1 -143
  12. package/src/rules/no-host-header-in-links/index.js +1 -235
  13. package/src/rules/no-idor-resource-access/index.js +1 -126
  14. package/src/rules/no-insecure-cookie-options/index.js +1 -158
  15. package/src/rules/no-missing-cors-check/index.js +1 -351
  16. package/src/rules/no-missing-csrf-protection/index.js +1 -161
  17. package/src/rules/no-missing-security-headers/index.js +1 -206
  18. package/src/rules/no-permissive-cors/index.js +1 -185
  19. package/src/rules/no-permissive-trust-proxy/index.js +1 -106
  20. package/src/rules/no-sensitive-data-in-query/index.js +1 -182
  21. package/src/rules/no-static-root-exposure/index.js +1 -267
  22. package/src/rules/no-unsafe-csp-directives/index.js +1 -264
  23. package/src/rules/no-user-controlled-redirect/index.js +1 -117
  24. package/src/rules/no-user-controlled-render-locals/index.js +1 -268
  25. package/src/rules/require-case-insensitive-path-guard/index.js +1 -180
  26. package/src/rules/require-csrf-protection/index.js +1 -201
  27. package/src/rules/require-express-body-parser-limits/index.js +1 -181
  28. package/src/rules/require-helmet/index.js +1 -166
  29. package/src/rules/require-query-type-guard/index.js +1 -258
  30. package/src/rules/require-rate-limiting/index.js +1 -136
  31. package/src/rules/require-route-authentication/index.js +1 -225
  32. package/src/rules/require-strict-transport-security/index.js +1 -171
  33. package/src/types/index.js +1 -2
  34. package/src/utils/index.js +1 -81
@@ -1,171 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireStrictTransportSecurity = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DEFAULT_MIN_MAX_AGE = 15552000;
6
- const HSTS_NAMES = new Set(['hsts', 'strictTransportSecurity']);
7
- function propertyKeyName(prop) {
8
- if (prop.computed)
9
- return null;
10
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier)
11
- return prop.key.name;
12
- if (prop.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
13
- typeof prop.key.value === 'string') {
14
- return prop.key.value;
15
- }
16
- return null;
17
- }
18
- function isHelmetHstsFactory(node) {
19
- const callee = node.callee;
20
- if (callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
21
- return false;
22
- if (callee.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
23
- return false;
24
- if (callee.computed)
25
- return false;
26
- if (callee.object.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
27
- return false;
28
- return callee.object.name === 'helmet' && HSTS_NAMES.has(callee.property.name);
29
- }
30
- function isHelmetCall(node) {
31
- return (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
32
- node.callee.name === 'helmet');
33
- }
34
- exports.requireStrictTransportSecurity = (0, eslint_devkit_1.createRule)({
35
- name: 'require-strict-transport-security',
36
- meta: {
37
- type: 'problem',
38
- hasSuggestions: true,
39
- docs: {
40
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-strict-transport-security.md',
41
- description: 'Require a Strict-Transport-Security header with a long max-age and includeSubDomains',
42
- cwe: 'CWE-319',
43
- cvss: 7.4,
44
- confidence: 'high',
45
- },
46
- messages: {
47
- hstsDisabled: (0, eslint_devkit_1.formatLLMMessage)({
48
- icon: eslint_devkit_1.MessageIcons.SECURITY,
49
- issueName: 'HSTS Disabled (CWE-319)',
50
- cwe: 'CWE-319',
51
- cvss: 7.4,
52
- description: 'helmet({ {{option}}: false }) removes the Strict-Transport-Security header. Every first request of a session can then be downgraded to plaintext HTTP and stripped in transit.',
53
- severity: 'HIGH',
54
- fix: 'Remove the `{{option}}: false` entry, or configure it: { maxAge: 31536000, includeSubDomains: true, preload: true }.',
55
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
56
- }),
57
- maxAgeTooShort: (0, eslint_devkit_1.formatLLMMessage)({
58
- icon: eslint_devkit_1.MessageIcons.SECURITY,
59
- issueName: 'HSTS max-age Too Short (CWE-319)',
60
- cwe: 'CWE-319',
61
- cvss: 5.9,
62
- description: 'Strict-Transport-Security max-age is {{maxAge}}s, below the {{minimum}}s floor. Once it lapses, the next visit is downgradeable again.',
63
- severity: 'MEDIUM',
64
- fix: 'Set maxAge to at least {{minimum}} seconds. Preload submission (hstspreload.org) requires 31536000 — one year — plus includeSubDomains and preload.',
65
- documentationLink: 'https://hstspreload.org/',
66
- }),
67
- subdomainsExcluded: (0, eslint_devkit_1.formatLLMMessage)({
68
- icon: eslint_devkit_1.MessageIcons.SECURITY,
69
- issueName: 'HSTS Excludes Subdomains (CWE-319)',
70
- cwe: 'CWE-319',
71
- cvss: 5.9,
72
- description: 'includeSubDomains is off, so any subdomain still answers over plaintext HTTP — enough to plant a cookie the parent domain trusts.',
73
- severity: 'MEDIUM',
74
- fix: 'Set includeSubDomains: true once every subdomain serves HTTPS.',
75
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
76
- }),
77
- raiseMaxAge: 'Raise maxAge to {{minimum}} seconds',
78
- },
79
- schema: [
80
- {
81
- type: 'object',
82
- properties: {
83
- minMaxAge: {
84
- type: 'number',
85
- minimum: 0,
86
- description: 'Minimum accepted max-age in seconds',
87
- },
88
- requireSubDomains: {
89
- type: 'boolean',
90
- description: 'Require includeSubDomains',
91
- },
92
- },
93
- additionalProperties: false,
94
- },
95
- ],
96
- },
97
- defaultOptions: [{}],
98
- create(context, [options]) {
99
- const { minMaxAge, requireSubDomains } = options;
100
- const minimum = minMaxAge ?? DEFAULT_MIN_MAX_AGE;
101
- const wantSubDomains = requireSubDomains ?? true;
102
- function checkHstsOptions(config) {
103
- for (const prop of config.properties) {
104
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
105
- continue;
106
- const name = propertyKeyName(prop);
107
- if (!name)
108
- continue;
109
- if (name === 'maxAge' &&
110
- prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
111
- typeof prop.value.value === 'number' &&
112
- prop.value.value < minimum) {
113
- const maxAgeNode = prop.value;
114
- context.report({
115
- node: prop,
116
- messageId: 'maxAgeTooShort',
117
- data: { maxAge: String(maxAgeNode.value), minimum: String(minimum) },
118
- suggest: [
119
- {
120
- messageId: 'raiseMaxAge',
121
- data: { minimum: String(minimum) },
122
- fix: (fixer) => fixer.replaceText(maxAgeNode, String(minimum)),
123
- },
124
- ],
125
- });
126
- continue;
127
- }
128
- if (wantSubDomains &&
129
- name === 'includeSubDomains' &&
130
- prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
131
- prop.value.value === false) {
132
- context.report({ node: prop, messageId: 'subdomainsExcluded' });
133
- }
134
- }
135
- }
136
- function checkHstsValue(node, value, option) {
137
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
138
- value.value === false) {
139
- context.report({ node, messageId: 'hstsDisabled', data: { option } });
140
- return;
141
- }
142
- if (value.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
143
- checkHstsOptions(value);
144
- }
145
- }
146
- return {
147
- CallExpression(node) {
148
- if (isHelmetHstsFactory(node)) {
149
- const config = node.arguments[0];
150
- if (config && config.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
151
- checkHstsOptions(config);
152
- }
153
- return;
154
- }
155
- if (!isHelmetCall(node))
156
- return;
157
- const config = node.arguments[0];
158
- if (!config || config.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
159
- return;
160
- for (const prop of config.properties) {
161
- if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
162
- continue;
163
- const name = propertyKeyName(prop);
164
- if (!name || !HSTS_NAMES.has(name))
165
- continue;
166
- checkHstsValue(prop, prop.value, name);
167
- }
168
- },
169
- };
170
- },
171
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireStrictTransportSecurity=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DEFAULT_MIN_MAX_AGE=15552e3;const HSTS_NAMES=new Set(["hsts","strictTransportSecurity"]);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}function isHelmetHstsFactory(node){const callee=node.callee;if(callee.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;if(callee.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(callee.computed)return false;if(callee.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;return callee.object.name==="helmet"&&HSTS_NAMES.has(callee.property.name)}function isHelmetCall(node){return node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="helmet"}exports.requireStrictTransportSecurity=(0,eslint_devkit_1.createRule)({name:"require-strict-transport-security",meta:{type:"problem",hasSuggestions:true,docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-express-security/docs/rules/require-strict-transport-security.md",description:"Require a Strict-Transport-Security header with a long max-age and includeSubDomains",cwe:"CWE-319",cvss:7.4,confidence:"high"},messages:{hstsDisabled:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"HSTS Disabled (CWE-319)",cwe:"CWE-319",cvss:7.4,description:"helmet({ {{option}}: false }) removes the Strict-Transport-Security header. Every first request of a session can then be downgraded to plaintext HTTP and stripped in transit.",severity:"HIGH",fix:"Remove the `{{option}}: false` entry, or configure it: { maxAge: 31536000, includeSubDomains: true, preload: true }.",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),maxAgeTooShort:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"HSTS max-age Too Short (CWE-319)",cwe:"CWE-319",cvss:5.9,description:"Strict-Transport-Security max-age is {{maxAge}}s, below the {{minimum}}s floor. Once it lapses, the next visit is downgradeable again.",severity:"MEDIUM",fix:"Set maxAge to at least {{minimum}} seconds. Preload submission (hstspreload.org) requires 31536000 \u2014 one year \u2014 plus includeSubDomains and preload.",documentationLink:"https://hstspreload.org/"}),subdomainsExcluded:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"HSTS Excludes Subdomains (CWE-319)",cwe:"CWE-319",cvss:5.9,description:"includeSubDomains is off, so any subdomain still answers over plaintext HTTP \u2014 enough to plant a cookie the parent domain trusts.",severity:"MEDIUM",fix:"Set includeSubDomains: true once every subdomain serves HTTPS.",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),raiseMaxAge:"Raise maxAge to {{minimum}} seconds"},schema:[{type:"object",properties:{minMaxAge:{type:"number",minimum:0,description:"Minimum accepted max-age in seconds"},requireSubDomains:{type:"boolean",description:"Require includeSubDomains"}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options]){const{minMaxAge,requireSubDomains}=options;const minimum=minMaxAge??DEFAULT_MIN_MAX_AGE;const wantSubDomains=requireSubDomains??true;function checkHstsOptions(config){for(const prop of config.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const name=propertyKeyName(prop);if(!name)continue;if(name==="maxAge"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof prop.value.value==="number"&&prop.value.value<minimum){const maxAgeNode=prop.value;context.report({node:prop,messageId:"maxAgeTooShort",data:{maxAge:String(maxAgeNode.value),minimum:String(minimum)},suggest:[{messageId:"raiseMaxAge",data:{minimum:String(minimum)},fix:fixer=>fixer.replaceText(maxAgeNode,String(minimum))}]});continue}if(wantSubDomains&&name==="includeSubDomains"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value===false){context.report({node:prop,messageId:"subdomainsExcluded"})}}}function checkHstsValue(node,value,option){if(value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&value.value===false){context.report({node,messageId:"hstsDisabled",data:{option}});return}if(value.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkHstsOptions(value)}}return{CallExpression(node){if(isHelmetHstsFactory(node)){const config2=node.arguments[0];if(config2&&config2.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){checkHstsOptions(config2)}return}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||!HSTS_NAMES.has(name))continue;checkHstsValue(prop,prop.value,name)}}}}});
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});
@@ -1,81 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walk = walk;
4
- exports.readsPrincipal = readsPrincipal;
5
- exports.isClientRequestMember = isClientRequestMember;
6
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
7
- const PRINCIPAL_PROPERTIES = new Set([
8
- 'user',
9
- 'auth',
10
- 'session',
11
- 'currentUser',
12
- 'principal',
13
- 'identity',
14
- 'userId',
15
- 'authInfo',
16
- ]);
17
- const PRINCIPAL_RECEIVER = /^(req|request|res|response|ctx|locals)$/i;
18
- const CLIENT_CONTAINERS = new Set(['body', 'query', 'params']);
19
- const REQUEST_RECEIVER = /^(req|request)$/i;
20
- function walk(node, visit) {
21
- visit(node);
22
- for (const key of Object.keys(node)) {
23
- if (key === 'parent')
24
- continue;
25
- const value = node[key];
26
- if (Array.isArray(value)) {
27
- for (const item of value) {
28
- if (item && typeof item === 'object' && 'type' in item) {
29
- walk(item, visit);
30
- }
31
- }
32
- continue;
33
- }
34
- if (value && typeof value === 'object' && 'type' in value) {
35
- walk(value, visit);
36
- }
37
- }
38
- }
39
- function readsPrincipal(node) {
40
- let found = false;
41
- walk(node, (child) => {
42
- if (found)
43
- return;
44
- if (child.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
45
- return;
46
- if (child.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
47
- return;
48
- if (!PRINCIPAL_PROPERTIES.has(child.property.name))
49
- return;
50
- const { object } = child;
51
- if (object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
52
- found = PRINCIPAL_RECEIVER.test(object.name);
53
- return;
54
- }
55
- if (object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
56
- object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
57
- found = PRINCIPAL_RECEIVER.test(object.property.name);
58
- }
59
- });
60
- return found;
61
- }
62
- function isClientRequestMember(node) {
63
- if (node.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
64
- return false;
65
- const { object } = node;
66
- if (object.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
67
- return false;
68
- if (object.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
69
- return false;
70
- if (!CLIENT_CONTAINERS.has(object.property.name))
71
- return false;
72
- const root = object.object;
73
- if (root.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
74
- return REQUEST_RECEIVER.test(root.name);
75
- }
76
- if (root.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
77
- root.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
78
- return REQUEST_RECEIVER.test(root.property.name);
79
- }
80
- return false;
81
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.walk=walk;exports.readsPrincipal=readsPrincipal;exports.isClientRequestMember=isClientRequestMember;const eslint_devkit_1=require("@interlace/eslint-devkit");const PRINCIPAL_PROPERTIES=new Set(["user","auth","session","currentUser","principal","identity","userId","authInfo"]);const PRINCIPAL_RECEIVER=/^(req|request|res|response|ctx|locals)$/i;const CLIENT_CONTAINERS=new Set(["body","query","params"]);const REQUEST_RECEIVER=/^(req|request)$/i;function walk(node,visit){visit(node);for(const key of Object.keys(node)){if(key==="parent")continue;const value=node[key];if(Array.isArray(value)){for(const item of value){if(item&&typeof item==="object"&&"type"in item){walk(item,visit)}}continue}if(value&&typeof value==="object"&&"type"in value){walk(value,visit)}}}function readsPrincipal(node){let found=false;walk(node,child=>{if(found)return;if(child.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return;if(child.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return;if(!PRINCIPAL_PROPERTIES.has(child.property.name))return;const{object}=child;if(object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){found=PRINCIPAL_RECEIVER.test(object.name);return}if(object.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&object.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){found=PRINCIPAL_RECEIVER.test(object.property.name)}});return found}function isClientRequestMember(node){if(node.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;const{object}=node;if(object.type!==eslint_devkit_1.AST_NODE_TYPES.MemberExpression)return false;if(object.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return false;if(!CLIENT_CONTAINERS.has(object.property.name))return false;const root=object.object;if(root.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return REQUEST_RECEIVER.test(root.name)}if(root.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&root.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return REQUEST_RECEIVER.test(root.property.name)}return false}