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.
- package/package.json +2 -2
- package/src/index.js +1 -159
- package/src/oxlint.js +1 -3
- package/src/rules/detect-mixed-content/index.js +1 -38
- package/src/rules/no-allow-arbitrary-loads/index.js +1 -41
- package/src/rules/no-clickjacking/index.js +1 -361
- package/src/rules/no-client-side-auth-logic/index.js +1 -67
- package/src/rules/no-cookie-auth-tokens/index.js +1 -109
- package/src/rules/no-credentials-in-query-params/index.js +1 -55
- package/src/rules/no-disabled-certificate-validation/index.js +1 -59
- package/src/rules/no-dynamic-service-worker-url/index.js +1 -78
- package/src/rules/no-eval/index.js +1 -160
- package/src/rules/no-filereader-innerhtml/index.js +1 -196
- package/src/rules/no-http-urls/index.js +1 -109
- package/src/rules/no-innerhtml/index.js +1 -150
- package/src/rules/no-insecure-redirects/index.js +1 -238
- package/src/rules/no-insecure-websocket/index.js +1 -57
- package/src/rules/no-jwt-in-storage/index.js +1 -178
- package/src/rules/no-missing-cors-check/index.js +1 -351
- package/src/rules/no-missing-csrf-protection/index.js +1 -165
- package/src/rules/no-missing-security-headers/index.js +1 -197
- package/src/rules/no-password-in-url/index.js +1 -47
- package/src/rules/no-permissive-cors/index.js +1 -65
- package/src/rules/no-postmessage-innerhtml/index.js +1 -161
- package/src/rules/no-postmessage-wildcard-origin/index.js +1 -112
- package/src/rules/no-sensitive-cookie-js/index.js +1 -151
- package/src/rules/no-sensitive-data-in-analytics/index.js +1 -58
- package/src/rules/no-sensitive-data-in-cache/index.js +1 -47
- package/src/rules/no-sensitive-indexeddb/index.js +1 -110
- package/src/rules/no-sensitive-localstorage/index.js +1 -173
- package/src/rules/no-sensitive-sessionstorage/index.js +1 -144
- package/src/rules/no-tracking-without-consent/index.js +1 -65
- package/src/rules/no-unencrypted-transmission/index.js +1 -208
- package/src/rules/no-unescaped-url-parameter/index.js +1 -319
- package/src/rules/no-unsafe-eval-csp/index.js +1 -75
- package/src/rules/no-unsafe-inline-csp/index.js +1 -75
- package/src/rules/no-unvalidated-deeplinks/index.js +1 -59
- package/src/rules/no-websocket-eval/index.js +1 -197
- package/src/rules/no-websocket-innerhtml/index.js +1 -185
- package/src/rules/no-worker-message-innerhtml/index.js +1 -181
- package/src/rules/require-blob-url-revocation/index.js +1 -93
- package/src/rules/require-cookie-secure-attrs/index.js +1 -101
- package/src/rules/require-csp-headers/index.js +1 -59
- package/src/rules/require-https-only/index.js +1 -57
- package/src/rules/require-mime-type-validation/index.js +1 -61
- package/src/rules/require-postmessage-origin-check/index.js +1 -132
- package/src/rules/require-url-validation/index.js +1 -68
- package/src/rules/require-websocket-wss/index.js +1 -125
|
@@ -1,197 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noMissingSecurityHeaders = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const DEFAULT_REQUIRED_HEADERS = [
|
|
7
|
-
'Content-Security-Policy',
|
|
8
|
-
'X-Frame-Options',
|
|
9
|
-
'X-Content-Type-Options',
|
|
10
|
-
];
|
|
11
|
-
function extractHeaderName(node) {
|
|
12
|
-
if (node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
|
|
13
|
-
return String(node.arguments[0].value);
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
|
|
18
|
-
const setHeaders = new Set();
|
|
19
|
-
let current = node;
|
|
20
|
-
let scopeNode = null;
|
|
21
|
-
while (current) {
|
|
22
|
-
if (current.type === 'FunctionDeclaration' ||
|
|
23
|
-
current.type === 'FunctionExpression' ||
|
|
24
|
-
current.type === 'ArrowFunctionExpression') {
|
|
25
|
-
scopeNode = current;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
current = current.parent ?? null;
|
|
29
|
-
}
|
|
30
|
-
if (!scopeNode) {
|
|
31
|
-
scopeNode = context.sourceCode.ast;
|
|
32
|
-
}
|
|
33
|
-
function collectHeaders(astNode) {
|
|
34
|
-
if (astNode.type === 'CallExpression' &&
|
|
35
|
-
astNode.callee.type === 'MemberExpression' &&
|
|
36
|
-
astNode.callee.property.type === 'Identifier' &&
|
|
37
|
-
['setHeader', 'header', 'set'].includes(astNode.callee.property.name)) {
|
|
38
|
-
const headerName = extractHeaderName(astNode);
|
|
39
|
-
if (headerName) {
|
|
40
|
-
setHeaders.add(headerName);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (astNode.type === 'Program' && astNode.body) {
|
|
44
|
-
astNode.body.forEach(collectHeaders);
|
|
45
|
-
}
|
|
46
|
-
else if ((astNode.type === 'FunctionDeclaration' ||
|
|
47
|
-
astNode.type === 'FunctionExpression' ||
|
|
48
|
-
astNode.type === 'ArrowFunctionExpression') && astNode.body) {
|
|
49
|
-
collectHeaders(astNode.body);
|
|
50
|
-
}
|
|
51
|
-
else if (astNode.type === 'BlockStatement' && astNode.body) {
|
|
52
|
-
astNode.body.forEach(collectHeaders);
|
|
53
|
-
}
|
|
54
|
-
else if (astNode.type === 'ExpressionStatement' && astNode.expression) {
|
|
55
|
-
collectHeaders(astNode.expression);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
collectHeaders(scopeNode);
|
|
59
|
-
return requiredHeaders.filter(header => !setHeaders.has(header));
|
|
60
|
-
}
|
|
61
|
-
exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
|
|
62
|
-
name: 'no-missing-security-headers',
|
|
63
|
-
meta: {
|
|
64
|
-
type: 'problem',
|
|
65
|
-
deprecated: true,
|
|
66
|
-
replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
|
|
67
|
-
docs: {
|
|
68
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-security-headers.md',
|
|
69
|
-
description: 'Detects missing security headers in HTTP responses',
|
|
70
|
-
cwe: 'CWE-693',
|
|
71
|
-
cvss: 7.5,
|
|
72
|
-
},
|
|
73
|
-
hasSuggestions: true,
|
|
74
|
-
messages: {
|
|
75
|
-
missingSecurityHeader: (0, eslint_devkit_1.formatLLMMessage)({
|
|
76
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
77
|
-
issueName: 'Missing security headers',
|
|
78
|
-
cwe: 'CWE-693',
|
|
79
|
-
description: 'Missing security headers: {{headers}}',
|
|
80
|
-
severity: 'HIGH',
|
|
81
|
-
fix: 'Set security headers: Content-Security-Policy, X-Frame-Options, X-Content-Type-Options',
|
|
82
|
-
documentationLink: 'https://owasp.org/www-project-secure-headers/',
|
|
83
|
-
}),
|
|
84
|
-
addSecurityHeaders: (0, eslint_devkit_1.formatLLMMessage)({
|
|
85
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
86
|
-
issueName: 'Add Security Headers',
|
|
87
|
-
description: 'Add security headers middleware',
|
|
88
|
-
severity: 'LOW',
|
|
89
|
-
fix: 'Add Content-Security-Policy, X-Frame-Options headers',
|
|
90
|
-
documentationLink: 'https://owasp.org/www-project-secure-headers/',
|
|
91
|
-
}),
|
|
92
|
-
useMiddleware: (0, eslint_devkit_1.formatLLMMessage)({
|
|
93
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
94
|
-
issueName: 'Use Helmet',
|
|
95
|
-
description: 'Use helmet.js for security headers',
|
|
96
|
-
severity: 'LOW',
|
|
97
|
-
fix: 'app.use(helmet())',
|
|
98
|
-
documentationLink: 'https://helmetjs.github.io/',
|
|
99
|
-
}),
|
|
100
|
-
setHeader: (0, eslint_devkit_1.formatLLMMessage)({
|
|
101
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
102
|
-
issueName: 'Set Headers',
|
|
103
|
-
description: 'Set security headers manually',
|
|
104
|
-
severity: 'LOW',
|
|
105
|
-
fix: 'res.setHeader("X-Frame-Options", "DENY")',
|
|
106
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers',
|
|
107
|
-
}),
|
|
108
|
-
},
|
|
109
|
-
schema: [
|
|
110
|
-
{
|
|
111
|
-
type: 'object',
|
|
112
|
-
properties: {
|
|
113
|
-
requiredHeaders: {
|
|
114
|
-
type: 'array',
|
|
115
|
-
items: { type: 'string' },
|
|
116
|
-
default: DEFAULT_REQUIRED_HEADERS, description: 'Security headers a response must set'
|
|
117
|
-
},
|
|
118
|
-
ignoreInTests: {
|
|
119
|
-
type: 'boolean',
|
|
120
|
-
default: true,
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
additionalProperties: false,
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
defaultOptions: [
|
|
128
|
-
{
|
|
129
|
-
requiredHeaders: DEFAULT_REQUIRED_HEADERS,
|
|
130
|
-
ignoreInTests: true,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
create(context, [options = {}]) {
|
|
134
|
-
const { requiredHeaders = DEFAULT_REQUIRED_HEADERS, ignoreInTests = true, } = options || {};
|
|
135
|
-
const filename = context.filename;
|
|
136
|
-
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
137
|
-
if (isTestFile) {
|
|
138
|
-
return {};
|
|
139
|
-
}
|
|
140
|
-
const reportedScopes = new Set();
|
|
141
|
-
function getScopeKey(node) {
|
|
142
|
-
let current = node;
|
|
143
|
-
while (current) {
|
|
144
|
-
if (current.type === 'FunctionDeclaration' ||
|
|
145
|
-
current.type === 'FunctionExpression' ||
|
|
146
|
-
current.type === 'ArrowFunctionExpression') {
|
|
147
|
-
return `${current.range?.[0]}-${current.range?.[1]}`;
|
|
148
|
-
}
|
|
149
|
-
current = current.parent ?? null;
|
|
150
|
-
}
|
|
151
|
-
return 'program';
|
|
152
|
-
}
|
|
153
|
-
function checkCallExpression(node) {
|
|
154
|
-
if (node.callee.type === 'MemberExpression' &&
|
|
155
|
-
node.callee.property.type === 'Identifier') {
|
|
156
|
-
const methodName = node.callee.property.name;
|
|
157
|
-
if (['setHeader', 'header', 'set'].includes(methodName)) {
|
|
158
|
-
const scopeKey = getScopeKey(node);
|
|
159
|
-
if (reportedScopes.has(scopeKey)) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const missing = checkFunctionForSecurityHeaders(node, requiredHeaders, context);
|
|
163
|
-
if (missing.length > 0) {
|
|
164
|
-
reportedScopes.add(scopeKey);
|
|
165
|
-
context.report({
|
|
166
|
-
node,
|
|
167
|
-
messageId: 'missingSecurityHeader',
|
|
168
|
-
data: {
|
|
169
|
-
headers: missing.join(', '),
|
|
170
|
-
},
|
|
171
|
-
suggest: [
|
|
172
|
-
{
|
|
173
|
-
messageId: 'addSecurityHeaders',
|
|
174
|
-
fix: () => null,
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
messageId: 'useMiddleware',
|
|
178
|
-
fix: () => null,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
messageId: 'setHeader',
|
|
182
|
-
fix: () => null,
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
reportedScopes.add(scopeKey);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
CallExpression: checkCallExpression,
|
|
195
|
-
};
|
|
196
|
-
},
|
|
197
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMissingSecurityHeaders=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const DEFAULT_REQUIRED_HEADERS=["Content-Security-Policy","X-Frame-Options","X-Content-Type-Options"];function extractHeaderName(node){if(node.arguments.length>0&&node.arguments[0].type==="Literal"){return String(node.arguments[0].value)}return null}function checkFunctionForSecurityHeaders(node,requiredHeaders,context){const setHeaders=new Set;let current=node;let scopeNode=null;while(current){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){scopeNode=current;break}current=current.parent??null}if(!scopeNode){scopeNode=context.sourceCode.ast}function collectHeaders(astNode){if(astNode.type==="CallExpression"&&astNode.callee.type==="MemberExpression"&&astNode.callee.property.type==="Identifier"&&["setHeader","header","set"].includes(astNode.callee.property.name)){const headerName=extractHeaderName(astNode);if(headerName){setHeaders.add(headerName)}}if(astNode.type==="Program"&&astNode.body){astNode.body.forEach(collectHeaders)}else if((astNode.type==="FunctionDeclaration"||astNode.type==="FunctionExpression"||astNode.type==="ArrowFunctionExpression")&&astNode.body){collectHeaders(astNode.body)}else if(astNode.type==="BlockStatement"&&astNode.body){astNode.body.forEach(collectHeaders)}else if(astNode.type==="ExpressionStatement"&&astNode.expression){collectHeaders(astNode.expression)}}collectHeaders(scopeNode);return requiredHeaders.filter(header=>!setHeaders.has(header))}exports.noMissingSecurityHeaders=(0,eslint_devkit_2.createRule)({name:"no-missing-security-headers",meta:{type:"problem",deprecated:true,replacedBy:["@see eslint-plugin-express-security/require-helmet"],docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-security-headers.md",description:"Detects missing security headers in HTTP responses",cwe:"CWE-693",cvss:7.5},hasSuggestions:true,messages:{missingSecurityHeader:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Missing security headers",cwe:"CWE-693",description:"Missing security headers: {{headers}}",severity:"HIGH",fix:"Set security headers: Content-Security-Policy, X-Frame-Options, X-Content-Type-Options",documentationLink:"https://owasp.org/www-project-secure-headers/"}),addSecurityHeaders:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Add Security Headers",description:"Add security headers middleware",severity:"LOW",fix:"Add Content-Security-Policy, X-Frame-Options headers",documentationLink:"https://owasp.org/www-project-secure-headers/"}),useMiddleware:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Helmet",description:"Use helmet.js for security headers",severity:"LOW",fix:"app.use(helmet())",documentationLink:"https://helmetjs.github.io/"}),setHeader:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Set Headers",description:"Set security headers manually",severity:"LOW",fix:'res.setHeader("X-Frame-Options", "DENY")',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers"})},schema:[{type:"object",properties:{requiredHeaders:{type:"array",items:{type:"string"},default:DEFAULT_REQUIRED_HEADERS,description:"Security headers a response must set"},ignoreInTests:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{requiredHeaders:DEFAULT_REQUIRED_HEADERS,ignoreInTests:true}],create(context,[options={}]){const{requiredHeaders=DEFAULT_REQUIRED_HEADERS,ignoreInTests=true}=options||{};const filename=context.filename;const isTestFile=ignoreInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);if(isTestFile){return{}}const reportedScopes=new Set;function getScopeKey(node){let current=node;while(current){if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"){return`${current.range?.[0]}-${current.range?.[1]}`}current=current.parent??null}return"program"}function checkCallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"){const methodName=node.callee.property.name;if(["setHeader","header","set"].includes(methodName)){const scopeKey=getScopeKey(node);if(reportedScopes.has(scopeKey)){return}const missing=checkFunctionForSecurityHeaders(node,requiredHeaders,context);if(missing.length>0){reportedScopes.add(scopeKey);context.report({node,messageId:"missingSecurityHeader",data:{headers:missing.join(", ")},suggest:[{messageId:"addSecurityHeaders",fix:()=>null},{messageId:"useMiddleware",fix:()=>null},{messageId:"setHeader",fix:()=>null}]})}else{reportedScopes.add(scopeKey)}}}}return{CallExpression:checkCallExpression}}});
|
|
@@ -1,47 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noPasswordInUrl = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noPasswordInUrl = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-password-in-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-password-in-url.md',
|
|
11
|
-
description: 'Prevent passwords in URLs',
|
|
12
|
-
cwe: 'CWE-521',
|
|
13
|
-
cvss: 5.3,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
18
|
-
issueName: 'violation Detected',
|
|
19
|
-
cwe: 'CWE-521',
|
|
20
|
-
description: 'Prevent passwords in URLs detected - this is a security risk',
|
|
21
|
-
severity: 'CRITICAL',
|
|
22
|
-
fix: 'Review and apply secure practices',
|
|
23
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/521.html',
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
schema: [],
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
function report(node) {
|
|
31
|
-
context.report({
|
|
32
|
-
node,
|
|
33
|
-
messageId: 'violationDetected',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
Literal(node) {
|
|
38
|
-
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
39
|
-
const urlPattern = /https?:\/\/[^:]+:[^@]+@/;
|
|
40
|
-
if (urlPattern.test(node.value)) {
|
|
41
|
-
report(node);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPasswordInUrl=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noPasswordInUrl=(0,eslint_devkit_1.createRule)({name:"no-password-in-url",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-password-in-url.md",description:"Prevent passwords in URLs",cwe:"CWE-521",cvss:5.3},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-521",description:"Prevent passwords in URLs detected - this is a security risk",severity:"CRITICAL",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/521.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{Literal(node){if(node.type==="Literal"&&typeof node.value==="string"){const urlPattern=/https?:\/\/[^:]+:[^@]+@/;if(urlPattern.test(node.value)){report(node)}}}}}});
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noPermissiveCors = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-permissive-cors',
|
|
7
|
-
meta: {
|
|
8
|
-
type: 'problem',
|
|
9
|
-
deprecated: true,
|
|
10
|
-
replacedBy: ['@see eslint-plugin-express-security/no-permissive-cors'],
|
|
11
|
-
docs: {
|
|
12
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-permissive-cors.md',
|
|
13
|
-
description: 'Prevent overly permissive CORS configuration',
|
|
14
|
-
cwe: 'CWE-942',
|
|
15
|
-
cvss: 7.5,
|
|
16
|
-
confidence: 'high',
|
|
17
|
-
},
|
|
18
|
-
messages: {
|
|
19
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
20
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
21
|
-
issueName: 'violation Detected',
|
|
22
|
-
cwe: 'CWE-942',
|
|
23
|
-
description: 'Prevent overly permissive CORS configuration detected - this is a security risk',
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: 'Review and apply secure practices',
|
|
26
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/942.html',
|
|
27
|
-
})
|
|
28
|
-
},
|
|
29
|
-
schema: [],
|
|
30
|
-
},
|
|
31
|
-
defaultOptions: [],
|
|
32
|
-
create(context) {
|
|
33
|
-
function report(node) {
|
|
34
|
-
context.report({
|
|
35
|
-
node,
|
|
36
|
-
messageId: 'violationDetected',
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
CallExpression(node) {
|
|
41
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
42
|
-
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
43
|
-
node.callee.property.name === 'setHeader' &&
|
|
44
|
-
node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
45
|
-
node.arguments[0].value === 'Access-Control-Allow-Origin' &&
|
|
46
|
-
node.arguments[1]?.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
47
|
-
node.arguments[1].value === '*') {
|
|
48
|
-
report(node);
|
|
49
|
-
}
|
|
50
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
51
|
-
node.callee.name === 'cors' &&
|
|
52
|
-
node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
53
|
-
const originProp = node.arguments[0].properties.find((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
|
|
54
|
-
p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
55
|
-
p.key.name === 'origin');
|
|
56
|
-
if (originProp &&
|
|
57
|
-
originProp.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
58
|
-
originProp.value.value === '*') {
|
|
59
|
-
report(node);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPermissiveCors=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noPermissiveCors=(0,eslint_devkit_1.createRule)({name:"no-permissive-cors",meta:{type:"problem",deprecated:true,replacedBy:["@see eslint-plugin-express-security/no-permissive-cors"],docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-permissive-cors.md",description:"Prevent overly permissive CORS configuration",cwe:"CWE-942",cvss:7.5,confidence:"high"},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"violation Detected",cwe:"CWE-942",description:"Prevent overly permissive CORS configuration detected - this is a security risk",severity:"HIGH",fix:"Review and apply secure practices",documentationLink:"https://cwe.mitre.org/data/definitions/942.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&&node.callee.property.name==="setHeader"&&node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&node.arguments[0].value==="Access-Control-Allow-Origin"&&node.arguments[1]?.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&node.arguments[1].value==="*"){report(node)}if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="cors"&&node.arguments[0]?.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){const originProp=node.arguments[0].properties.find(p=>p.type===eslint_devkit_1.AST_NODE_TYPES.Property&&p.key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&p.key.name==="origin");if(originProp&&originProp.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&originProp.value.value==="*"){report(node)}}}}}});
|
|
@@ -1,161 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noPostmessageInnerhtml = 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.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
8
|
-
name: 'no-postmessage-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-postmessage-innerhtml.md',
|
|
13
|
-
description: 'Disallow using innerHTML or similar methods with postMessage data',
|
|
14
|
-
cwe: 'CWE-79',
|
|
15
|
-
cvss: 8.8,
|
|
16
|
-
},
|
|
17
|
-
hasSuggestions: true,
|
|
18
|
-
messages: {
|
|
19
|
-
unsafeInnerhtml: (0, eslint_devkit_1.formatLLMMessage)({
|
|
20
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
21
|
-
issueName: 'XSS via postMessage',
|
|
22
|
-
cwe: 'CWE-79',
|
|
23
|
-
owasp: 'A03:2021',
|
|
24
|
-
cvss: 8.8,
|
|
25
|
-
description: 'Using {{method}} with postMessage data allows XSS attacks. Any window can send malicious HTML that will be executed.',
|
|
26
|
-
severity: 'HIGH',
|
|
27
|
-
fix: 'Use textContent for plain text, or sanitize with DOMPurify before using innerHTML.',
|
|
28
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns',
|
|
29
|
-
}),
|
|
30
|
-
useTextContent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
31
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
32
|
-
issueName: 'Use Safe DOM Methods',
|
|
33
|
-
description: 'Use textContent or sanitize input with DOMPurify',
|
|
34
|
-
severity: 'LOW',
|
|
35
|
-
fix: 'element.textContent = event.data; // For plain text\nelement.innerHTML = DOMPurify.sanitize(event.data); // For HTML',
|
|
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 inMessageHandler = false;
|
|
61
|
-
let eventParamName = null;
|
|
62
|
-
function checkMessageHandler(node) {
|
|
63
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
64
|
-
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
65
|
-
node.callee.property.name === 'addEventListener' &&
|
|
66
|
-
node.arguments.length >= 2) {
|
|
67
|
-
const eventTypeArg = node.arguments[0];
|
|
68
|
-
if (eventTypeArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
69
|
-
eventTypeArg.value === 'message') {
|
|
70
|
-
const callback = node.arguments[1];
|
|
71
|
-
if (callback.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
72
|
-
callback.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression) {
|
|
73
|
-
const firstParam = callback.params[0];
|
|
74
|
-
if (firstParam && firstParam.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
75
|
-
return { isMessageHandler: true, eventParam: firstParam.name };
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return { isMessageHandler: false, eventParam: null };
|
|
81
|
-
}
|
|
82
|
-
function referencesEventData(node, eventName) {
|
|
83
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
84
|
-
if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
85
|
-
node.object.name === eventName &&
|
|
86
|
-
node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
87
|
-
node.property.name === 'data') {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
return referencesEventData(node.object, eventName);
|
|
91
|
-
}
|
|
92
|
-
if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.name === eventName) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
CallExpression(node) {
|
|
99
|
-
const { isMessageHandler, eventParam } = checkMessageHandler(node);
|
|
100
|
-
if (isMessageHandler) {
|
|
101
|
-
inMessageHandler = true;
|
|
102
|
-
eventParamName = eventParam;
|
|
103
|
-
}
|
|
104
|
-
if (!inMessageHandler || !eventParamName)
|
|
105
|
-
return;
|
|
106
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
107
|
-
node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
108
|
-
DANGEROUS_METHODS.has(node.callee.property.name)) {
|
|
109
|
-
for (const arg of node.arguments) {
|
|
110
|
-
if (referencesEventData(arg, eventParamName)) {
|
|
111
|
-
context.report({
|
|
112
|
-
node,
|
|
113
|
-
messageId: 'unsafeInnerhtml',
|
|
114
|
-
data: {
|
|
115
|
-
method: node.callee.property.name,
|
|
116
|
-
},
|
|
117
|
-
suggest: [
|
|
118
|
-
{
|
|
119
|
-
messageId: 'useTextContent',
|
|
120
|
-
fix: () => null,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
});
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
'CallExpression:exit'(node) {
|
|
130
|
-
const { isMessageHandler } = checkMessageHandler(node);
|
|
131
|
-
if (isMessageHandler) {
|
|
132
|
-
inMessageHandler = false;
|
|
133
|
-
eventParamName = null;
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
AssignmentExpression(node) {
|
|
137
|
-
if (!inMessageHandler || !eventParamName)
|
|
138
|
-
return;
|
|
139
|
-
if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
140
|
-
node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
141
|
-
DANGEROUS_PROPERTIES.has(node.left.property.name)) {
|
|
142
|
-
if (referencesEventData(node.right, eventParamName)) {
|
|
143
|
-
context.report({
|
|
144
|
-
node,
|
|
145
|
-
messageId: 'unsafeInnerhtml',
|
|
146
|
-
data: {
|
|
147
|
-
method: node.left.property.name,
|
|
148
|
-
},
|
|
149
|
-
suggest: [
|
|
150
|
-
{
|
|
151
|
-
messageId: 'useTextContent',
|
|
152
|
-
fix: () => null,
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
},
|
|
161
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPostmessageInnerhtml=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"]);exports.noPostmessageInnerhtml=(0,eslint_devkit_1.createRule)({name:"no-postmessage-innerhtml",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-postmessage-innerhtml.md",description:"Disallow using innerHTML or similar methods with postMessage data",cwe:"CWE-79",cvss:8.8},hasSuggestions:true,messages:{unsafeInnerhtml:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"XSS via postMessage",cwe:"CWE-79",owasp:"A03:2021",cvss:8.8,description:"Using {{method}} with postMessage data allows XSS attacks. Any window can send malicious HTML that will be executed.",severity:"HIGH",fix:"Use textContent for plain text, or sanitize with DOMPurify before using innerHTML.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns"}),useTextContent:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Safe DOM Methods",description:"Use textContent or sanitize input with DOMPurify",severity:"LOW",fix:"element.textContent = event.data; // For plain text\nelement.innerHTML = DOMPurify.sanitize(event.data); // For HTML",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{}}let inMessageHandler=false;let eventParamName=null;function checkMessageHandler(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 eventTypeArg=node.arguments[0];if(eventTypeArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&eventTypeArg.value==="message"){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{isMessageHandler:true,eventParam:firstParam.name}}}}}return{isMessageHandler:false,eventParam:null}}function referencesEventData(node,eventName){if(node.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression){if(node.object.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.object.name===eventName&&node.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.property.name==="data"){return true}return referencesEventData(node.object,eventName)}if(node.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.name===eventName){return true}return false}return{CallExpression(node){const{isMessageHandler,eventParam}=checkMessageHandler(node);if(isMessageHandler){inMessageHandler=true;eventParamName=eventParam}if(!inMessageHandler||!eventParamName)return;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(referencesEventData(arg,eventParamName)){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.callee.property.name},suggest:[{messageId:"useTextContent",fix:()=>null}]});break}}}},"CallExpression:exit"(node){const{isMessageHandler}=checkMessageHandler(node);if(isMessageHandler){inMessageHandler=false;eventParamName=null}},AssignmentExpression(node){if(!inMessageHandler||!eventParamName)return;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(referencesEventData(node.right,eventParamName)){context.report({node,messageId:"unsafeInnerhtml",data:{method:node.left.property.name},suggest:[{messageId:"useTextContent",fix:()=>null}]})}}}}}});
|
|
@@ -1,112 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noPostmessageWildcardOrigin = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noPostmessageWildcardOrigin = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-postmessage-wildcard-origin',
|
|
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-postmessage-wildcard-origin.md',
|
|
11
|
-
description: 'Disallow using wildcard (*) as targetOrigin in postMessage calls',
|
|
12
|
-
cwe: 'CWE-346',
|
|
13
|
-
cvss: 7.5,
|
|
14
|
-
},
|
|
15
|
-
hasSuggestions: true,
|
|
16
|
-
messages: {
|
|
17
|
-
wildcardOrigin: (0, eslint_devkit_1.formatLLMMessage)({
|
|
18
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
19
|
-
issueName: 'Wildcard postMessage Origin',
|
|
20
|
-
cwe: 'CWE-346',
|
|
21
|
-
owasp: 'A01:2021',
|
|
22
|
-
cvss: 7.5,
|
|
23
|
-
description: 'postMessage with "*" targetOrigin allows any window to receive the message, potentially leaking sensitive data to malicious sites.',
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: 'Specify the exact origin of the target window instead of "*".',
|
|
26
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns',
|
|
27
|
-
}),
|
|
28
|
-
specifyOrigin: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
30
|
-
issueName: 'Specify Target Origin',
|
|
31
|
-
description: 'Replace wildcard with specific origin',
|
|
32
|
-
severity: 'LOW',
|
|
33
|
-
fix: "Use the exact target origin, e.g., 'https://trusted-domain.com'",
|
|
34
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage',
|
|
35
|
-
}),
|
|
36
|
-
},
|
|
37
|
-
schema: [
|
|
38
|
-
{
|
|
39
|
-
type: 'object',
|
|
40
|
-
properties: {
|
|
41
|
-
allowInTests: {
|
|
42
|
-
type: 'boolean',
|
|
43
|
-
default: true,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
additionalProperties: false,
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
defaultOptions: [{ allowInTests: true }],
|
|
51
|
-
create(context, [options = {}]) {
|
|
52
|
-
const { allowInTests = true } = options;
|
|
53
|
-
const filename = context.filename;
|
|
54
|
-
const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
55
|
-
if (allowInTests && isTestFile) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
CallExpression(node) {
|
|
60
|
-
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const property = node.callee.property;
|
|
64
|
-
if (property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
65
|
-
property.name !== 'postMessage') {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const args = node.arguments;
|
|
69
|
-
if (args.length < 2) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const targetOriginArg = args[1];
|
|
73
|
-
if (targetOriginArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
74
|
-
targetOriginArg.value === '*') {
|
|
75
|
-
context.report({
|
|
76
|
-
node: targetOriginArg,
|
|
77
|
-
messageId: 'wildcardOrigin',
|
|
78
|
-
suggest: [
|
|
79
|
-
{
|
|
80
|
-
messageId: 'specifyOrigin',
|
|
81
|
-
fix: (fixer) => fixer.replaceText(targetOriginArg, "'https://your-domain.com'"),
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (targetOriginArg.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
|
|
88
|
-
for (const prop of targetOriginArg.properties) {
|
|
89
|
-
if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Property)
|
|
90
|
-
continue;
|
|
91
|
-
const key = prop.key;
|
|
92
|
-
if (key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
93
|
-
key.name === 'targetOrigin' &&
|
|
94
|
-
prop.value.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
95
|
-
prop.value.value === '*') {
|
|
96
|
-
context.report({
|
|
97
|
-
node: prop.value,
|
|
98
|
-
messageId: 'wildcardOrigin',
|
|
99
|
-
suggest: [
|
|
100
|
-
{
|
|
101
|
-
messageId: 'specifyOrigin',
|
|
102
|
-
fix: (fixer) => fixer.replaceText(prop.value, "'https://your-domain.com'"),
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noPostmessageWildcardOrigin=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noPostmessageWildcardOrigin=(0,eslint_devkit_1.createRule)({name:"no-postmessage-wildcard-origin",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-postmessage-wildcard-origin.md",description:"Disallow using wildcard (*) as targetOrigin in postMessage calls",cwe:"CWE-346",cvss:7.5},hasSuggestions:true,messages:{wildcardOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Wildcard postMessage Origin",cwe:"CWE-346",owasp:"A01:2021",cvss:7.5,description:'postMessage with "*" targetOrigin allows any window to receive the message, potentially leaking sensitive data to malicious sites.',severity:"HIGH",fix:'Specify the exact origin of the target window instead of "*".',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns"}),specifyOrigin:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Specify Target Origin",description:"Replace wildcard with specific origin",severity:"LOW",fix:"Use the exact target origin, e.g., 'https://trusted-domain.com'",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage"})},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){return}const property=node.callee.property;if(property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier||property.name!=="postMessage"){return}const args=node.arguments;if(args.length<2){return}const targetOriginArg=args[1];if(targetOriginArg.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&targetOriginArg.value==="*"){context.report({node:targetOriginArg,messageId:"wildcardOrigin",suggest:[{messageId:"specifyOrigin",fix:fixer=>fixer.replaceText(targetOriginArg,"'https://your-domain.com'")}]});return}if(targetOriginArg.type===eslint_devkit_1.AST_NODE_TYPES.ObjectExpression){for(const prop of targetOriginArg.properties){if(prop.type!==eslint_devkit_1.AST_NODE_TYPES.Property)continue;const key=prop.key;if(key.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&key.name==="targetOrigin"&&prop.value.type===eslint_devkit_1.AST_NODE_TYPES.Literal&&prop.value.value==="*"){context.report({node:prop.value,messageId:"wildcardOrigin",suggest:[{messageId:"specifyOrigin",fix:fixer=>fixer.replaceText(prop.value,"'https://your-domain.com'")}]})}}}}}}});
|