eslint-plugin-browser-security 1.2.13 → 1.2.14

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 (48) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -159
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/detect-mixed-content/index.js +1 -38
  5. package/src/rules/no-allow-arbitrary-loads/index.js +1 -41
  6. package/src/rules/no-clickjacking/index.js +1 -361
  7. package/src/rules/no-client-side-auth-logic/index.js +1 -67
  8. package/src/rules/no-cookie-auth-tokens/index.js +1 -109
  9. package/src/rules/no-credentials-in-query-params/index.js +1 -55
  10. package/src/rules/no-disabled-certificate-validation/index.js +1 -59
  11. package/src/rules/no-dynamic-service-worker-url/index.js +1 -78
  12. package/src/rules/no-eval/index.js +1 -160
  13. package/src/rules/no-filereader-innerhtml/index.js +1 -196
  14. package/src/rules/no-http-urls/index.js +1 -109
  15. package/src/rules/no-innerhtml/index.js +1 -150
  16. package/src/rules/no-insecure-redirects/index.js +1 -238
  17. package/src/rules/no-insecure-websocket/index.js +1 -57
  18. package/src/rules/no-jwt-in-storage/index.js +1 -178
  19. package/src/rules/no-missing-cors-check/index.js +1 -351
  20. package/src/rules/no-missing-csrf-protection/index.js +1 -165
  21. package/src/rules/no-missing-security-headers/index.js +1 -197
  22. package/src/rules/no-password-in-url/index.js +1 -47
  23. package/src/rules/no-permissive-cors/index.js +1 -65
  24. package/src/rules/no-postmessage-innerhtml/index.js +1 -161
  25. package/src/rules/no-postmessage-wildcard-origin/index.js +1 -112
  26. package/src/rules/no-sensitive-cookie-js/index.js +1 -151
  27. package/src/rules/no-sensitive-data-in-analytics/index.js +1 -58
  28. package/src/rules/no-sensitive-data-in-cache/index.js +1 -47
  29. package/src/rules/no-sensitive-indexeddb/index.js +1 -110
  30. package/src/rules/no-sensitive-localstorage/index.js +1 -173
  31. package/src/rules/no-sensitive-sessionstorage/index.js +1 -144
  32. package/src/rules/no-tracking-without-consent/index.js +1 -65
  33. package/src/rules/no-unencrypted-transmission/index.js +1 -208
  34. package/src/rules/no-unescaped-url-parameter/index.js +1 -319
  35. package/src/rules/no-unsafe-eval-csp/index.js +1 -75
  36. package/src/rules/no-unsafe-inline-csp/index.js +1 -75
  37. package/src/rules/no-unvalidated-deeplinks/index.js +1 -59
  38. package/src/rules/no-websocket-eval/index.js +1 -197
  39. package/src/rules/no-websocket-innerhtml/index.js +1 -185
  40. package/src/rules/no-worker-message-innerhtml/index.js +1 -181
  41. package/src/rules/require-blob-url-revocation/index.js +1 -93
  42. package/src/rules/require-cookie-secure-attrs/index.js +1 -101
  43. package/src/rules/require-csp-headers/index.js +1 -59
  44. package/src/rules/require-https-only/index.js +1 -57
  45. package/src/rules/require-mime-type-validation/index.js +1 -61
  46. package/src/rules/require-postmessage-origin-check/index.js +1 -132
  47. package/src/rules/require-url-validation/index.js +1 -68
  48. package/src/rules/require-websocket-wss/index.js +1 -125
@@ -1,93 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireBlobUrlRevocation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.requireBlobUrlRevocation = (0, eslint_devkit_1.createRule)({
6
- name: 'require-blob-url-revocation',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-blob-url-revocation.md',
11
- description: 'Require revoking Blob URLs to prevent memory leaks',
12
- cwe: 'CWE-401',
13
- cvss: 5.3,
14
- },
15
- hasSuggestions: true,
16
- messages: {
17
- missingRevoke: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Blob URL Memory Leak',
20
- cwe: 'CWE-401',
21
- owasp: 'A06:2021',
22
- cvss: 5.3,
23
- description: 'URL.createObjectURL() creates a reference that persists until explicitly revoked. Without revokeObjectURL(), memory leaks occur.',
24
- severity: 'MEDIUM',
25
- fix: 'Call URL.revokeObjectURL(blobUrl) when the URL is no longer needed.',
26
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL',
27
- }),
28
- addRevocation: (0, eslint_devkit_1.formatLLMMessage)({
29
- icon: eslint_devkit_1.MessageIcons.INFO,
30
- issueName: 'Add URL Revocation',
31
- description: 'Revoke the Blob URL after use',
32
- severity: 'LOW',
33
- fix: 'URL.revokeObjectURL(blobUrl);',
34
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL',
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
- const createdUrls = new Map();
54
- const revokedUrls = new Set();
55
- return {
56
- CallExpression(node) {
57
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
58
- node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
59
- node.callee.object.name === 'URL' &&
60
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
61
- node.callee.property.name === 'createObjectURL') {
62
- const parent = node.parent;
63
- if (parent &&
64
- parent.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator &&
65
- parent.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
66
- createdUrls.set(parent.id.name, parent);
67
- }
68
- }
69
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
70
- node.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
71
- node.callee.object.name === 'URL' &&
72
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
73
- node.callee.property.name === 'revokeObjectURL') {
74
- const arg = node.arguments[0];
75
- if (arg && arg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
76
- revokedUrls.add(arg.name);
77
- }
78
- }
79
- },
80
- 'Program:exit'() {
81
- for (const [urlVar, declaratorNode] of createdUrls) {
82
- if (!revokedUrls.has(urlVar)) {
83
- context.report({
84
- node: declaratorNode,
85
- messageId: 'missingRevoke',
86
- suggest: [{ messageId: 'addRevocation', fix: () => null }],
87
- });
88
- }
89
- }
90
- },
91
- };
92
- },
93
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireBlobUrlRevocation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.requireBlobUrlRevocation=(0,eslint_devkit_1.createRule)({name:"require-blob-url-revocation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-blob-url-revocation.md",description:"Require revoking Blob URLs to prevent memory leaks",cwe:"CWE-401",cvss:5.3},hasSuggestions:true,messages:{missingRevoke:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Blob URL Memory Leak",cwe:"CWE-401",owasp:"A06:2021",cvss:5.3,description:"URL.createObjectURL() creates a reference that persists until explicitly revoked. Without revokeObjectURL(), memory leaks occur.",severity:"MEDIUM",fix:"Call URL.revokeObjectURL(blobUrl) when the URL is no longer needed.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL"}),addRevocation:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add URL Revocation",description:"Revoke the Blob URL after use",severity:"LOW",fix:"URL.revokeObjectURL(blobUrl);",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL"})},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{}}const createdUrls=new Map;const revokedUrls=new Set;return{CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="URL"&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="createObjectURL"){const parent=node.parent;if(parent&&parent.type===eslint_devkit_1.AST_NODE_TYPES.VariableDeclarator&&parent.id.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){createdUrls.set(parent.id.name,parent)}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.object.name==="URL"&&node.callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.property.name==="revokeObjectURL"){const arg=node.arguments[0];if(arg&&arg.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){revokedUrls.add(arg.name)}}},"Program:exit"(){for(const[urlVar,declaratorNode]of createdUrls){if(!revokedUrls.has(urlVar)){context.report({node:declaratorNode,messageId:"missingRevoke",suggest:[{messageId:"addRevocation",fix:()=>null}]})}}}}}});
@@ -1,101 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireCookieSecureAttrs = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.requireCookieSecureAttrs = (0, eslint_devkit_1.createRule)({
6
- name: 'require-cookie-secure-attrs',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-cookie-secure-attrs.md',
11
- description: 'Require Secure and SameSite attributes when setting cookies',
12
- cwe: 'CWE-614',
13
- cvss: 6.5,
14
- },
15
- hasSuggestions: true,
16
- messages: {
17
- missingSecure: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'Cookie Missing Secure Attribute',
20
- cwe: 'CWE-614',
21
- owasp: 'A02:2021',
22
- cvss: 6.5,
23
- description: 'Cookie set without Secure attribute. It will be sent over unencrypted HTTP connections.',
24
- severity: 'MEDIUM',
25
- fix: 'Add Secure attribute: document.cookie = "name=value; Secure; SameSite=Strict"',
26
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies',
27
- }),
28
- missingSameSite: (0, eslint_devkit_1.formatLLMMessage)({
29
- icon: eslint_devkit_1.MessageIcons.SECURITY,
30
- issueName: 'Cookie Missing SameSite Attribute',
31
- cwe: 'CWE-352',
32
- owasp: 'A01:2021',
33
- cvss: 6.5,
34
- description: 'Cookie set without SameSite attribute. It may be vulnerable to CSRF attacks.',
35
- severity: 'MEDIUM',
36
- fix: 'Add SameSite attribute: document.cookie = "name=value; SameSite=Strict"',
37
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite',
38
- }),
39
- addSecureAttrs: (0, eslint_devkit_1.formatLLMMessage)({
40
- icon: eslint_devkit_1.MessageIcons.INFO,
41
- issueName: 'Add Secure Attributes',
42
- description: 'Add Secure and SameSite attributes',
43
- severity: 'LOW',
44
- fix: 'document.cookie = "name=value; Secure; SameSite=Strict"',
45
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security',
46
- }),
47
- },
48
- schema: [
49
- {
50
- type: 'object',
51
- properties: { allowInTests: { type: 'boolean', default: true } },
52
- additionalProperties: false,
53
- },
54
- ],
55
- },
56
- defaultOptions: [{ allowInTests: true }],
57
- create(context, [options = {}]) {
58
- const { allowInTests = true } = options;
59
- const filename = context.filename;
60
- const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
61
- if (allowInTests && isTestFile) {
62
- return {};
63
- }
64
- return {
65
- AssignmentExpression(node) {
66
- if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
67
- node.left.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
68
- node.left.object.name === 'document' &&
69
- node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
70
- node.left.property.name === 'cookie') {
71
- let cookieValue = '';
72
- if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
73
- typeof node.right.value === 'string') {
74
- cookieValue = node.right.value;
75
- }
76
- else if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral) {
77
- cookieValue = node.right.quasis.map((q) => q.value.raw).join('');
78
- }
79
- if (!cookieValue)
80
- return;
81
- const hasSecure = /;\s*secure/i.test(cookieValue);
82
- const hasSameSite = /;\s*samesite/i.test(cookieValue);
83
- if (!hasSecure) {
84
- context.report({
85
- node,
86
- messageId: 'missingSecure',
87
- suggest: [{ messageId: 'addSecureAttrs', fix: () => null }],
88
- });
89
- }
90
- if (!hasSameSite) {
91
- context.report({
92
- node,
93
- messageId: 'missingSameSite',
94
- suggest: [{ messageId: 'addSecureAttrs', fix: () => null }],
95
- });
96
- }
97
- }
98
- },
99
- };
100
- },
101
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireCookieSecureAttrs=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.requireCookieSecureAttrs=(0,eslint_devkit_1.createRule)({name:"require-cookie-secure-attrs",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-cookie-secure-attrs.md",description:"Require Secure and SameSite attributes when setting cookies",cwe:"CWE-614",cvss:6.5},hasSuggestions:true,messages:{missingSecure:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Cookie Missing Secure Attribute",cwe:"CWE-614",owasp:"A02:2021",cvss:6.5,description:"Cookie set without Secure attribute. It will be sent over unencrypted HTTP connections.",severity:"MEDIUM",fix:'Add Secure attribute: document.cookie = "name=value; Secure; SameSite=Strict"',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies"}),missingSameSite:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Cookie Missing SameSite Attribute",cwe:"CWE-352",owasp:"A01:2021",cvss:6.5,description:"Cookie set without SameSite attribute. It may be vulnerable to CSRF attacks.",severity:"MEDIUM",fix:'Add SameSite attribute: document.cookie = "name=value; SameSite=Strict"',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"}),addSecureAttrs:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Secure Attributes",description:"Add Secure and SameSite attributes",severity:"LOW",fix:'document.cookie = "name=value; Secure; SameSite=Strict"',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#security"})},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{AssignmentExpression(node){if(node.left.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&node.left.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.object.name==="document"&&node.left.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.left.property.name==="cookie"){let cookieValue="";if(node.right.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof node.right.value==="string"){cookieValue=node.right.value}else if(node.right.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral){cookieValue=node.right.quasis.map(q=>q.value.raw).join("")}if(!cookieValue)return;const hasSecure=/;\s*secure/i.test(cookieValue);const hasSameSite=/;\s*samesite/i.test(cookieValue);if(!hasSecure){context.report({node,messageId:"missingSecure",suggest:[{messageId:"addSecureAttrs",fix:()=>null}]})}if(!hasSameSite){context.report({node,messageId:"missingSameSite",suggest:[{messageId:"addSecureAttrs",fix:()=>null}]})}}}}}});
@@ -1,59 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireCspHeaders = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.requireCspHeaders = (0, eslint_devkit_1.createRule)({
6
- name: 'require-csp-headers',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-csp-headers.md',
11
- description: 'Require Content Security Policy headers',
12
- cwe: 'CWE-1021',
13
- cvss: 5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Missing CSP',
19
- cwe: 'CWE-1021',
20
- description: 'HTML response without Content-Security-Policy header',
21
- severity: 'MEDIUM',
22
- fix: 'Use helmet.contentSecurityPolicy() or set CSP header manually',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/1021.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- return {
34
- CallExpression(node) {
35
- if (node.callee.type === 'MemberExpression' &&
36
- node.callee.property.type === 'Identifier' &&
37
- node.callee.property.name === 'send') {
38
- const arg = node.arguments[0];
39
- if (arg && arg.type === 'TemplateLiteral') {
40
- const quasi = arg.quasis[0]?.value?.raw || '';
41
- if (quasi.includes('<html') || quasi.includes('<!DOCTYPE')) {
42
- report(node);
43
- }
44
- }
45
- if (arg && arg.type === 'Literal' && typeof arg.value === 'string') {
46
- if (arg.value.includes('<html') || arg.value.includes('<!DOCTYPE')) {
47
- report(node);
48
- }
49
- }
50
- }
51
- if (node.callee.type === 'MemberExpression' &&
52
- node.callee.property.type === 'Identifier' &&
53
- node.callee.property.name === 'render') {
54
- report(node);
55
- }
56
- },
57
- };
58
- },
59
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireCspHeaders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.requireCspHeaders=(0,eslint_devkit_1.createRule)({name:"require-csp-headers",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-csp-headers.md",description:"Require Content Security Policy headers",cwe:"CWE-1021",cvss:5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing CSP",cwe:"CWE-1021",description:"HTML response without Content-Security-Policy header",severity:"MEDIUM",fix:"Use helmet.contentSecurityPolicy() or set CSP header manually",documentationLink:"https://cwe.mitre.org/data/definitions/1021.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="send"){const arg=node.arguments[0];if(arg&&arg.type==="TemplateLiteral"){const quasi=arg.quasis[0]?.value?.raw||"";if(quasi.includes("<html")||quasi.includes("<!DOCTYPE")){report(node)}}if(arg&&arg.type==="Literal"&&typeof arg.value==="string"){if(arg.value.includes("<html")||arg.value.includes("<!DOCTYPE")){report(node)}}}if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="render"){report(node)}}}}});
@@ -1,57 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireHttpsOnly = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const AXIOS_HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
6
- exports.requireHttpsOnly = (0, eslint_devkit_1.createRule)({
7
- name: 'require-https-only',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-https-only.md',
12
- description: 'Enforce HTTPS for all external requests',
13
- cwe: 'CWE-319',
14
- cvss: 7.5,
15
- },
16
- messages: {
17
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
18
- icon: eslint_devkit_1.MessageIcons.SECURITY,
19
- issueName: 'violation Detected',
20
- cwe: 'CWE-319',
21
- description: 'Enforce HTTPS for all external requests detected - this is a security risk',
22
- severity: 'HIGH',
23
- fix: 'Review and apply secure practices',
24
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
25
- })
26
- },
27
- schema: [],
28
- },
29
- defaultOptions: [],
30
- create(context) {
31
- function report(node) {
32
- context.report({
33
- node,
34
- messageId: 'violationDetected',
35
- });
36
- }
37
- return {
38
- CallExpression(node) {
39
- const callee = node.callee;
40
- const isFetch = callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && callee.name === 'fetch';
41
- const isAxios = callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
42
- callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
43
- callee.object.name === 'axios' &&
44
- callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
45
- AXIOS_HTTP_METHODS.includes(callee.property.name);
46
- if ((isFetch || isAxios) && node.arguments[0]) {
47
- const url = node.arguments[0];
48
- if (url.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
49
- typeof url.value === 'string' &&
50
- url.value.startsWith('http://')) {
51
- report(node);
52
- }
53
- }
54
- },
55
- };
56
- },
57
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireHttpsOnly=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const AXIOS_HTTP_METHODS=["get","post","put","delete","patch","head","options"];exports.requireHttpsOnly=(0,eslint_devkit_1.createRule)({name:"require-https-only",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-https-only.md",description:"Enforce HTTPS for all external requests",cwe:"CWE-319",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-319",description:"Enforce HTTPS for all external requests detected - this is a security risk",severity:"HIGH",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/319.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{CallExpression(node){const callee=node.callee;const isFetch=callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.name==="fetch";const isAxios=callee.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&callee.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&callee.object.name==="axios"&&callee.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&AXIOS_HTTP_METHODS.includes(callee.property.name);if((isFetch||isAxios)&&node.arguments[0]){const url=node.arguments[0];if(url.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&typeof url.value==="string"&&url.value.startsWith("http://")){report(node)}}}}}});
@@ -1,61 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireMimeTypeValidation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.requireMimeTypeValidation = (0, eslint_devkit_1.createRule)({
6
- name: 'require-mime-type-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/require-mime-type-validation.md',
11
- description: 'Require MIME type validation for file uploads',
12
- cwe: 'CWE-434',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Missing MIME Validation',
19
- cwe: 'CWE-434',
20
- description: 'File upload without MIME type validation - unrestricted upload vulnerability',
21
- severity: 'HIGH',
22
- fix: 'Add fileFilter option to validate MIME types',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/434.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- return {
34
- CallExpression(node) {
35
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
36
- node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
37
- ['single', 'array', 'fields'].includes(node.callee.property.name)) {
38
- const calleeObj = node.callee.object;
39
- if (calleeObj.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
40
- const multerArgs = calleeObj.arguments[0];
41
- if (multerArgs && multerArgs.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
42
- const hasFileFilter = multerArgs.properties.some((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Property && p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && (p.key.name === 'fileFilter' || p.key.name === 'limits'));
43
- if (!hasFileFilter) {
44
- report(node);
45
- }
46
- }
47
- else if (!multerArgs) {
48
- report(node);
49
- }
50
- }
51
- }
52
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.callee.name === 'upload') {
53
- if (node.arguments.length === 0 ||
54
- (node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.Identifier)) {
55
- report(node);
56
- }
57
- }
58
- },
59
- };
60
- },
61
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireMimeTypeValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.requireMimeTypeValidation=(0,eslint_devkit_1.createRule)({name:"require-mime-type-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-mime-type-validation.md",description:"Require MIME type validation for file uploads",cwe:"CWE-434",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing MIME Validation",cwe:"CWE-434",description:"File upload without MIME type validation - unrestricted upload vulnerability",severity:"HIGH",fix:"Add fileFilter option to validate MIME types",documentationLink:"https://cwe.mitre.org/data/definitions/434.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}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&&["single","array","fields"].includes(node.callee.property.name)){const calleeObj=node.callee.object;if(calleeObj.type===eslint_devkit_1.AST_NODE_TYPES.CallExpression){const multerArgs=calleeObj.arguments[0];if(multerArgs&&multerArgs.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const hasFileFilter=multerArgs.properties.some(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&(p.key.name==="fileFilter"||p.key.name==="limits"));if(!hasFileFilter){report(node)}}else if(!multerArgs){report(node)}}}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="upload"){if(node.arguments.length===0||node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.Identifier){report(node)}}}}}});
@@ -1,132 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requirePostmessageOriginCheck = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- function hasOriginCheck(node, sourceCode) {
6
- const text = sourceCode.getText(node);
7
- const originPatterns = [
8
- /event\.origin\s*[!=]==?\s*/,
9
- /e\.origin\s*[!=]==?\s*/,
10
- /\.origin\s*[!=]==?\s*/,
11
- /origin\s*[!=]==?\s*/,
12
- /checkOrigin/i,
13
- /validateOrigin/i,
14
- /isAllowedOrigin/i,
15
- /trustedOrigins/i,
16
- /allowedOrigins/i,
17
- ];
18
- return originPatterns.some((pattern) => pattern.test(text));
19
- }
20
- exports.requirePostmessageOriginCheck = (0, eslint_devkit_1.createRule)({
21
- name: 'require-postmessage-origin-check',
22
- meta: {
23
- type: 'problem',
24
- docs: {
25
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-postmessage-origin-check.md',
26
- description: 'Require origin validation in postMessage event listeners',
27
- cwe: 'CWE-346',
28
- cvss: 7.5,
29
- },
30
- hasSuggestions: true,
31
- messages: {
32
- missingOriginCheck: (0, eslint_devkit_1.formatLLMMessage)({
33
- icon: eslint_devkit_1.MessageIcons.SECURITY,
34
- issueName: 'Missing postMessage Origin Validation',
35
- cwe: 'CWE-346',
36
- description: 'postMessage listener lacks origin check. Malicious sites can send messages that will be processed.',
37
- severity: 'HIGH',
38
- fix: "Add origin validation: if (event.origin !== 'https://trusted-domain.com') return;",
39
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns',
40
- }),
41
- addOriginCheck: (0, eslint_devkit_1.formatLLMMessage)({
42
- icon: eslint_devkit_1.MessageIcons.INFO,
43
- issueName: 'Add Origin Check',
44
- description: 'Validate event.origin before processing message',
45
- severity: 'LOW',
46
- fix: "if (event.origin !== 'https://expected-origin.com') return;",
47
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage',
48
- }),
49
- },
50
- schema: [
51
- {
52
- type: 'object',
53
- properties: {
54
- allowInTests: {
55
- type: 'boolean',
56
- default: false,
57
- },
58
- trustedOrigins: {
59
- type: 'array',
60
- items: { type: 'string' },
61
- default: [], description: 'Origins accepted without an explicit check'
62
- },
63
- },
64
- additionalProperties: false,
65
- },
66
- ],
67
- },
68
- defaultOptions: [
69
- {
70
- allowInTests: false,
71
- trustedOrigins: [],
72
- },
73
- ],
74
- create(context, [options = {}]) {
75
- const { allowInTests = false } = options;
76
- const filename = context.filename;
77
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
78
- if (isTestFile) {
79
- return {};
80
- }
81
- const sourceCode = context.sourceCode;
82
- return {
83
- CallExpression(node) {
84
- const callee = node.callee;
85
- let isMessageListener = false;
86
- if (callee.type === 'MemberExpression' &&
87
- callee.property.type === 'Identifier' &&
88
- callee.property.name === 'addEventListener') {
89
- const eventArg = node.arguments[0];
90
- if (eventArg &&
91
- eventArg.type === 'Literal' &&
92
- eventArg.value === 'message') {
93
- isMessageListener = true;
94
- }
95
- }
96
- if (callee.type === 'Identifier' &&
97
- callee.name === 'addEventListener') {
98
- const eventArg = node.arguments[0];
99
- if (eventArg &&
100
- eventArg.type === 'Literal' &&
101
- eventArg.value === 'message') {
102
- isMessageListener = true;
103
- }
104
- }
105
- if (!isMessageListener) {
106
- return;
107
- }
108
- const handlerArg = node.arguments[1];
109
- if (!handlerArg) {
110
- return;
111
- }
112
- if (handlerArg.type === 'FunctionExpression' ||
113
- handlerArg.type === 'ArrowFunctionExpression') {
114
- if (!hasOriginCheck(handlerArg, sourceCode)) {
115
- context.report({
116
- node: handlerArg,
117
- messageId: 'missingOriginCheck',
118
- suggest: [
119
- {
120
- messageId: 'addOriginCheck',
121
- fix: () => null,
122
- },
123
- ],
124
- });
125
- }
126
- }
127
- if (handlerArg.type === 'Identifier') {
128
- }
129
- },
130
- };
131
- },
132
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requirePostmessageOriginCheck=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function hasOriginCheck(node,sourceCode){const text=sourceCode.getText(node);const originPatterns=[/event\.origin\s*[!=]==?\s*/,/e\.origin\s*[!=]==?\s*/,/\.origin\s*[!=]==?\s*/,/origin\s*[!=]==?\s*/,/checkOrigin/i,/validateOrigin/i,/isAllowedOrigin/i,/trustedOrigins/i,/allowedOrigins/i];return originPatterns.some(pattern=>pattern.test(text))}exports.requirePostmessageOriginCheck=(0,eslint_devkit_1.createRule)({name:"require-postmessage-origin-check",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-postmessage-origin-check.md",description:"Require origin validation in postMessage event listeners",cwe:"CWE-346",cvss:7.5},hasSuggestions:true,messages:{missingOriginCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing postMessage Origin Validation",cwe:"CWE-346",description:"postMessage listener lacks origin check. Malicious sites can send messages that will be processed.",severity:"HIGH",fix:"Add origin validation: if (event.origin !== 'https://trusted-domain.com') return;",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns"}),addOriginCheck:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Origin Check",description:"Validate event.origin before processing message",severity:"LOW",fix:"if (event.origin !== 'https://expected-origin.com') return;",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false},trustedOrigins:{type:"array",items:{type:"string"},default:[],description:"Origins accepted without an explicit check"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,trustedOrigins:[]}],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 callee=node.callee;let isMessageListener=false;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true}}if(callee.type==="Identifier"&&callee.name==="addEventListener"){const eventArg=node.arguments[0];if(eventArg&&eventArg.type==="Literal"&&eventArg.value==="message"){isMessageListener=true}}if(!isMessageListener){return}const handlerArg=node.arguments[1];if(!handlerArg){return}if(handlerArg.type==="FunctionExpression"||handlerArg.type==="ArrowFunctionExpression"){if(!hasOriginCheck(handlerArg,sourceCode)){context.report({node:handlerArg,messageId:"missingOriginCheck",suggest:[{messageId:"addOriginCheck",fix:()=>null}]})}}if(handlerArg.type==="Identifier"){}}}}});
@@ -1,68 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireUrlValidation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.requireUrlValidation = (0, eslint_devkit_1.createRule)({
6
- name: 'require-url-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/require-url-validation.md',
11
- description: 'Enforce URL validation before navigation',
12
- cwe: 'CWE-601',
13
- cvss: 7.5,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'URL Validation Required',
19
- cwe: 'CWE-601',
20
- description: 'Unvalidated URL used for navigation - this is a security risk',
21
- severity: 'HIGH',
22
- fix: 'Validate URLs before using them for navigation',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/601.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- return {
34
- AssignmentExpression(node) {
35
- if (node.left.type === 'MemberExpression' &&
36
- node.left.object.type === 'Identifier' &&
37
- node.left.object.name === 'window' &&
38
- node.left.property.type === 'Identifier' &&
39
- node.left.property.name === 'location') {
40
- if (node.right.type === 'Identifier') {
41
- report(node);
42
- }
43
- }
44
- if (node.left.type === 'MemberExpression' &&
45
- node.left.object.type === 'Identifier' &&
46
- node.left.object.name === 'location' &&
47
- node.left.property.type === 'Identifier' &&
48
- node.left.property.name === 'href') {
49
- if (node.right.type === 'Identifier') {
50
- report(node);
51
- }
52
- }
53
- },
54
- CallExpression(node) {
55
- if (node.callee.type === 'MemberExpression' &&
56
- node.callee.object.type === 'Identifier' &&
57
- node.callee.object.name === 'window' &&
58
- node.callee.property.type === 'Identifier' &&
59
- node.callee.property.name === 'open') {
60
- const urlArg = node.arguments[0];
61
- if (urlArg && urlArg.type === 'Identifier') {
62
- report(node);
63
- }
64
- }
65
- },
66
- };
67
- },
68
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireUrlValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.requireUrlValidation=(0,eslint_devkit_1.createRule)({name:"require-url-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/require-url-validation.md",description:"Enforce URL validation before navigation",cwe:"CWE-601",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"URL Validation Required",cwe:"CWE-601",description:"Unvalidated URL used for navigation - this is a security risk",severity:"HIGH",fix:"Validate URLs before using them for navigation",documentationLink:"https://cwe.mitre.org/data/definitions/601.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{AssignmentExpression(node){if(node.left.type==="MemberExpression"&&node.left.object.type==="Identifier"&&node.left.object.name==="window"&&node.left.property.type==="Identifier"&&node.left.property.name==="location"){if(node.right.type==="Identifier"){report(node)}}if(node.left.type==="MemberExpression"&&node.left.object.type==="Identifier"&&node.left.object.name==="location"&&node.left.property.type==="Identifier"&&node.left.property.name==="href"){if(node.right.type==="Identifier"){report(node)}}},CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&node.callee.object.name==="window"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="open"){const urlArg=node.arguments[0];if(urlArg&&urlArg.type==="Identifier"){report(node)}}}}}});