eslint-plugin-browser-security 1.2.13 → 1.3.0

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 (49) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/index.js +1 -159
  4. package/src/oxlint.js +1 -3
  5. package/src/rules/detect-mixed-content/index.js +1 -38
  6. package/src/rules/no-allow-arbitrary-loads/index.js +1 -41
  7. package/src/rules/no-clickjacking/index.js +1 -361
  8. package/src/rules/no-client-side-auth-logic/index.js +1 -67
  9. package/src/rules/no-cookie-auth-tokens/index.js +1 -109
  10. package/src/rules/no-credentials-in-query-params/index.js +1 -55
  11. package/src/rules/no-disabled-certificate-validation/index.js +1 -59
  12. package/src/rules/no-dynamic-service-worker-url/index.js +1 -78
  13. package/src/rules/no-eval/index.js +1 -160
  14. package/src/rules/no-filereader-innerhtml/index.js +1 -196
  15. package/src/rules/no-http-urls/index.js +1 -109
  16. package/src/rules/no-innerhtml/index.js +1 -150
  17. package/src/rules/no-insecure-redirects/index.js +1 -238
  18. package/src/rules/no-insecure-websocket/index.js +1 -57
  19. package/src/rules/no-jwt-in-storage/index.js +1 -178
  20. package/src/rules/no-missing-cors-check/index.js +1 -351
  21. package/src/rules/no-missing-csrf-protection/index.js +1 -165
  22. package/src/rules/no-missing-security-headers/index.js +1 -197
  23. package/src/rules/no-password-in-url/index.js +1 -47
  24. package/src/rules/no-permissive-cors/index.js +1 -65
  25. package/src/rules/no-postmessage-innerhtml/index.js +1 -161
  26. package/src/rules/no-postmessage-wildcard-origin/index.js +1 -112
  27. package/src/rules/no-sensitive-cookie-js/index.js +1 -151
  28. package/src/rules/no-sensitive-data-in-analytics/index.js +1 -58
  29. package/src/rules/no-sensitive-data-in-cache/index.js +1 -47
  30. package/src/rules/no-sensitive-indexeddb/index.js +1 -110
  31. package/src/rules/no-sensitive-localstorage/index.js +1 -173
  32. package/src/rules/no-sensitive-sessionstorage/index.js +1 -144
  33. package/src/rules/no-tracking-without-consent/index.js +1 -65
  34. package/src/rules/no-unencrypted-transmission/index.js +1 -208
  35. package/src/rules/no-unescaped-url-parameter/index.js +1 -319
  36. package/src/rules/no-unsafe-eval-csp/index.js +1 -75
  37. package/src/rules/no-unsafe-inline-csp/index.js +1 -75
  38. package/src/rules/no-unvalidated-deeplinks/index.js +1 -59
  39. package/src/rules/no-websocket-eval/index.js +1 -197
  40. package/src/rules/no-websocket-innerhtml/index.js +1 -185
  41. package/src/rules/no-worker-message-innerhtml/index.js +1 -181
  42. package/src/rules/require-blob-url-revocation/index.js +1 -93
  43. package/src/rules/require-cookie-secure-attrs/index.js +1 -101
  44. package/src/rules/require-csp-headers/index.js +1 -59
  45. package/src/rules/require-https-only/index.js +1 -57
  46. package/src/rules/require-mime-type-validation/index.js +1 -61
  47. package/src/rules/require-postmessage-origin-check/index.js +1 -132
  48. package/src/rules/require-url-validation/index.js +1 -68
  49. package/src/rules/require-websocket-wss/index.js +1 -125
@@ -1,59 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDisabledCertificateValidation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
6
- name: 'no-disabled-certificate-validation',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-disabled-certificate-validation.md',
11
- description: 'Prevent disabled SSL/TLS certificate validation',
12
- cwe: 'CWE-295',
13
- cvss: 9.5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Disabled Certificate Validation',
19
- cwe: 'CWE-295',
20
- description: 'SSL/TLS certificate validation is disabled - man-in-the-middle attack possible',
21
- severity: 'CRITICAL',
22
- fix: 'Remove rejectUnauthorized: false or verify: false, fix certificate issues properly',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/295.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- const dangerousProperties = new Set(['rejectUnauthorized', 'strictSSL', 'verify']);
34
- return {
35
- Property(node) {
36
- if (node.key.type === 'Identifier' &&
37
- dangerousProperties.has(node.key.name) &&
38
- node.value.type === 'Literal' &&
39
- node.value.value === false) {
40
- report(node);
41
- }
42
- },
43
- AssignmentExpression(node) {
44
- if (node.left.type === 'MemberExpression' &&
45
- node.left.object.type === 'MemberExpression' &&
46
- node.left.object.object.type === 'Identifier' &&
47
- node.left.object.object.name === 'process' &&
48
- node.left.object.property.type === 'Identifier' &&
49
- node.left.object.property.name === 'env' &&
50
- node.left.property.type === 'Identifier' &&
51
- node.left.property.name === 'NODE_TLS_REJECT_UNAUTHORIZED') {
52
- if (node.right.type === 'Literal' && node.right.value === '0') {
53
- report(node);
54
- }
55
- }
56
- },
57
- };
58
- },
59
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDisabledCertificateValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noDisabledCertificateValidation=(0,eslint_devkit_1.createRule)({name:"no-disabled-certificate-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-disabled-certificate-validation.md",description:"Prevent disabled SSL/TLS certificate validation",cwe:"CWE-295",cvss:9.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Disabled Certificate Validation",cwe:"CWE-295",description:"SSL/TLS certificate validation is disabled - man-in-the-middle attack possible",severity:"CRITICAL",fix:"Remove rejectUnauthorized: false or verify: false, fix certificate issues properly",documentationLink:"https://cwe.mitre.org/data/definitions/295.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}const dangerousProperties=new Set(["rejectUnauthorized","strictSSL","verify"]);return{Property(node){if(node.key.type==="Identifier"&&dangerousProperties.has(node.key.name)&&node.value.type==="Literal"&&node.value.value===false){report(node)}},AssignmentExpression(node){if(node.left.type==="MemberExpression"&&node.left.object.type==="MemberExpression"&&node.left.object.object.type==="Identifier"&&node.left.object.object.name==="process"&&node.left.object.property.type==="Identifier"&&node.left.object.property.name==="env"&&node.left.property.type==="Identifier"&&node.left.property.name==="NODE_TLS_REJECT_UNAUTHORIZED"){if(node.right.type==="Literal"&&node.right.value==="0"){report(node)}}}}}});
@@ -1,78 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDynamicServiceWorkerUrl = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noDynamicServiceWorkerUrl = (0, eslint_devkit_1.createRule)({
6
- name: 'no-dynamic-service-worker-url',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-dynamic-service-worker-url.md',
11
- description: 'Disallow dynamic URLs in service worker registration',
12
- cwe: 'CWE-829',
13
- cvss: 8.1,
14
- },
15
- hasSuggestions: true,
16
- messages: {
17
- dynamicSwUrl: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Dynamic Service Worker URL',
20
- cwe: 'CWE-829',
21
- owasp: 'A08:2021',
22
- cvss: 8.1,
23
- description: 'Using dynamic URL for service worker registration. A compromised URL could give attacker persistent control over the page.',
24
- severity: 'HIGH',
25
- fix: 'Use a static, hardcoded path for service worker registration.',
26
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register',
27
- }),
28
- useStaticUrl: (0, eslint_devkit_1.formatLLMMessage)({
29
- icon: eslint_devkit_1.MessageIcons.INFO,
30
- issueName: 'Use Static URL',
31
- description: 'Use a static path for service worker',
32
- severity: 'LOW',
33
- fix: "navigator.serviceWorker.register('/sw.js');",
34
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register',
35
- }),
36
- },
37
- schema: [
38
- {
39
- type: 'object',
40
- properties: { allowInTests: { type: 'boolean', default: true } },
41
- additionalProperties: false,
42
- },
43
- ],
44
- },
45
- defaultOptions: [{ allowInTests: true }],
46
- create(context, [options = {}]) {
47
- const { allowInTests = true } = options;
48
- const filename = context.filename;
49
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
50
- if (allowInTests && isTestFile) {
51
- return {};
52
- }
53
- return {
54
- CallExpression(node) {
55
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
56
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
57
- node.callee.property.name === 'register') {
58
- const obj = node.callee.object;
59
- if (obj.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
60
- obj.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
61
- obj.property.name === 'serviceWorker') {
62
- const urlArg = node.arguments[0];
63
- if (!urlArg)
64
- return;
65
- if (urlArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
66
- return;
67
- }
68
- context.report({
69
- node,
70
- messageId: 'dynamicSwUrl',
71
- suggest: [{ messageId: 'useStaticUrl', fix: () => null }],
72
- });
73
- }
74
- }
75
- },
76
- };
77
- },
78
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDynamicServiceWorkerUrl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noDynamicServiceWorkerUrl=(0,eslint_devkit_1.createRule)({name:"no-dynamic-service-worker-url",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-dynamic-service-worker-url.md",description:"Disallow dynamic URLs in service worker registration",cwe:"CWE-829",cvss:8.1},hasSuggestions:true,messages:{dynamicSwUrl:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Dynamic Service Worker URL",cwe:"CWE-829",owasp:"A08:2021",cvss:8.1,description:"Using dynamic URL for service worker registration. A compromised URL could give attacker persistent control over the page.",severity:"HIGH",fix:"Use a static, hardcoded path for service worker registration.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register"}),useStaticUrl:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Static URL",description:"Use a static path for service worker",severity:"LOW",fix:"navigator.serviceWorker.register('/sw.js');",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}return{CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="register"){const obj=node.callee.object;if(obj.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&obj.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&obj.property.name==="serviceWorker"){const urlArg=node.arguments[0];if(!urlArg)return;if(urlArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal){return}context.report({node,messageId:"dynamicSwUrl",suggest:[{messageId:"useStaticUrl",fix:()=>null}]})}}}}}});
@@ -1,160 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noEval = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DANGEROUS_FUNCTIONS = new Set([
6
- 'eval',
7
- 'execScript',
8
- ]);
9
- const DANGEROUS_METHODS_WITH_STRING_ARG = new Set([
10
- 'setTimeout',
11
- 'setInterval',
12
- 'setImmediate',
13
- ]);
14
- exports.noEval = (0, eslint_devkit_1.createRule)({
15
- name: 'no-eval',
16
- meta: {
17
- type: 'problem',
18
- docs: {
19
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-eval.md',
20
- description: 'Disallow eval(), Function(), and other code execution patterns',
21
- cwe: 'CWE-95',
22
- cvss: 9.8,
23
- },
24
- hasSuggestions: true,
25
- messages: {
26
- dangerousEval: (0, eslint_devkit_1.formatLLMMessage)({
27
- icon: eslint_devkit_1.MessageIcons.SECURITY,
28
- issueName: 'Code Injection via {{function}}',
29
- cwe: 'CWE-95',
30
- description: 'Using {{function}} with dynamic input can execute arbitrary code. This is a critical security vulnerability.',
31
- severity: 'CRITICAL',
32
- fix: 'Use safe alternatives like JSON.parse() for data, or refactor to avoid dynamic code execution.',
33
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
34
- }),
35
- useSafeAlternative: (0, eslint_devkit_1.formatLLMMessage)({
36
- icon: eslint_devkit_1.MessageIcons.INFO,
37
- issueName: 'Use Safe Alternative',
38
- description: 'Replace with a safe alternative',
39
- severity: 'LOW',
40
- fix: 'Use JSON.parse() for JSON, or define functions statically.',
41
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!',
42
- }),
43
- },
44
- schema: [
45
- {
46
- type: 'object',
47
- properties: {
48
- allowInTests: {
49
- type: 'boolean',
50
- default: false,
51
- },
52
- allowFunctionConstructor: {
53
- type: 'boolean',
54
- default: false, description: 'Allow `new Function(...)` while still reporting `eval()`'
55
- },
56
- },
57
- additionalProperties: false,
58
- },
59
- ],
60
- },
61
- defaultOptions: [
62
- {
63
- allowInTests: false,
64
- allowFunctionConstructor: false,
65
- },
66
- ],
67
- create(context, [options = {}]) {
68
- const { allowInTests = false, allowFunctionConstructor = false } = options;
69
- const filename = context.filename;
70
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
71
- if (isTestFile) {
72
- return {};
73
- }
74
- return {
75
- CallExpression(node) {
76
- const callee = node.callee;
77
- if (callee.type === 'Identifier') {
78
- if (DANGEROUS_FUNCTIONS.has(callee.name)) {
79
- context.report({
80
- node,
81
- messageId: 'dangerousEval',
82
- data: { function: callee.name },
83
- suggest: [
84
- {
85
- messageId: 'useSafeAlternative',
86
- fix: () => null,
87
- },
88
- ],
89
- });
90
- return;
91
- }
92
- if (DANGEROUS_METHODS_WITH_STRING_ARG.has(callee.name)) {
93
- const firstArg = node.arguments[0];
94
- if (firstArg &&
95
- firstArg.type === 'Literal' &&
96
- typeof firstArg.value === 'string') {
97
- context.report({
98
- node,
99
- messageId: 'dangerousEval',
100
- data: { function: `${callee.name} with string` },
101
- suggest: [
102
- {
103
- messageId: 'useSafeAlternative',
104
- fix: () => null,
105
- },
106
- ],
107
- });
108
- }
109
- }
110
- }
111
- if (callee.type === 'MemberExpression') {
112
- let propertyName = null;
113
- if (!callee.computed &&
114
- callee.property.type === 'Identifier' &&
115
- DANGEROUS_FUNCTIONS.has(callee.property.name)) {
116
- propertyName = callee.property.name;
117
- }
118
- else if (callee.computed &&
119
- callee.property.type === 'Literal' &&
120
- typeof callee.property.value === 'string' &&
121
- DANGEROUS_FUNCTIONS.has(callee.property.value)) {
122
- propertyName = callee.property.value;
123
- }
124
- if (propertyName) {
125
- context.report({
126
- node,
127
- messageId: 'dangerousEval',
128
- data: { function: propertyName },
129
- suggest: [
130
- {
131
- messageId: 'useSafeAlternative',
132
- fix: () => null,
133
- },
134
- ],
135
- });
136
- }
137
- }
138
- },
139
- NewExpression(node) {
140
- if (allowFunctionConstructor) {
141
- return;
142
- }
143
- const callee = node.callee;
144
- if (callee.type === 'Identifier' && callee.name === 'Function') {
145
- context.report({
146
- node,
147
- messageId: 'dangerousEval',
148
- data: { function: 'Function constructor' },
149
- suggest: [
150
- {
151
- messageId: 'useSafeAlternative',
152
- fix: () => null,
153
- },
154
- ],
155
- });
156
- }
157
- },
158
- };
159
- },
160
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noEval=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DANGEROUS_FUNCTIONS=new Set(["eval","execScript"]);const DANGEROUS_METHODS_WITH_STRING_ARG=new Set(["setTimeout","setInterval","setImmediate"]);exports.noEval=(0,eslint_devkit_2.createRule)({name:"no-eval",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-eval.md",description:"Disallow eval(), Function(), and other code execution patterns",cwe:"CWE-95",cvss:9.8},hasSuggestions:true,messages:{dangerousEval:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Code Injection via {{function}}",cwe:"CWE-95",description:"Using {{function}} with dynamic input can execute arbitrary code. This is a critical security vulnerability.",severity:"CRITICAL",fix:"Use safe alternatives like JSON.parse() for data, or refactor to avoid dynamic code execution.",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useSafeAlternative:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Safe Alternative",description:"Replace with a safe alternative",severity:"LOW",fix:"Use JSON.parse() for JSON, or define functions statically.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false},allowFunctionConstructor:{type:"boolean",default:false,description:"Allow `new Function(...)` while still reporting `eval()`"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,allowFunctionConstructor:false}],create(context,[options={}]){const{allowInTests=false,allowFunctionConstructor=false}=options;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{CallExpression(node){const callee=node.callee;if(node.arguments.some(arg=>payloadSource(arg)==="websocket"))return;if(callee.type==="Identifier"){if(DANGEROUS_FUNCTIONS.has(callee.name)){context.report({node,messageId:"dangerousEval",data:{function:callee.name},suggest:[{messageId:"useSafeAlternative",fix:()=>null}]});return}if(DANGEROUS_METHODS_WITH_STRING_ARG.has(callee.name)){const firstArg=node.arguments[0];if(firstArg&&firstArg.type==="Literal"&&typeof firstArg.value==="string"){context.report({node,messageId:"dangerousEval",data:{function:`${callee.name} with string`},suggest:[{messageId:"useSafeAlternative",fix:()=>null}]})}}}if(callee.type==="MemberExpression"){let propertyName=null;if(!callee.computed&&callee.property.type==="Identifier"&&DANGEROUS_FUNCTIONS.has(callee.property.name)){propertyName=callee.property.name}else if(callee.computed&&callee.property.type==="Literal"&&typeof callee.property.value==="string"&&DANGEROUS_FUNCTIONS.has(callee.property.value)){propertyName=callee.property.value}if(propertyName){context.report({node,messageId:"dangerousEval",data:{function:propertyName},suggest:[{messageId:"useSafeAlternative",fix:()=>null}]})}}},NewExpression(node){if(node.arguments.some(arg=>payloadSource(arg)==="websocket"))return;if(allowFunctionConstructor){return}const callee=node.callee;if(callee.type==="Identifier"&&callee.name==="Function"){context.report({node,messageId:"dangerousEval",data:{function:"Function constructor"},suggest:[{messageId:"useSafeAlternative",fix:()=>null}]})}}}}});
@@ -1,196 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noFilereaderInnerhtml = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const DANGEROUS_PROPERTIES = new Set(['innerHTML', 'outerHTML']);
6
- const DANGEROUS_METHODS = new Set(['insertAdjacentHTML', 'write', 'writeln']);
7
- exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
8
- name: 'no-filereader-innerhtml',
9
- meta: {
10
- type: 'problem',
11
- docs: {
12
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-filereader-innerhtml.md',
13
- description: 'Disallow using innerHTML or similar methods with FileReader data',
14
- cwe: 'CWE-79',
15
- cvss: 8.1,
16
- },
17
- hasSuggestions: true,
18
- messages: {
19
- unsafeInnerhtml: (0, eslint_devkit_1.formatLLMMessage)({
20
- icon: eslint_devkit_1.MessageIcons.SECURITY,
21
- issueName: 'XSS via File Upload',
22
- cwe: 'CWE-79',
23
- owasp: 'A03:2021',
24
- cvss: 8.1,
25
- description: 'Using {{method}} with FileReader result enables XSS attacks. Malicious files can contain scripts that execute when rendered.',
26
- severity: 'HIGH',
27
- fix: 'Sanitize file content with DOMPurify before rendering, or use textContent for plain text.',
28
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/FileReader',
29
- }),
30
- sanitizeContent: (0, eslint_devkit_1.formatLLMMessage)({
31
- icon: eslint_devkit_1.MessageIcons.INFO,
32
- issueName: 'Sanitize File Content',
33
- description: 'Use textContent or sanitize with DOMPurify',
34
- severity: 'LOW',
35
- fix: 'const sanitized = DOMPurify.sanitize(e.target.result);\nelement.innerHTML = sanitized;',
36
- documentationLink: 'https://github.com/cure53/DOMPurify',
37
- }),
38
- },
39
- schema: [
40
- {
41
- type: 'object',
42
- properties: {
43
- allowInTests: {
44
- type: 'boolean',
45
- default: true,
46
- },
47
- },
48
- additionalProperties: false,
49
- },
50
- ],
51
- },
52
- defaultOptions: [{ allowInTests: true }],
53
- create(context, [options = {}]) {
54
- const { allowInTests = true } = options;
55
- const filename = context.filename;
56
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
57
- if (allowInTests && isTestFile) {
58
- return {};
59
- }
60
- let inFileReaderHandler = false;
61
- let eventParamName = null;
62
- function isFileReaderOnloadAssignment(node) {
63
- if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
64
- node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
65
- (node.left.property.name === 'onload' ||
66
- node.left.property.name === 'onloadend')) {
67
- const objName = node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
68
- ? node.left.object.name.toLowerCase()
69
- : '';
70
- if (objName.includes('reader') ||
71
- objName.includes('fr') ||
72
- objName === 'r') {
73
- const handler = node.right;
74
- if (handler.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression ||
75
- handler.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression) {
76
- const firstParam = handler.params[0];
77
- if (firstParam && firstParam.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
78
- return { isHandler: true, eventParam: firstParam.name };
79
- }
80
- }
81
- }
82
- }
83
- return { isHandler: false, eventParam: null };
84
- }
85
- function isFileReaderAddEventListener(node) {
86
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
87
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
88
- node.callee.property.name === 'addEventListener' &&
89
- node.arguments.length >= 2) {
90
- const eventType = node.arguments[0];
91
- if (eventType.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
92
- (eventType.value === 'load' || eventType.value === 'loadend')) {
93
- const callback = node.arguments[1];
94
- if (callback.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression ||
95
- callback.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression) {
96
- const firstParam = callback.params[0];
97
- if (firstParam && firstParam.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
98
- return { isHandler: true, eventParam: firstParam.name };
99
- }
100
- }
101
- }
102
- }
103
- return { isHandler: false, eventParam: null };
104
- }
105
- function referencesFileReaderResult(node, eventName) {
106
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
107
- if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
108
- node.property.name === 'result' &&
109
- node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
110
- node.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
111
- node.object.property.name === 'target' &&
112
- node.object.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
113
- node.object.object.name === eventName) {
114
- return true;
115
- }
116
- return referencesFileReaderResult(node.object, eventName);
117
- }
118
- return false;
119
- }
120
- return {
121
- AssignmentExpression(node) {
122
- const { isHandler, eventParam } = isFileReaderOnloadAssignment(node);
123
- if (isHandler) {
124
- inFileReaderHandler = true;
125
- eventParamName = eventParam;
126
- }
127
- if (!inFileReaderHandler || !eventParamName)
128
- return;
129
- if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
130
- node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
131
- DANGEROUS_PROPERTIES.has(node.left.property.name)) {
132
- if (referencesFileReaderResult(node.right, eventParamName)) {
133
- context.report({
134
- node,
135
- messageId: 'unsafeInnerhtml',
136
- data: {
137
- method: node.left.property.name,
138
- },
139
- suggest: [
140
- {
141
- messageId: 'sanitizeContent',
142
- fix: () => null,
143
- },
144
- ],
145
- });
146
- }
147
- }
148
- },
149
- 'AssignmentExpression:exit'(node) {
150
- const { isHandler } = isFileReaderOnloadAssignment(node);
151
- if (isHandler) {
152
- inFileReaderHandler = false;
153
- eventParamName = null;
154
- }
155
- },
156
- CallExpression(node) {
157
- const { isHandler, eventParam } = isFileReaderAddEventListener(node);
158
- if (isHandler) {
159
- inFileReaderHandler = true;
160
- eventParamName = eventParam;
161
- }
162
- if (!inFileReaderHandler || !eventParamName)
163
- return;
164
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
165
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
166
- DANGEROUS_METHODS.has(node.callee.property.name)) {
167
- for (const arg of node.arguments) {
168
- if (referencesFileReaderResult(arg, eventParamName)) {
169
- context.report({
170
- node,
171
- messageId: 'unsafeInnerhtml',
172
- data: {
173
- method: node.callee.property.name,
174
- },
175
- suggest: [
176
- {
177
- messageId: 'sanitizeContent',
178
- fix: () => null,
179
- },
180
- ],
181
- });
182
- break;
183
- }
184
- }
185
- }
186
- },
187
- 'CallExpression:exit'(node) {
188
- const { isHandler } = isFileReaderAddEventListener(node);
189
- if (isHandler) {
190
- inFileReaderHandler = false;
191
- eventParamName = null;
192
- }
193
- },
194
- };
195
- },
196
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noFilereaderInnerhtml=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const DANGEROUS_PROPERTIES=new Set(["innerHTML","outerHTML"]);const DANGEROUS_METHODS=new Set(["insertAdjacentHTML","write","writeln"]);function readsFileReaderResult(node){let current=node;while(current.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if(current.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&current.property.name==="result"){const owner=current.object;if(owner.type===eslint_devkit_1.AST_NODE_TYPES.Identifier)return true;return owner.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&owner.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&owner.property.name==="target"&&owner.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier}current=current.object}return false}exports.noFilereaderInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-filereader-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-filereader-innerhtml.md",description:"Disallow using innerHTML or similar methods with FileReader data",cwe:"CWE-79",cvss:8.1},hasSuggestions:true,messages:{unsafeInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via File Upload",cwe:"CWE-79",owasp:"A03:2021",cvss:8.1,description:"Using {{method}} with FileReader result enables XSS attacks. Malicious files can contain scripts that execute when rendered.",severity:"HIGH",fix:"Sanitize file content with DOMPurify before rendering, or use textContent for plain text.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/FileReader"}),sanitizeContent:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Sanitize File Content",description:"Use textContent or sanitize with DOMPurify",severity:"LOW",fix:"const sanitized = DOMPurify.sanitize(e.target.result);\nelement.innerHTML = sanitized;",documentationLink:"https://github.com/cure53/DOMPurify"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowInTests:true}],create(context,[options={}]){const{allowInTests=true}=options;const filename=context.filename;const isTestFile=/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(allowInTests&&isTestFile){return{}}function isFileReaderOnloadAssignment(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(node.left.property.name==="onload"||node.left.property.name==="onloadend")){const handler=node.right;if(handler.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||handler.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression){const firstParam=handler.params[0];if(firstParam&&firstParam.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return{isHandler:true,eventParam:firstParam.name}}}}return{isHandler:false,eventParam:null}}function isFileReaderAddEventListener(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="addEventListener"&&node.arguments.length>=2){const eventType=node.arguments[0];if(eventType.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&(eventType.value==="load"||eventType.value==="loadend")){const callback=node.arguments[1];if(callback.type===eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression||callback.type===eslint_devkit_1.AST_NODE_TYPES.FunctionExpression){const firstParam=callback.params[0];if(firstParam&&firstParam.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){return{isHandler:true,eventParam:firstParam.name}}}}}return{isHandler:false,eventParam:null}}const payloadSource=(0,eslint_devkit_1.createPayloadResolver)(context.sourceCode);return{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_PROPERTIES.has(node.left.property.name)){if(payloadSource(node.right)==="filereader"&&readsFileReaderResult(node.right)){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.left.property.name},suggest:[{messageId:"sanitizeContent",fix:()=>null}]})}}},"AssignmentExpression:exit"(node){const{isHandler}=isFileReaderOnloadAssignment(node);if(isHandler){}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&DANGEROUS_METHODS.has(node.callee.property.name)){for(const arg of node.arguments){if(payloadSource(arg)==="filereader"&&readsFileReaderResult(arg)){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.callee.property.name},suggest:[{messageId:"sanitizeContent",fix:()=>null}]});break}}}},"CallExpression:exit"(node){const{isHandler}=isFileReaderAddEventListener(node);if(isHandler){}}}}});
@@ -1,109 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noHttpUrls = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noHttpUrls = (0, eslint_devkit_1.createRule)({
6
- name: 'no-http-urls',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-http-urls.md',
11
- description: 'Disallow hardcoded HTTP URLs (require HTTPS)',
12
- cwe: 'CWE-319',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- insecureHttp: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Insecure HTTP URL',
19
- cwe: 'CWE-319',
20
- owasp: 'A02:2021',
21
- cvss: 7.5,
22
- description: 'Hardcoded HTTP URL detected: "{{url}}"',
23
- severity: 'HIGH',
24
- compliance: ['SOC2', 'PCI-DSS', 'HIPAA'],
25
- fix: 'Use HTTPS instead: const url = "https://..."',
26
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
27
- }),
28
- insecureHttpWithException: (0, eslint_devkit_1.formatLLMMessage)({
29
- icon: eslint_devkit_1.MessageIcons.WARNING,
30
- issueName: 'Insecure HTTP URL',
31
- cwe: 'CWE-319',
32
- owasp: 'A02:2021',
33
- cvss: 5.3,
34
- description: 'HTTP URL detected: "{{url}}"',
35
- severity: 'MEDIUM',
36
- fix: 'Use HTTPS or add to allowedHosts config',
37
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
38
- }),
39
- },
40
- schema: [
41
- {
42
- type: 'object',
43
- properties: {
44
- allowedHosts: {
45
- type: 'array',
46
- items: { type: 'string' },
47
- description: 'List of hostnames allowed to use HTTP (e.g., localhost, 127.0.0.1)',
48
- },
49
- allowedPorts: {
50
- type: 'array',
51
- items: { type: 'number' },
52
- description: 'List of ports allowed for HTTP (e.g., 3000, 8080 for development)',
53
- },
54
- },
55
- additionalProperties: false,
56
- },
57
- ],
58
- },
59
- defaultOptions: [
60
- {
61
- allowedHosts: ['localhost', '127.0.0.1'],
62
- allowedPorts: [],
63
- },
64
- ],
65
- create(context) {
66
- const [options = {}] = context.options;
67
- const allowedHosts = options.allowedHosts ?? ['localhost', '127.0.0.1'];
68
- const allowedPorts = options.allowedPorts ?? [];
69
- function isAllowedException(url) {
70
- try {
71
- const parsedUrl = new URL(url);
72
- if (allowedHosts.includes(parsedUrl.hostname)) {
73
- return true;
74
- }
75
- if (parsedUrl.port && allowedPorts.includes(parseInt(parsedUrl.port, 10))) {
76
- return true;
77
- }
78
- return false;
79
- }
80
- catch {
81
- return allowedHosts.some(host => url.includes(host));
82
- }
83
- }
84
- function checkStringValue(node, value) {
85
- const httpPattern = /^http:\/\//i;
86
- if (httpPattern.test(value) && !isAllowedException(value)) {
87
- context.report({
88
- node,
89
- messageId: allowedHosts.length > 0 || allowedPorts.length > 0
90
- ? 'insecureHttpWithException'
91
- : 'insecureHttp',
92
- data: { url: value },
93
- });
94
- }
95
- }
96
- return {
97
- Literal(node) {
98
- if (typeof node.value === 'string') {
99
- checkStringValue(node, node.value);
100
- }
101
- },
102
- TemplateElement(node) {
103
- if (node.value.cooked) {
104
- checkStringValue(node, node.value.cooked);
105
- }
106
- },
107
- };
108
- },
109
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHttpUrls=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noHttpUrls=(0,eslint_devkit_1.createRule)({name:"no-http-urls",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-http-urls.md",description:"Disallow hardcoded HTTP URLs (require HTTPS)",cwe:"CWE-319",cvss:7.5},messages:{insecureHttp:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:7.5,description:'Hardcoded HTTP URL detected: "{{url}}"',severity:"HIGH",compliance:["SOC2","PCI-DSS","HIPAA"],fix:'Use HTTPS instead: const url = "https://..."',documentationLink:"https://cwe.mitre.org/data/definitions/319.html"}),insecureHttpWithException:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Insecure HTTP URL",cwe:"CWE-319",owasp:"A02:2021",cvss:5.3,description:'HTTP URL detected: "{{url}}"',severity:"MEDIUM",fix:"Use HTTPS or add to allowedHosts config",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"})},schema:[{type:"object",properties:{allowedHosts:{type:"array",items:{type:"string"},description:"List of hostnames allowed to use HTTP (e.g., localhost, 127.0.0.1)"},allowedPorts:{type:"array",items:{type:"number"},description:"List of ports allowed for HTTP (e.g., 3000, 8080 for development)"}},additionalProperties:false}]},defaultOptions:[{allowedHosts:["localhost","127.0.0.1"],allowedPorts:[]}],create(context){const[options={}]=context.options;const allowedHosts=options.allowedHosts??["localhost","127.0.0.1"];const allowedPorts=options.allowedPorts??[];function isAllowedException(url){try{const parsedUrl=new URL(url);if(allowedHosts.includes(parsedUrl.hostname)){return true}if(parsedUrl.port&&allowedPorts.includes(parseInt(parsedUrl.port,10))){return true}return false}catch{return allowedHosts.some(host=>url.includes(host))}}function checkStringValue(node,value){const httpPattern=/^http:\/\//i;if(httpPattern.test(value)&&!isAllowedException(value)){context.report({node,messageId:allowedHosts.length>0||allowedPorts.length>0?"insecureHttpWithException":"insecureHttp",data:{url:value}})}}return{Literal(node){if(typeof node.value==="string"){checkStringValue(node,node.value)}},TemplateElement(node){if(node.value.cooked){checkStringValue(node,node.value.cooked)}}}}});