eslint-plugin-browser-security 1.1.1 → 1.2.1
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/LICENSE +2 -0
- package/README.md +78 -56
- package/package.json +6 -5
- package/src/index.js +62 -0
- package/src/rules/detect-mixed-content/index.d.ts +12 -0
- package/src/rules/detect-mixed-content/index.js +45 -0
- package/src/rules/no-allow-arbitrary-loads/index.d.ts +12 -0
- package/src/rules/no-allow-arbitrary-loads/index.js +48 -0
- package/src/rules/no-clickjacking/index.d.ts +36 -0
- package/src/rules/no-clickjacking/index.js +401 -0
- package/src/rules/no-client-side-auth-logic/index.d.ts +12 -0
- package/src/rules/no-client-side-auth-logic/index.js +74 -0
- package/src/rules/no-cookie-auth-tokens/index.d.ts +3 -1
- package/src/rules/no-credentials-in-query-params/index.d.ts +12 -0
- package/src/rules/no-credentials-in-query-params/index.js +62 -0
- package/src/rules/no-disabled-certificate-validation/index.d.ts +12 -0
- package/src/rules/no-disabled-certificate-validation/index.js +66 -0
- package/src/rules/no-dynamic-service-worker-url/index.d.ts +3 -1
- package/src/rules/no-eval/index.d.ts +3 -1
- package/src/rules/no-filereader-innerhtml/index.d.ts +3 -1
- package/src/rules/no-http-urls/index.d.ts +17 -0
- package/src/rules/no-http-urls/index.js +119 -0
- package/src/rules/no-innerhtml/index.d.ts +3 -1
- package/src/rules/no-insecure-redirects/index.d.ts +26 -0
- package/src/rules/no-insecure-redirects/index.js +221 -0
- package/src/rules/no-insecure-websocket/index.d.ts +12 -0
- package/src/rules/no-insecure-websocket/index.js +66 -0
- package/src/rules/no-jwt-in-storage/index.d.ts +3 -1
- package/src/rules/no-missing-cors-check/index.d.ts +28 -0
- package/src/rules/no-missing-cors-check/index.js +399 -0
- package/src/rules/no-missing-csrf-protection/index.d.ts +30 -0
- package/src/rules/no-missing-csrf-protection/index.js +185 -0
- package/src/rules/no-missing-security-headers/index.d.ts +26 -0
- package/src/rules/no-missing-security-headers/index.js +223 -0
- package/src/rules/no-password-in-url/index.d.ts +12 -0
- package/src/rules/no-password-in-url/index.js +55 -0
- package/src/rules/no-permissive-cors/index.d.ts +12 -0
- package/src/rules/no-permissive-cors/index.js +74 -0
- package/src/rules/no-postmessage-innerhtml/index.d.ts +3 -1
- package/src/rules/no-postmessage-wildcard-origin/index.d.ts +3 -1
- package/src/rules/no-sensitive-cookie-js/index.d.ts +3 -1
- package/src/rules/no-sensitive-data-in-analytics/index.d.ts +12 -0
- package/src/rules/no-sensitive-data-in-analytics/index.js +66 -0
- package/src/rules/no-sensitive-data-in-cache/index.d.ts +12 -0
- package/src/rules/no-sensitive-data-in-cache/index.js +53 -0
- package/src/rules/no-sensitive-indexeddb/index.d.ts +3 -1
- package/src/rules/no-sensitive-localstorage/index.d.ts +3 -1
- package/src/rules/no-sensitive-sessionstorage/index.d.ts +3 -1
- package/src/rules/no-tracking-without-consent/index.d.ts +12 -0
- package/src/rules/no-tracking-without-consent/index.js +72 -0
- package/src/rules/no-unencrypted-transmission/index.d.ts +30 -0
- package/src/rules/no-unencrypted-transmission/index.js +241 -0
- package/src/rules/no-unescaped-url-parameter/index.d.ts +28 -0
- package/src/rules/no-unescaped-url-parameter/index.js +357 -0
- package/src/rules/no-unsafe-eval-csp/index.d.ts +3 -1
- package/src/rules/no-unsafe-inline-csp/index.d.ts +3 -1
- package/src/rules/no-unvalidated-deeplinks/index.d.ts +12 -0
- package/src/rules/no-unvalidated-deeplinks/index.js +67 -0
- package/src/rules/no-websocket-eval/index.d.ts +3 -1
- package/src/rules/no-websocket-innerhtml/index.d.ts +3 -1
- package/src/rules/no-worker-message-innerhtml/index.d.ts +3 -1
- package/src/rules/require-blob-url-revocation/index.d.ts +3 -1
- package/src/rules/require-cookie-secure-attrs/index.d.ts +3 -1
- package/src/rules/require-csp-headers/index.d.ts +12 -0
- package/src/rules/require-csp-headers/index.js +69 -0
- package/src/rules/require-https-only/index.d.ts +12 -0
- package/src/rules/require-https-only/index.js +67 -0
- package/src/rules/require-mime-type-validation/index.d.ts +12 -0
- package/src/rules/require-mime-type-validation/index.js +71 -0
- package/src/rules/require-postmessage-origin-check/index.d.ts +3 -1
- package/src/rules/require-url-validation/index.d.ts +12 -0
- package/src/rules/require-url-validation/index.js +77 -0
- package/src/rules/require-websocket-wss/index.d.ts +3 -1
- package/AGENTS.md +0 -97
- package/CHANGELOG.md +0 -81
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noUnescapedUrlParameter = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
+
/**
|
|
12
|
+
* Check if a node is inside a URL encoding function call
|
|
13
|
+
*/
|
|
14
|
+
function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
15
|
+
let current = node;
|
|
16
|
+
while (current) {
|
|
17
|
+
if (current.type === 'CallExpression') {
|
|
18
|
+
const callee = current.callee;
|
|
19
|
+
// Check for encodeURIComponent, encodeURI
|
|
20
|
+
if (callee.type === 'Identifier') {
|
|
21
|
+
const calleeName = callee.name;
|
|
22
|
+
if (['encodeURIComponent', 'encodeURI', 'escape'].includes(calleeName)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Check if it's a trusted library call
|
|
27
|
+
if (callee.type === 'MemberExpression') {
|
|
28
|
+
const object = callee.object;
|
|
29
|
+
if (object.type === 'Identifier') {
|
|
30
|
+
const objectName = object.name.toLowerCase();
|
|
31
|
+
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Traverse up the AST
|
|
38
|
+
if ('parent' in current && current.parent) {
|
|
39
|
+
current = current.parent;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a string matches any ignore pattern
|
|
49
|
+
*/
|
|
50
|
+
function matchesIgnorePattern(text, ignorePatterns) {
|
|
51
|
+
return ignorePatterns.some(pattern => {
|
|
52
|
+
try {
|
|
53
|
+
const regex = new RegExp(pattern, 'i');
|
|
54
|
+
return regex.test(text);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if a node is a URL construction pattern
|
|
63
|
+
*/
|
|
64
|
+
function isUrlConstruction(node, sourceCode) {
|
|
65
|
+
let text = sourceCode.getText(node);
|
|
66
|
+
// For template literals, combine raw strings to improve pattern detection
|
|
67
|
+
if (node.type === 'TemplateLiteral') {
|
|
68
|
+
text = node.quasis.map(q => q.value.raw).join('');
|
|
69
|
+
}
|
|
70
|
+
// Check for URL construction patterns
|
|
71
|
+
const urlPatterns = [
|
|
72
|
+
/\bhttps?:\/\//, // HTTP/HTTPS URLs
|
|
73
|
+
/\bnew\s+URL\s*\(/,
|
|
74
|
+
/\burl\s*[=:]\s*/, // url = or url:
|
|
75
|
+
/\burl\s*\+/, // url +
|
|
76
|
+
/\bwindow\.location/,
|
|
77
|
+
/\blocation\.href/,
|
|
78
|
+
/\bwindow\.open\s*\(/,
|
|
79
|
+
/\?[^=]+=/, // Query parameters
|
|
80
|
+
];
|
|
81
|
+
return urlPatterns.some(pattern => pattern.test(text));
|
|
82
|
+
}
|
|
83
|
+
exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
84
|
+
name: 'no-unescaped-url-parameter',
|
|
85
|
+
meta: {
|
|
86
|
+
type: 'problem',
|
|
87
|
+
docs: {
|
|
88
|
+
description: 'Detects unescaped URL parameters',
|
|
89
|
+
},
|
|
90
|
+
hasSuggestions: true,
|
|
91
|
+
messages: {
|
|
92
|
+
unescapedUrlParameter: (0, eslint_devkit_1.formatLLMMessage)({
|
|
93
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
94
|
+
issueName: 'Unescaped URL Parameter',
|
|
95
|
+
cwe: 'CWE-79',
|
|
96
|
+
description: 'Unescaped URL parameter detected: {{parameter}}',
|
|
97
|
+
severity: 'HIGH',
|
|
98
|
+
fix: '{{safeAlternative}}',
|
|
99
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/79.html',
|
|
100
|
+
}),
|
|
101
|
+
useEncodeURIComponent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
102
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
103
|
+
issueName: 'Use encodeURIComponent',
|
|
104
|
+
description: 'Use encodeURIComponent for URL params',
|
|
105
|
+
severity: 'LOW',
|
|
106
|
+
fix: '`https://example.com?q=${encodeURIComponent(param)}`',
|
|
107
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent',
|
|
108
|
+
}),
|
|
109
|
+
useURLSearchParams: (0, eslint_devkit_1.formatLLMMessage)({
|
|
110
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
111
|
+
issueName: 'Use URLSearchParams',
|
|
112
|
+
description: 'Use URLSearchParams for safe URL construction',
|
|
113
|
+
severity: 'LOW',
|
|
114
|
+
fix: 'new URLSearchParams({ q: param }).toString()',
|
|
115
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams',
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
schema: [
|
|
119
|
+
{
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
allowInTests: {
|
|
123
|
+
type: 'boolean',
|
|
124
|
+
default: false,
|
|
125
|
+
description: 'Allow unescaped URL parameters in test files',
|
|
126
|
+
},
|
|
127
|
+
trustedLibraries: {
|
|
128
|
+
type: 'array',
|
|
129
|
+
items: { type: 'string' },
|
|
130
|
+
default: ['url', 'querystring'],
|
|
131
|
+
description: 'Trusted URL construction libraries',
|
|
132
|
+
},
|
|
133
|
+
ignorePatterns: {
|
|
134
|
+
type: 'array',
|
|
135
|
+
items: { type: 'string' },
|
|
136
|
+
default: [],
|
|
137
|
+
description: 'Additional safe patterns to ignore',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
defaultOptions: [
|
|
145
|
+
{
|
|
146
|
+
allowInTests: false,
|
|
147
|
+
trustedLibraries: ['url', 'querystring'],
|
|
148
|
+
ignorePatterns: [],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
create(context, [options = {}]) {
|
|
152
|
+
const { allowInTests = false, trustedLibraries = ['url', 'querystring'], ignorePatterns = [], } = options;
|
|
153
|
+
const filename = context.getFilename();
|
|
154
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
155
|
+
const sourceCode = context.sourceCode || context.sourceCode;
|
|
156
|
+
function checkTemplateLiteral(node) {
|
|
157
|
+
if (isTestFile) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Check if this is a URL construction
|
|
161
|
+
if (!isUrlConstruction(node, sourceCode)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Check each expression in the template
|
|
165
|
+
for (const expression of node.expressions) {
|
|
166
|
+
const text = sourceCode.getText(expression);
|
|
167
|
+
// Check if it matches any ignore pattern
|
|
168
|
+
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// Check if it's already encoded
|
|
172
|
+
if (isInsideEncodingCall(expression, sourceCode, trustedLibraries)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
// Check if it's a user input pattern
|
|
176
|
+
const userInputPatterns = [
|
|
177
|
+
/\breq\.(query|params|body|headers|cookies)/,
|
|
178
|
+
/\brequest\.(query|params|body)/,
|
|
179
|
+
/\buserInput\b/i,
|
|
180
|
+
/\binput\b/i,
|
|
181
|
+
/\bsearchParams\b/,
|
|
182
|
+
/\bparam\b/i, // Generic param variable
|
|
183
|
+
];
|
|
184
|
+
// Check both the expression text and the full template literal
|
|
185
|
+
// This catches nested patterns like req.query.id
|
|
186
|
+
const fullText = sourceCode.getText(node);
|
|
187
|
+
const exprText = sourceCode.getText(expression);
|
|
188
|
+
const isUserInput = userInputPatterns.some(pattern => pattern.test(text)) ||
|
|
189
|
+
userInputPatterns.some(pattern => pattern.test(fullText)) ||
|
|
190
|
+
userInputPatterns.some(pattern => pattern.test(exprText)) ||
|
|
191
|
+
// Also check for nested member expressions like req.query.id
|
|
192
|
+
(expression.type === 'MemberExpression' &&
|
|
193
|
+
userInputPatterns.some(pattern => {
|
|
194
|
+
// Check the full expression including nested properties
|
|
195
|
+
return pattern.test(exprText);
|
|
196
|
+
}));
|
|
197
|
+
if (isUserInput) {
|
|
198
|
+
context.report({
|
|
199
|
+
node: expression,
|
|
200
|
+
messageId: 'unescapedUrlParameter',
|
|
201
|
+
data: {
|
|
202
|
+
parameter: text,
|
|
203
|
+
safeAlternative: `Use encodeURIComponent() or URLSearchParams: const url = \`https://example.com?q=\${encodeURIComponent(${text})}\`;`,
|
|
204
|
+
},
|
|
205
|
+
suggest: [
|
|
206
|
+
{
|
|
207
|
+
messageId: 'useEncodeURIComponent',
|
|
208
|
+
fix: (_fixer) => null,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
messageId: 'useURLSearchParams',
|
|
212
|
+
fix: (_fixer) => null,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function checkBinaryExpression(node) {
|
|
220
|
+
if (isTestFile) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// Check for string concatenation in URL construction
|
|
224
|
+
if (node.operator === '+') {
|
|
225
|
+
if (!isUrlConstruction(node, sourceCode)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Check right side (usually the parameter)
|
|
229
|
+
if (node.right.type !== 'Literal') {
|
|
230
|
+
const rightText = sourceCode.getText(node.right);
|
|
231
|
+
// Check if it matches any ignore pattern
|
|
232
|
+
if (matchesIgnorePattern(rightText, ignorePatterns)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Check if it's already encoded
|
|
236
|
+
if (isInsideEncodingCall(node.right, sourceCode, trustedLibraries)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// Check if it's a user input pattern
|
|
240
|
+
const userInputPatterns = [
|
|
241
|
+
/\breq\.(query|params|body)/,
|
|
242
|
+
/\brequest\.(query|params|body)/,
|
|
243
|
+
/\buserInput\b/,
|
|
244
|
+
/\binput\b/,
|
|
245
|
+
];
|
|
246
|
+
const isUserInput = userInputPatterns.some(pattern => pattern.test(rightText));
|
|
247
|
+
if (isUserInput) {
|
|
248
|
+
context.report({
|
|
249
|
+
node: node.right,
|
|
250
|
+
messageId: 'unescapedUrlParameter',
|
|
251
|
+
data: {
|
|
252
|
+
parameter: rightText,
|
|
253
|
+
safeAlternative: `Use encodeURIComponent(): ${sourceCode.getText(node.left)} + encodeURIComponent(${rightText})`,
|
|
254
|
+
},
|
|
255
|
+
suggest: [
|
|
256
|
+
{
|
|
257
|
+
messageId: 'useEncodeURIComponent',
|
|
258
|
+
fix: (_fixer) => null,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function isUserControlled(node, visited = new Set()) {
|
|
267
|
+
const text = sourceCode.getText(node);
|
|
268
|
+
const patterns = [
|
|
269
|
+
/\breq\.(query|params|body|headers|cookies)/,
|
|
270
|
+
/\brequest\.(query|params|body)/,
|
|
271
|
+
/\buserInput\b/i,
|
|
272
|
+
/\binput\b/i,
|
|
273
|
+
/\bsearchParams\b/,
|
|
274
|
+
/\bparam\b/i,
|
|
275
|
+
/\breturnUrl\b/i,
|
|
276
|
+
/\burl\b/i,
|
|
277
|
+
/\bredirect\b/i,
|
|
278
|
+
/\bnext\b/i,
|
|
279
|
+
];
|
|
280
|
+
if (patterns.some(p => p.test(text)))
|
|
281
|
+
return true;
|
|
282
|
+
// Trace identifiers
|
|
283
|
+
if (node.type === 'Identifier') {
|
|
284
|
+
if (visited.has(node.name))
|
|
285
|
+
return false;
|
|
286
|
+
visited.add(node.name);
|
|
287
|
+
const scope = sourceCode.getScope(node);
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
289
|
+
const variable = scope.variables.find((v) => v.name === node.name);
|
|
290
|
+
if (variable && variable.defs.length > 0) {
|
|
291
|
+
const def = variable.defs[0];
|
|
292
|
+
if (def.type === 'Variable' && def.node.init) {
|
|
293
|
+
const init = def.node.init;
|
|
294
|
+
// Check if init is constructed from other user inputs
|
|
295
|
+
if (isUserControlled(init, visited))
|
|
296
|
+
return true;
|
|
297
|
+
// Check if init is a TemplateLiteral containing user inputs in expressions
|
|
298
|
+
if (init.type === 'TemplateLiteral') {
|
|
299
|
+
return init.expressions.some(expr => isUserControlled(expr, visited));
|
|
300
|
+
}
|
|
301
|
+
// Check if init is BinaryExpression (concatenation)
|
|
302
|
+
if (init.type === 'BinaryExpression') {
|
|
303
|
+
return isUserControlled(init.left, visited) || isUserControlled(init.right, visited);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
TemplateLiteral: checkTemplateLiteral,
|
|
312
|
+
BinaryExpression: checkBinaryExpression,
|
|
313
|
+
AssignmentExpression(node) {
|
|
314
|
+
if (isTestFile)
|
|
315
|
+
return;
|
|
316
|
+
// Check for window.location = ... or window.location.href = ...
|
|
317
|
+
const left = node.left;
|
|
318
|
+
let isLocationAssignment = false;
|
|
319
|
+
if (left.type === 'MemberExpression') {
|
|
320
|
+
const objectName = left.object.type === 'Identifier' ? left.object.name :
|
|
321
|
+
(left.object.type === 'MemberExpression' ? sourceCode.getText(left.object) : '');
|
|
322
|
+
const propName = left.property.type === 'Identifier' ? left.property.name : '';
|
|
323
|
+
if ((objectName === 'window' && propName === 'location') ||
|
|
324
|
+
(propName === 'href' && objectName.includes('location'))) {
|
|
325
|
+
isLocationAssignment = true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else if (left.type === 'Identifier' && left.name === 'location') {
|
|
329
|
+
// In browser location = ... is valid
|
|
330
|
+
isLocationAssignment = true;
|
|
331
|
+
}
|
|
332
|
+
if (isLocationAssignment) {
|
|
333
|
+
const right = node.right;
|
|
334
|
+
const rightText = sourceCode.getText(right);
|
|
335
|
+
// Skip TemplateLiteral and BinaryExpression as they are covered by their own visitors
|
|
336
|
+
if (right.type === 'TemplateLiteral' || right.type === 'BinaryExpression') {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (matchesIgnorePattern(rightText, ignorePatterns))
|
|
340
|
+
return;
|
|
341
|
+
if (isInsideEncodingCall(right, sourceCode, trustedLibraries))
|
|
342
|
+
return;
|
|
343
|
+
if (isUserControlled(right)) {
|
|
344
|
+
context.report({
|
|
345
|
+
node: right,
|
|
346
|
+
messageId: 'unescapedUrlParameter',
|
|
347
|
+
data: {
|
|
348
|
+
parameter: rightText,
|
|
349
|
+
safeAlternative: 'Validate and encode URL before redirecting',
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
});
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const noUnsafeEvalCsp: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const noUnsafeEvalCsp: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const noUnsafeInlineCsp: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const noUnsafeInlineCsp: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
export interface Options {
|
|
7
|
+
}
|
|
8
|
+
type RuleOptions = [Options?];
|
|
9
|
+
export declare const noUnvalidatedDeeplinks: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noUnvalidatedDeeplinks = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Require validation of deep link URLs
|
|
11
|
+
*/
|
|
12
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
|
+
exports.noUnvalidatedDeeplinks = (0, eslint_devkit_1.createRule)({
|
|
14
|
+
name: 'no-unvalidated-deeplinks',
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Require validation of deep link URLs',
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
23
|
+
issueName: 'Unvalidated Deeplink',
|
|
24
|
+
cwe: 'CWE-939',
|
|
25
|
+
description: 'Deep link URL used without validation - potential open redirect',
|
|
26
|
+
severity: 'HIGH',
|
|
27
|
+
fix: 'Validate deep link URLs against a whitelist before navigation',
|
|
28
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/939.html',
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
function report(node) {
|
|
36
|
+
context.report({ node, messageId: 'violationDetected' });
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
// Detect Linking.openURL() with variable argument (React Native)
|
|
41
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
42
|
+
node.callee.object.type === 'Identifier' &&
|
|
43
|
+
node.callee.object.name === 'Linking' &&
|
|
44
|
+
node.callee.property.type === 'Identifier' &&
|
|
45
|
+
node.callee.property.name === 'openURL') {
|
|
46
|
+
const urlArg = node.arguments[0];
|
|
47
|
+
// Flag if URL is a variable/expression, not a literal
|
|
48
|
+
if (urlArg && urlArg.type === 'Identifier') {
|
|
49
|
+
report(node);
|
|
50
|
+
}
|
|
51
|
+
if (urlArg && urlArg.type === 'MemberExpression') {
|
|
52
|
+
report(node);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Detect navigation.navigate with external URLs
|
|
56
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
57
|
+
node.callee.property.type === 'Identifier' &&
|
|
58
|
+
node.callee.property.name === 'navigate') {
|
|
59
|
+
const urlArg = node.arguments[0];
|
|
60
|
+
if (urlArg && urlArg.type === 'Identifier') {
|
|
61
|
+
report(node);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const noWebsocketEval: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const noWebsocketEval: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const noWebsocketInnerhtml: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const noWebsocketInnerhtml: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const noWorkerMessageInnerhtml: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const noWorkerMessageInnerhtml: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -18,5 +18,7 @@ export interface Options {
|
|
|
18
18
|
allowInTests?: boolean;
|
|
19
19
|
}
|
|
20
20
|
type RuleOptions = [Options?];
|
|
21
|
-
export declare const requireBlobUrlRevocation: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
21
|
+
export declare const requireBlobUrlRevocation: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
22
24
|
export {};
|
|
@@ -17,5 +17,7 @@ export interface Options {
|
|
|
17
17
|
allowInTests?: boolean;
|
|
18
18
|
}
|
|
19
19
|
type RuleOptions = [Options?];
|
|
20
|
-
export declare const requireCookieSecureAttrs: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener
|
|
20
|
+
export declare const requireCookieSecureAttrs: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
|
|
21
|
+
name: string;
|
|
22
|
+
};
|
|
21
23
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
export interface Options {
|
|
7
|
+
}
|
|
8
|
+
type RuleOptions = [Options?];
|
|
9
|
+
export declare const requireCspHeaders: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireCspHeaders = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Require Content Security Policy
|
|
11
|
+
*/
|
|
12
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
13
|
+
exports.requireCspHeaders = (0, eslint_devkit_1.createRule)({
|
|
14
|
+
name: 'require-csp-headers',
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Require Content Security Policy headers',
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
22
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
23
|
+
issueName: 'Missing CSP',
|
|
24
|
+
cwe: 'CWE-1021',
|
|
25
|
+
description: 'HTML response without Content-Security-Policy header',
|
|
26
|
+
severity: 'MEDIUM',
|
|
27
|
+
fix: 'Use helmet.contentSecurityPolicy() or set CSP header manually',
|
|
28
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/1021.html',
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
function report(node) {
|
|
36
|
+
context.report({ node, messageId: 'violationDetected' });
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
// Detect res.send(html) with HTML content without CSP
|
|
41
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
42
|
+
node.callee.property.type === 'Identifier' &&
|
|
43
|
+
node.callee.property.name === 'send') {
|
|
44
|
+
const arg = node.arguments[0];
|
|
45
|
+
// Check if sending HTML string
|
|
46
|
+
if (arg && arg.type === 'TemplateLiteral') {
|
|
47
|
+
const quasi = arg.quasis[0]?.value?.raw || '';
|
|
48
|
+
if (quasi.includes('<html') || quasi.includes('<!DOCTYPE')) {
|
|
49
|
+
report(node);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (arg && arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
53
|
+
if (arg.value.includes('<html') || arg.value.includes('<!DOCTYPE')) {
|
|
54
|
+
report(node);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Detect res.render() without CSP middleware
|
|
59
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
60
|
+
node.callee.property.type === 'Identifier' &&
|
|
61
|
+
node.callee.property.name === 'render') {
|
|
62
|
+
// This is a heuristic - flag render calls as a reminder
|
|
63
|
+
// In real projects, you'd check for helmet middleware
|
|
64
|
+
report(node);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
export interface Options {
|
|
7
|
+
}
|
|
8
|
+
type RuleOptions = [Options?];
|
|
9
|
+
export declare const requireHttpsOnly: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireHttpsOnly = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview Enforce HTTPS for all external requests
|
|
11
|
+
* @see https://owasp.org/www-project-mobile-top-10/
|
|
12
|
+
* @see https://cwe.mitre.org/data/definitions/319.html
|
|
13
|
+
*/
|
|
14
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
15
|
+
/** HTTP methods supported by axios for request interception */
|
|
16
|
+
const AXIOS_HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
17
|
+
exports.requireHttpsOnly = (0, eslint_devkit_1.createRule)({
|
|
18
|
+
name: 'require-https-only',
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Enforce HTTPS for all external requests',
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
27
|
+
issueName: 'violation Detected',
|
|
28
|
+
cwe: 'CWE-319',
|
|
29
|
+
description: 'Enforce HTTPS for all external requests detected - this is a security risk',
|
|
30
|
+
severity: 'HIGH',
|
|
31
|
+
fix: 'Review and apply secure practices',
|
|
32
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
schema: [],
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
create(context) {
|
|
39
|
+
function report(node) {
|
|
40
|
+
context.report({
|
|
41
|
+
node,
|
|
42
|
+
messageId: 'violationDetected',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
CallExpression(node) {
|
|
47
|
+
const callee = node.callee;
|
|
48
|
+
// Check fetch() calls
|
|
49
|
+
const isFetch = callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && callee.name === 'fetch';
|
|
50
|
+
// Check axios.get/post/etc calls
|
|
51
|
+
const isAxios = callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
52
|
+
callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
53
|
+
callee.object.name === 'axios' &&
|
|
54
|
+
callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
55
|
+
AXIOS_HTTP_METHODS.includes(callee.property.name);
|
|
56
|
+
if ((isFetch || isAxios) && node.arguments[0]) {
|
|
57
|
+
const url = node.arguments[0];
|
|
58
|
+
if (url.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
59
|
+
typeof url.value === 'string' &&
|
|
60
|
+
url.value.startsWith('http://')) {
|
|
61
|
+
report(node);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|