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,319 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnescapedUrlParameter = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
7
|
-
let current = node;
|
|
8
|
-
while (current) {
|
|
9
|
-
if (current.type === 'CallExpression') {
|
|
10
|
-
const callee = current.callee;
|
|
11
|
-
if (callee.type === 'Identifier') {
|
|
12
|
-
const calleeName = callee.name;
|
|
13
|
-
if (['encodeURIComponent', 'encodeURI', 'escape'].includes(calleeName)) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (callee.type === 'MemberExpression') {
|
|
18
|
-
const object = callee.object;
|
|
19
|
-
if (object.type === 'Identifier') {
|
|
20
|
-
const objectName = object.name.toLowerCase();
|
|
21
|
-
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if ('parent' in current && current.parent) {
|
|
28
|
-
current = current.parent;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
function matchesIgnorePattern(text, ignorePatterns) {
|
|
37
|
-
return ignorePatterns.some(pattern => {
|
|
38
|
-
try {
|
|
39
|
-
const regex = new RegExp(pattern, 'i');
|
|
40
|
-
return regex.test(text);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function isUrlConstruction(node, sourceCode) {
|
|
48
|
-
let text = sourceCode.getText(node);
|
|
49
|
-
if (node.type === 'TemplateLiteral') {
|
|
50
|
-
text = node.quasis.map(q => q.value.raw).join('');
|
|
51
|
-
}
|
|
52
|
-
const urlPatterns = [
|
|
53
|
-
/\bhttps?:\/\//,
|
|
54
|
-
/\bnew\s+URL\s*\(/,
|
|
55
|
-
/\burl\s*[=:]\s*/,
|
|
56
|
-
/\burl\s*\+/,
|
|
57
|
-
/\bwindow\.location/,
|
|
58
|
-
/\blocation\.href/,
|
|
59
|
-
/\bwindow\.open\s*\(/,
|
|
60
|
-
/\?[^=]+=/,
|
|
61
|
-
];
|
|
62
|
-
return urlPatterns.some(pattern => pattern.test(text));
|
|
63
|
-
}
|
|
64
|
-
exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
65
|
-
name: 'no-unescaped-url-parameter',
|
|
66
|
-
meta: {
|
|
67
|
-
type: 'problem',
|
|
68
|
-
docs: {
|
|
69
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unescaped-url-parameter.md',
|
|
70
|
-
description: 'Detects unescaped URL parameters',
|
|
71
|
-
cwe: 'CWE-79',
|
|
72
|
-
cvss: 6.1,
|
|
73
|
-
},
|
|
74
|
-
hasSuggestions: true,
|
|
75
|
-
messages: {
|
|
76
|
-
unescapedUrlParameter: (0, eslint_devkit_1.formatLLMMessage)({
|
|
77
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
78
|
-
issueName: 'Unescaped URL Parameter',
|
|
79
|
-
cwe: 'CWE-79',
|
|
80
|
-
description: 'Unescaped URL parameter detected: {{parameter}}',
|
|
81
|
-
severity: 'HIGH',
|
|
82
|
-
fix: '{{safeAlternative}}',
|
|
83
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/79.html',
|
|
84
|
-
}),
|
|
85
|
-
useEncodeURIComponent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
86
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
87
|
-
issueName: 'Use encodeURIComponent',
|
|
88
|
-
description: 'Use encodeURIComponent for URL params',
|
|
89
|
-
severity: 'LOW',
|
|
90
|
-
fix: '`https://example.com?q=${encodeURIComponent(param)}`',
|
|
91
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent',
|
|
92
|
-
}),
|
|
93
|
-
useURLSearchParams: (0, eslint_devkit_1.formatLLMMessage)({
|
|
94
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
95
|
-
issueName: 'Use URLSearchParams',
|
|
96
|
-
description: 'Use URLSearchParams for safe URL construction',
|
|
97
|
-
severity: 'LOW',
|
|
98
|
-
fix: 'new URLSearchParams({ q: param }).toString()',
|
|
99
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams',
|
|
100
|
-
}),
|
|
101
|
-
},
|
|
102
|
-
schema: [
|
|
103
|
-
{
|
|
104
|
-
type: 'object',
|
|
105
|
-
properties: {
|
|
106
|
-
allowInTests: {
|
|
107
|
-
type: 'boolean',
|
|
108
|
-
default: false,
|
|
109
|
-
description: 'Allow unescaped URL parameters in test files',
|
|
110
|
-
},
|
|
111
|
-
trustedLibraries: {
|
|
112
|
-
type: 'array',
|
|
113
|
-
items: { type: 'string' },
|
|
114
|
-
default: ['url', 'querystring'],
|
|
115
|
-
description: 'Trusted URL construction libraries',
|
|
116
|
-
},
|
|
117
|
-
ignorePatterns: {
|
|
118
|
-
type: 'array',
|
|
119
|
-
items: { type: 'string' },
|
|
120
|
-
default: [],
|
|
121
|
-
description: 'Additional safe patterns to ignore',
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
additionalProperties: false,
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
},
|
|
128
|
-
defaultOptions: [
|
|
129
|
-
{
|
|
130
|
-
allowInTests: false,
|
|
131
|
-
trustedLibraries: ['url', 'querystring'],
|
|
132
|
-
ignorePatterns: [],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
create(context, [options = {}]) {
|
|
136
|
-
const { allowInTests = false, trustedLibraries = ['url', 'querystring'], ignorePatterns = [], } = options;
|
|
137
|
-
const filename = context.filename;
|
|
138
|
-
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
139
|
-
const sourceCode = context.sourceCode;
|
|
140
|
-
function checkTemplateLiteral(node) {
|
|
141
|
-
if (isTestFile) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (!isUrlConstruction(node, sourceCode)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
for (const expression of node.expressions) {
|
|
148
|
-
const text = sourceCode.getText(expression);
|
|
149
|
-
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (isInsideEncodingCall(expression, sourceCode, trustedLibraries)) {
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
const userInputPatterns = [
|
|
156
|
-
/\breq\.(query|params|body|headers|cookies)/,
|
|
157
|
-
/\brequest\.(query|params|body)/,
|
|
158
|
-
/\buserInput\b/i,
|
|
159
|
-
/\binput\b/i,
|
|
160
|
-
/\bsearchParams\b/,
|
|
161
|
-
/\bparam\b/i,
|
|
162
|
-
];
|
|
163
|
-
const fullText = sourceCode.getText(node);
|
|
164
|
-
const exprText = sourceCode.getText(expression);
|
|
165
|
-
const isUserInput = userInputPatterns.some(pattern => pattern.test(text)) ||
|
|
166
|
-
userInputPatterns.some(pattern => pattern.test(fullText)) ||
|
|
167
|
-
userInputPatterns.some(pattern => pattern.test(exprText)) ||
|
|
168
|
-
(expression.type === 'MemberExpression' &&
|
|
169
|
-
userInputPatterns.some(pattern => {
|
|
170
|
-
return pattern.test(exprText);
|
|
171
|
-
}));
|
|
172
|
-
if (isUserInput) {
|
|
173
|
-
context.report({
|
|
174
|
-
node: expression,
|
|
175
|
-
messageId: 'unescapedUrlParameter',
|
|
176
|
-
data: {
|
|
177
|
-
parameter: text,
|
|
178
|
-
safeAlternative: `Use encodeURIComponent() or URLSearchParams: const url = \`https://example.com?q=\${encodeURIComponent(${text})}\`;`,
|
|
179
|
-
},
|
|
180
|
-
suggest: [
|
|
181
|
-
{
|
|
182
|
-
messageId: 'useEncodeURIComponent',
|
|
183
|
-
fix: (_fixer) => null,
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
messageId: 'useURLSearchParams',
|
|
187
|
-
fix: (_fixer) => null,
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function checkBinaryExpression(node) {
|
|
195
|
-
if (isTestFile) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (node.operator === '+') {
|
|
199
|
-
if (!isUrlConstruction(node, sourceCode)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (node.right.type !== 'Literal') {
|
|
203
|
-
const rightText = sourceCode.getText(node.right);
|
|
204
|
-
if (matchesIgnorePattern(rightText, ignorePatterns)) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (isInsideEncodingCall(node.right, sourceCode, trustedLibraries)) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const userInputPatterns = [
|
|
211
|
-
/\breq\.(query|params|body)/,
|
|
212
|
-
/\brequest\.(query|params|body)/,
|
|
213
|
-
/\buserInput\b/,
|
|
214
|
-
/\binput\b/,
|
|
215
|
-
];
|
|
216
|
-
const isUserInput = userInputPatterns.some(pattern => pattern.test(rightText));
|
|
217
|
-
if (isUserInput) {
|
|
218
|
-
context.report({
|
|
219
|
-
node: node.right,
|
|
220
|
-
messageId: 'unescapedUrlParameter',
|
|
221
|
-
data: {
|
|
222
|
-
parameter: rightText,
|
|
223
|
-
safeAlternative: `Use encodeURIComponent(): ${sourceCode.getText(node.left)} + encodeURIComponent(${rightText})`,
|
|
224
|
-
},
|
|
225
|
-
suggest: [
|
|
226
|
-
{
|
|
227
|
-
messageId: 'useEncodeURIComponent',
|
|
228
|
-
fix: (_fixer) => null,
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function isUserControlled(node, visited = new Set()) {
|
|
237
|
-
const text = sourceCode.getText(node);
|
|
238
|
-
const patterns = [
|
|
239
|
-
/\breq\.(query|params|body|headers|cookies)/,
|
|
240
|
-
/\brequest\.(query|params|body)/,
|
|
241
|
-
/\buserInput\b/i,
|
|
242
|
-
/\binput\b/i,
|
|
243
|
-
/\bsearchParams\b/,
|
|
244
|
-
/\bparam\b/i,
|
|
245
|
-
/\breturnUrl\b/i,
|
|
246
|
-
/\burl\b/i,
|
|
247
|
-
/\bredirect\b/i,
|
|
248
|
-
/\bnext\b/i,
|
|
249
|
-
];
|
|
250
|
-
if (patterns.some(p => p.test(text)))
|
|
251
|
-
return true;
|
|
252
|
-
if (node.type === 'Identifier') {
|
|
253
|
-
if (visited.has(node.name))
|
|
254
|
-
return false;
|
|
255
|
-
visited.add(node.name);
|
|
256
|
-
const scope = sourceCode.getScope(node);
|
|
257
|
-
const variable = scope.variables.find((v) => v.name === node.name);
|
|
258
|
-
if (variable && variable.defs.length > 0) {
|
|
259
|
-
const def = variable.defs[0];
|
|
260
|
-
if (def.type === 'Variable' && def.node.init) {
|
|
261
|
-
const init = def.node.init;
|
|
262
|
-
if (isUserControlled(init, visited))
|
|
263
|
-
return true;
|
|
264
|
-
if (init.type === 'TemplateLiteral') {
|
|
265
|
-
return init.expressions.some(expr => isUserControlled(expr, visited));
|
|
266
|
-
}
|
|
267
|
-
if (init.type === 'BinaryExpression') {
|
|
268
|
-
return isUserControlled(init.left, visited) || isUserControlled(init.right, visited);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
TemplateLiteral: checkTemplateLiteral,
|
|
277
|
-
BinaryExpression: checkBinaryExpression,
|
|
278
|
-
AssignmentExpression(node) {
|
|
279
|
-
if (isTestFile)
|
|
280
|
-
return;
|
|
281
|
-
const left = node.left;
|
|
282
|
-
let isLocationAssignment = false;
|
|
283
|
-
if (left.type === 'MemberExpression') {
|
|
284
|
-
const objectName = left.object.type === 'Identifier' ? left.object.name :
|
|
285
|
-
(left.object.type === 'MemberExpression' ? sourceCode.getText(left.object) : '');
|
|
286
|
-
const propName = left.property.type === 'Identifier' ? left.property.name : '';
|
|
287
|
-
if ((objectName === 'window' && propName === 'location') ||
|
|
288
|
-
(propName === 'href' && objectName.includes('location'))) {
|
|
289
|
-
isLocationAssignment = true;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
else if (left.type === 'Identifier' && left.name === 'location') {
|
|
293
|
-
isLocationAssignment = true;
|
|
294
|
-
}
|
|
295
|
-
if (isLocationAssignment) {
|
|
296
|
-
const right = node.right;
|
|
297
|
-
const rightText = sourceCode.getText(right);
|
|
298
|
-
if (right.type === 'TemplateLiteral' || right.type === 'BinaryExpression') {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (matchesIgnorePattern(rightText, ignorePatterns))
|
|
302
|
-
return;
|
|
303
|
-
if (isInsideEncodingCall(right, sourceCode, trustedLibraries))
|
|
304
|
-
return;
|
|
305
|
-
if (isUserControlled(right)) {
|
|
306
|
-
context.report({
|
|
307
|
-
node: right,
|
|
308
|
-
messageId: 'unescapedUrlParameter',
|
|
309
|
-
data: {
|
|
310
|
-
parameter: rightText,
|
|
311
|
-
safeAlternative: 'Validate and encode URL before redirecting',
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
},
|
|
319
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnescapedUrlParameter=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isInsideEncodingCall(node,sourceCode,trustedLibraries){let current=node;while(current){if(current.type==="CallExpression"){const callee=current.callee;if(callee.type==="Identifier"){const calleeName=callee.name;if(["encodeURIComponent","encodeURI","escape"].includes(calleeName)){return true}}if(callee.type==="MemberExpression"){const object=callee.object;if(object.type==="Identifier"){const objectName=object.name.toLowerCase();if(trustedLibraries.some(lib=>objectName.includes(lib.toLowerCase()))){return true}}}}if("parent"in current&¤t.parent){current=current.parent}else{break}}return false}function matchesIgnorePattern(text,ignorePatterns){return ignorePatterns.some(pattern=>{try{const regex=new RegExp(pattern,"i");return regex.test(text)}catch{return false}})}function isUrlConstruction(node,sourceCode){let text=sourceCode.getText(node);if(node.type==="TemplateLiteral"){text=node.quasis.map(q=>q.value.raw).join("")}const urlPatterns=[/\bhttps?:\/\//,/\bnew\s+URL\s*\(/,/\burl\s*[=:]\s*/,/\burl\s*\+/,/\bwindow\.location/,/\blocation\.href/,/\bwindow\.open\s*\(/,/\?[^=]+=/];return urlPatterns.some(pattern=>pattern.test(text))}exports.noUnescapedUrlParameter=(0,eslint_devkit_2.createRule)({name:"no-unescaped-url-parameter",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unescaped-url-parameter.md",description:"Detects unescaped URL parameters",cwe:"CWE-79",cvss:6.1},hasSuggestions:true,messages:{unescapedUrlParameter:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unescaped URL Parameter",cwe:"CWE-79",description:"Unescaped URL parameter detected: {{parameter}}",severity:"HIGH",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/79.html"}),useEncodeURIComponent:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use encodeURIComponent",description:"Use encodeURIComponent for URL params",severity:"LOW",fix:"`https://example.com?q=${encodeURIComponent(param)}`",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent"}),useURLSearchParams:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use URLSearchParams",description:"Use URLSearchParams for safe URL construction",severity:"LOW",fix:"new URLSearchParams({ q: param }).toString()",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow unescaped URL parameters in test files"},trustedLibraries:{type:"array",items:{type:"string"},default:["url","querystring"],description:"Trusted URL construction libraries"},ignorePatterns:{type:"array",items:{type:"string"},default:[],description:"Additional safe patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,trustedLibraries:["url","querystring"],ignorePatterns:[]}],create(context,[options={}]){const{allowInTests=false,trustedLibraries=["url","querystring"],ignorePatterns=[]}=options;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);const sourceCode=context.sourceCode;function checkTemplateLiteral(node){if(isTestFile){return}if(!isUrlConstruction(node,sourceCode)){return}for(const expression of node.expressions){const text=sourceCode.getText(expression);if(matchesIgnorePattern(text,ignorePatterns)){continue}if(isInsideEncodingCall(expression,sourceCode,trustedLibraries)){continue}const userInputPatterns=[/\breq\.(query|params|body|headers|cookies)/,/\brequest\.(query|params|body)/,/\buserInput\b/i,/\binput\b/i,/\bsearchParams\b/,/\bparam\b/i];const fullText=sourceCode.getText(node);const exprText=sourceCode.getText(expression);const isUserInput=userInputPatterns.some(pattern=>pattern.test(text))||userInputPatterns.some(pattern=>pattern.test(fullText))||userInputPatterns.some(pattern=>pattern.test(exprText))||expression.type==="MemberExpression"&&userInputPatterns.some(pattern=>{return pattern.test(exprText)});if(isUserInput){context.report({node:expression,messageId:"unescapedUrlParameter",data:{parameter:text,safeAlternative:`Use encodeURIComponent() or URLSearchParams: const url = \`https://example.com?q=\${encodeURIComponent(${text})}\`;`},suggest:[{messageId:"useEncodeURIComponent",fix:_fixer=>null},{messageId:"useURLSearchParams",fix:_fixer=>null}]})}}}function checkBinaryExpression(node){if(isTestFile){return}if(node.operator==="+"){if(!isUrlConstruction(node,sourceCode)){return}if(node.right.type!=="Literal"){const rightText=sourceCode.getText(node.right);if(matchesIgnorePattern(rightText,ignorePatterns)){return}if(isInsideEncodingCall(node.right,sourceCode,trustedLibraries)){return}const userInputPatterns=[/\breq\.(query|params|body)/,/\brequest\.(query|params|body)/,/\buserInput\b/,/\binput\b/];const isUserInput=userInputPatterns.some(pattern=>pattern.test(rightText));if(isUserInput){context.report({node:node.right,messageId:"unescapedUrlParameter",data:{parameter:rightText,safeAlternative:`Use encodeURIComponent(): ${sourceCode.getText(node.left)} + encodeURIComponent(${rightText})`},suggest:[{messageId:"useEncodeURIComponent",fix:_fixer=>null}]})}}}}function isUserControlled(node,visited=new Set){const text=sourceCode.getText(node);const patterns=[/\breq\.(query|params|body|headers|cookies)/,/\brequest\.(query|params|body)/,/\buserInput\b/i,/\binput\b/i,/\bsearchParams\b/,/\bparam\b/i,/\breturnUrl\b/i,/\burl\b/i,/\bredirect\b/i,/\bnext\b/i];if(patterns.some(p=>p.test(text)))return true;if(node.type==="Identifier"){if(visited.has(node.name))return false;visited.add(node.name);const scope=sourceCode.getScope(node);const variable=scope.variables.find(v=>v.name===node.name);if(variable&&variable.defs.length>0){const def=variable.defs[0];if(def.type==="Variable"&&def.node.init){const init=def.node.init;if(isUserControlled(init,visited))return true;if(init.type==="TemplateLiteral"){return init.expressions.some(expr=>isUserControlled(expr,visited))}if(init.type==="BinaryExpression"){return isUserControlled(init.left,visited)||isUserControlled(init.right,visited)}}}}return false}return{TemplateLiteral:checkTemplateLiteral,BinaryExpression:checkBinaryExpression,AssignmentExpression(node){if(isTestFile)return;const left=node.left;let isLocationAssignment=false;if(left.type==="MemberExpression"){const objectName=left.object.type==="Identifier"?left.object.name:left.object.type==="MemberExpression"?sourceCode.getText(left.object):"";const propName=left.property.type==="Identifier"?left.property.name:"";if(objectName==="window"&&propName==="location"||propName==="href"&&objectName.includes("location")){isLocationAssignment=true}}else if(left.type==="Identifier"&&left.name==="location"){isLocationAssignment=true}if(isLocationAssignment){const right=node.right;const rightText=sourceCode.getText(right);if(right.type==="TemplateLiteral"||right.type==="BinaryExpression"){return}if(matchesIgnorePattern(rightText,ignorePatterns))return;if(isInsideEncodingCall(right,sourceCode,trustedLibraries))return;if(isUserControlled(right)){context.report({node:right,messageId:"unescapedUrlParameter",data:{parameter:rightText,safeAlternative:"Validate and encode URL before redirecting"}})}}}}}});
|
|
@@ -1,75 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnsafeEvalCsp = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noUnsafeEvalCsp = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-unsafe-eval-csp',
|
|
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-unsafe-eval-csp.md',
|
|
11
|
-
description: "Disallow 'unsafe-eval' in Content Security Policy",
|
|
12
|
-
cwe: 'CWE-95',
|
|
13
|
-
cvss: 8.1,
|
|
14
|
-
},
|
|
15
|
-
hasSuggestions: true,
|
|
16
|
-
messages: {
|
|
17
|
-
unsafeEval: (0, eslint_devkit_1.formatLLMMessage)({
|
|
18
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
19
|
-
issueName: "CSP 'unsafe-eval' Detected",
|
|
20
|
-
cwe: 'CWE-95',
|
|
21
|
-
owasp: 'A03:2021',
|
|
22
|
-
cvss: 8.1,
|
|
23
|
-
description: "'unsafe-eval' in CSP allows eval(), new Function(), and setTimeout(string). This enables code injection attacks.",
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: "Remove 'unsafe-eval' and refactor code to avoid eval-like patterns.",
|
|
26
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src',
|
|
27
|
-
}),
|
|
28
|
-
removeUnsafeEval: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
30
|
-
issueName: "Remove 'unsafe-eval'",
|
|
31
|
-
description: 'Refactor code to avoid eval() and remove unsafe-eval from CSP',
|
|
32
|
-
severity: 'LOW',
|
|
33
|
-
fix: "script-src 'self'; // Remove 'unsafe-eval'",
|
|
34
|
-
documentationLink: 'https://web.dev/strict-csp/',
|
|
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 UNSAFE_EVAL_PATTERN = /'unsafe-eval'/gi;
|
|
54
|
-
function checkForUnsafeEval(node, value) {
|
|
55
|
-
if (UNSAFE_EVAL_PATTERN.test(value)) {
|
|
56
|
-
context.report({
|
|
57
|
-
node,
|
|
58
|
-
messageId: 'unsafeEval',
|
|
59
|
-
suggest: [{ messageId: 'removeUnsafeEval', fix: () => null }],
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
Literal(node) {
|
|
65
|
-
if (typeof node.value === 'string') {
|
|
66
|
-
checkForUnsafeEval(node, node.value);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
TemplateLiteral(node) {
|
|
70
|
-
const value = node.quasis.map((q) => q.value.raw).join('');
|
|
71
|
-
checkForUnsafeEval(node, value);
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafeEvalCsp=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noUnsafeEvalCsp=(0,eslint_devkit_1.createRule)({name:"no-unsafe-eval-csp",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unsafe-eval-csp.md",description:"Disallow 'unsafe-eval' in Content Security Policy",cwe:"CWE-95",cvss:8.1},hasSuggestions:true,messages:{unsafeEval:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"CSP 'unsafe-eval' Detected",cwe:"CWE-95",owasp:"A03:2021",cvss:8.1,description:"'unsafe-eval' in CSP allows eval(), new Function(), and setTimeout(string). This enables code injection attacks.",severity:"HIGH",fix:"Remove 'unsafe-eval' and refactor code to avoid eval-like patterns.",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src"}),removeUnsafeEval:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Remove 'unsafe-eval'",description:"Refactor code to avoid eval() and remove unsafe-eval from CSP",severity:"LOW",fix:"script-src 'self'; // Remove 'unsafe-eval'",documentationLink:"https://web.dev/strict-csp/"})},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 UNSAFE_EVAL_PATTERN=/'unsafe-eval'/gi;function checkForUnsafeEval(node,value){if(UNSAFE_EVAL_PATTERN.test(value)){context.report({node,messageId:"unsafeEval",suggest:[{messageId:"removeUnsafeEval",fix:()=>null}]})}}return{Literal(node){if(typeof node.value==="string"){checkForUnsafeEval(node,node.value)}},TemplateLiteral(node){const value=node.quasis.map(q=>q.value.raw).join("");checkForUnsafeEval(node,value)}}}});
|
|
@@ -1,75 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnsafeInlineCsp = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noUnsafeInlineCsp = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-unsafe-inline-csp',
|
|
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-unsafe-inline-csp.md',
|
|
11
|
-
description: "Disallow 'unsafe-inline' in Content Security Policy",
|
|
12
|
-
cwe: 'CWE-79',
|
|
13
|
-
cvss: 7.5,
|
|
14
|
-
},
|
|
15
|
-
hasSuggestions: true,
|
|
16
|
-
messages: {
|
|
17
|
-
unsafeInline: (0, eslint_devkit_1.formatLLMMessage)({
|
|
18
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
19
|
-
issueName: "CSP 'unsafe-inline' Detected",
|
|
20
|
-
cwe: 'CWE-79',
|
|
21
|
-
owasp: 'A03:2021',
|
|
22
|
-
cvss: 7.5,
|
|
23
|
-
description: "'unsafe-inline' in CSP allows inline scripts/styles to execute, defeating XSS protection.",
|
|
24
|
-
severity: 'HIGH',
|
|
25
|
-
fix: "Use nonces or hashes instead: script-src 'nonce-abc123' or script-src 'sha256-...'",
|
|
26
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP',
|
|
27
|
-
}),
|
|
28
|
-
useNonceOrHash: (0, eslint_devkit_1.formatLLMMessage)({
|
|
29
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
30
|
-
issueName: 'Use Nonce or Hash',
|
|
31
|
-
description: 'Replace unsafe-inline with nonces or hashes',
|
|
32
|
-
severity: 'LOW',
|
|
33
|
-
fix: "script-src 'self' 'nonce-randomValue'; (generate nonce per-request)",
|
|
34
|
-
documentationLink: 'https://content-security-policy.com/nonce/',
|
|
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 UNSAFE_INLINE_PATTERN = /'unsafe-inline'/gi;
|
|
54
|
-
function checkForUnsafeInline(node, value) {
|
|
55
|
-
if (UNSAFE_INLINE_PATTERN.test(value)) {
|
|
56
|
-
context.report({
|
|
57
|
-
node,
|
|
58
|
-
messageId: 'unsafeInline',
|
|
59
|
-
suggest: [{ messageId: 'useNonceOrHash', fix: () => null }],
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
Literal(node) {
|
|
65
|
-
if (typeof node.value === 'string') {
|
|
66
|
-
checkForUnsafeInline(node, node.value);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
TemplateLiteral(node) {
|
|
70
|
-
const value = node.quasis.map((q) => q.value.raw).join('');
|
|
71
|
-
checkForUnsafeInline(node, value);
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafeInlineCsp=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noUnsafeInlineCsp=(0,eslint_devkit_1.createRule)({name:"no-unsafe-inline-csp",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unsafe-inline-csp.md",description:"Disallow 'unsafe-inline' in Content Security Policy",cwe:"CWE-79",cvss:7.5},hasSuggestions:true,messages:{unsafeInline:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"CSP 'unsafe-inline' Detected",cwe:"CWE-79",owasp:"A03:2021",cvss:7.5,description:"'unsafe-inline' in CSP allows inline scripts/styles to execute, defeating XSS protection.",severity:"HIGH",fix:"Use nonces or hashes instead: script-src 'nonce-abc123' or script-src 'sha256-...'",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP"}),useNonceOrHash:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Nonce or Hash",description:"Replace unsafe-inline with nonces or hashes",severity:"LOW",fix:"script-src 'self' 'nonce-randomValue'; (generate nonce per-request)",documentationLink:"https://content-security-policy.com/nonce/"})},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 UNSAFE_INLINE_PATTERN=/'unsafe-inline'/gi;function checkForUnsafeInline(node,value){if(UNSAFE_INLINE_PATTERN.test(value)){context.report({node,messageId:"unsafeInline",suggest:[{messageId:"useNonceOrHash",fix:()=>null}]})}}return{Literal(node){if(typeof node.value==="string"){checkForUnsafeInline(node,node.value)}},TemplateLiteral(node){const value=node.quasis.map(q=>q.value.raw).join("");checkForUnsafeInline(node,value)}}}});
|
|
@@ -1,59 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnvalidatedDeeplinks = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noUnvalidatedDeeplinks = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-unvalidated-deeplinks',
|
|
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-unvalidated-deeplinks.md',
|
|
11
|
-
description: 'Require validation of deep link URLs',
|
|
12
|
-
cwe: 'CWE-939',
|
|
13
|
-
cvss: 7.5,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
18
|
-
issueName: 'Unvalidated Deeplink',
|
|
19
|
-
cwe: 'CWE-939',
|
|
20
|
-
description: 'Deep link URL used without validation - potential open redirect',
|
|
21
|
-
severity: 'HIGH',
|
|
22
|
-
fix: 'Validate deep link URLs against a whitelist before navigation',
|
|
23
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/939.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.object.type === 'Identifier' &&
|
|
37
|
-
node.callee.object.name === 'Linking' &&
|
|
38
|
-
node.callee.property.type === 'Identifier' &&
|
|
39
|
-
node.callee.property.name === 'openURL') {
|
|
40
|
-
const urlArg = node.arguments[0];
|
|
41
|
-
if (urlArg && urlArg.type === 'Identifier') {
|
|
42
|
-
report(node);
|
|
43
|
-
}
|
|
44
|
-
if (urlArg && urlArg.type === 'MemberExpression') {
|
|
45
|
-
report(node);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (node.callee.type === 'MemberExpression' &&
|
|
49
|
-
node.callee.property.type === 'Identifier' &&
|
|
50
|
-
node.callee.property.name === 'navigate') {
|
|
51
|
-
const urlArg = node.arguments[0];
|
|
52
|
-
if (urlArg && urlArg.type === 'Identifier') {
|
|
53
|
-
report(node);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnvalidatedDeeplinks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noUnvalidatedDeeplinks=(0,eslint_devkit_1.createRule)({name:"no-unvalidated-deeplinks",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unvalidated-deeplinks.md",description:"Require validation of deep link URLs",cwe:"CWE-939",cvss:7.5},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unvalidated Deeplink",cwe:"CWE-939",description:"Deep link URL used without validation - potential open redirect",severity:"HIGH",fix:"Validate deep link URLs against a whitelist before navigation",documentationLink:"https://cwe.mitre.org/data/definitions/939.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&node.callee.object.name==="Linking"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="openURL"){const urlArg=node.arguments[0];if(urlArg&&urlArg.type==="Identifier"){report(node)}if(urlArg&&urlArg.type==="MemberExpression"){report(node)}}if(node.callee.type==="MemberExpression"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="navigate"){const urlArg=node.arguments[0];if(urlArg&&urlArg.type==="Identifier"){report(node)}}}}}});
|