eslint-plugin-browser-security 1.2.5 → 1.2.7
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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/rules/no-clickjacking/index.js +0 -8
- package/src/rules/no-cookie-auth-tokens/index.js +1 -1
- package/src/rules/no-filereader-innerhtml/index.js +0 -5
- package/src/rules/no-innerhtml/index.js +0 -1
- package/src/rules/no-insecure-redirects/index.js +0 -2
- package/src/rules/no-jwt-in-storage/index.js +0 -3
- package/src/rules/no-missing-cors-check/index.js +5 -3
- package/src/rules/no-missing-security-headers/index.js +3 -3
- package/src/rules/no-postmessage-innerhtml/index.js +0 -2
- package/src/rules/no-sensitive-cookie-js/index.js +0 -1
- package/src/rules/no-sensitive-localstorage/index.js +0 -2
- package/src/rules/no-sensitive-sessionstorage/index.js +0 -2
- package/src/rules/no-unencrypted-transmission/index.js +2 -6
- package/src/rules/no-websocket-eval/index.js +2 -9
- package/src/rules/no-worker-message-innerhtml/index.js +0 -1
- package/src/rules/require-blob-url-revocation/index.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
## [1.2.3] - 2026-02-08
|
|
2
2
|
|
|
3
|
+
## 1.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#252](https://github.com/ofri-peretz/eslint/pull/252) [`d67e395`](https://github.com/ofri-peretz/eslint/commit/d67e3953c2748ad36e6aebe0f24b1d04e518b4d0) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Fix Codecov badge showing "unknown" — switch from flag to component URL format
|
|
8
|
+
|
|
9
|
+
## 1.2.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
|
|
14
|
+
|
|
3
15
|
## 1.2.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<a href="https://www.npmjs.com/package/eslint-plugin-browser-security" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-browser-security.svg" alt="NPM Version" /></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/eslint-plugin-browser-security" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-browser-security.svg" alt="NPM Downloads" /></a>
|
|
12
12
|
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
13
|
-
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=browser-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=browser-security" alt="Codecov" /></a>
|
|
13
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint-plugin-browser-security" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?component=eslint-plugin-browser-security" alt="Codecov" /></a>
|
|
14
14
|
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-browser-security",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "Security-focused ESLint plugin for browser applications. Detects XSS vulnerabilities, postMessage abuse, localStorage/sessionStorage/IndexedDB token exposure, cookie security issues, WebSocket security, Blob URL leaks, Service Worker risks, and CSP misconfigurations.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -259,11 +259,9 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
if (hasSrc && srcValue && !isTrustedSource(srcValue)) {
|
|
262
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
263
262
|
if (safetyChecker.isSafe(node, context)) {
|
|
264
263
|
return;
|
|
265
264
|
}
|
|
266
|
-
/* c8 ignore stop */
|
|
267
265
|
context.report({
|
|
268
266
|
node: node.openingElement,
|
|
269
267
|
messageId: 'unsafeIframeUsage',
|
|
@@ -310,11 +308,9 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
310
308
|
current = current.parent;
|
|
311
309
|
}
|
|
312
310
|
if (isFrameManipulation) {
|
|
313
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
314
311
|
if (safetyChecker.isSafe(node, context)) {
|
|
315
312
|
return;
|
|
316
313
|
}
|
|
317
|
-
/* c8 ignore stop */
|
|
318
314
|
context.report({
|
|
319
315
|
node,
|
|
320
316
|
messageId: 'frameManipulation',
|
|
@@ -334,11 +330,9 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
334
330
|
const text = node.value.toLowerCase();
|
|
335
331
|
if ((text.includes('style=') || text.includes('css')) &&
|
|
336
332
|
hasTransparentStyles(text)) {
|
|
337
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
338
333
|
if (safetyChecker.isSafe(node, context)) {
|
|
339
334
|
return;
|
|
340
335
|
}
|
|
341
|
-
/* c8 ignore stop */
|
|
342
336
|
context.report({
|
|
343
337
|
node,
|
|
344
338
|
messageId: 'transparentFrameOverlay',
|
|
@@ -355,11 +349,9 @@ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
|
|
|
355
349
|
if (detectTransparentOverlays) {
|
|
356
350
|
const text = sourceCode.getText(node).toLowerCase();
|
|
357
351
|
if (text.includes('style') && hasTransparentStyles(text)) {
|
|
358
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
359
352
|
if (safetyChecker.isSafe(node, context)) {
|
|
360
353
|
return;
|
|
361
354
|
}
|
|
362
|
-
/* c8 ignore stop */
|
|
363
355
|
context.report({
|
|
364
356
|
node,
|
|
365
357
|
messageId: 'transparentFrameOverlay',
|
|
@@ -112,7 +112,7 @@ exports.noCookieAuthTokens = (0, eslint_devkit_1.createRule)({
|
|
|
112
112
|
context.report({
|
|
113
113
|
node,
|
|
114
114
|
messageId: 'authTokenInCookie',
|
|
115
|
-
suggest: [{ messageId: 'useHttpOnlyCookie', fix:
|
|
115
|
+
suggest: [{ messageId: 'useHttpOnlyCookie', fix: () => null }],
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -132,7 +132,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
132
132
|
return true;
|
|
133
133
|
}
|
|
134
134
|
// Check nested
|
|
135
|
-
/* c8 ignore next - Recursive call for deeply nested expressions */
|
|
136
135
|
return referencesFileReaderResult(node.object, eventName);
|
|
137
136
|
}
|
|
138
137
|
return false;
|
|
@@ -168,7 +167,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
},
|
|
171
|
-
/* c8 ignore start - Exit handler cleanup, not testable with RuleTester */
|
|
172
170
|
'AssignmentExpression:exit'(node) {
|
|
173
171
|
const { isHandler } = isFileReaderOnloadAssignment(node);
|
|
174
172
|
if (isHandler) {
|
|
@@ -176,7 +174,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
176
174
|
eventParamName = null;
|
|
177
175
|
}
|
|
178
176
|
},
|
|
179
|
-
/* c8 ignore stop */
|
|
180
177
|
CallExpression(node) {
|
|
181
178
|
// Check if entering addEventListener handler
|
|
182
179
|
const { isHandler, eventParam } = isFileReaderAddEventListener(node);
|
|
@@ -210,7 +207,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
210
207
|
}
|
|
211
208
|
}
|
|
212
209
|
},
|
|
213
|
-
/* c8 ignore start - Exit handler cleanup, not testable with RuleTester */
|
|
214
210
|
'CallExpression:exit'(node) {
|
|
215
211
|
const { isHandler } = isFileReaderAddEventListener(node);
|
|
216
212
|
if (isHandler) {
|
|
@@ -218,7 +214,6 @@ exports.noFilereaderInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
218
214
|
eventParamName = null;
|
|
219
215
|
}
|
|
220
216
|
},
|
|
221
|
-
/* c8 ignore stop */
|
|
222
217
|
};
|
|
223
218
|
},
|
|
224
219
|
});
|
|
@@ -68,11 +68,9 @@ function isRedirectValidated(node, sourceCode) {
|
|
|
68
68
|
const program = sourceCode.ast;
|
|
69
69
|
const nodeStart = node.loc?.start;
|
|
70
70
|
const nodeEnd = node.loc?.end;
|
|
71
|
-
/* c8 ignore start -- Guard clause: loc is always present in RuleTester */
|
|
72
71
|
if (!nodeStart || !nodeEnd || !program) {
|
|
73
72
|
return false;
|
|
74
73
|
}
|
|
75
|
-
/* c8 ignore stop */
|
|
76
74
|
// Check for validation function calls before this redirect
|
|
77
75
|
const validationPatterns = [
|
|
78
76
|
/\b(validateUrl|validateRedirect|isValidUrl|isSafeUrl)\s*\(/,
|
|
@@ -162,7 +162,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
|
|
|
162
162
|
const obj = node.left.object;
|
|
163
163
|
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
164
164
|
!storageObjects.has(obj.name)) {
|
|
165
|
-
/* c8 ignore next - Guard clause for non-storage objects */
|
|
166
165
|
return;
|
|
167
166
|
}
|
|
168
167
|
let keyValue = null;
|
|
@@ -176,12 +175,10 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
|
|
|
176
175
|
keyValue = node.left.property.name;
|
|
177
176
|
}
|
|
178
177
|
// Check value for JWT pattern
|
|
179
|
-
/* c8 ignore start - Value-based JWT detection for assignment expressions */
|
|
180
178
|
if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
|
|
181
179
|
typeof node.right.value === 'string') {
|
|
182
180
|
hasJwtValue = isJwtValue(node.right.value);
|
|
183
181
|
}
|
|
184
|
-
/* c8 ignore stop */
|
|
185
182
|
if ((keyValue && isJwtKey(keyValue)) || hasJwtValue) {
|
|
186
183
|
context.report({
|
|
187
184
|
node,
|
|
@@ -298,10 +298,12 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
|
|
|
298
298
|
let current = node;
|
|
299
299
|
while (current) {
|
|
300
300
|
if (current.type === 'Program' || current.type === 'FunctionDeclaration' || current.type === 'FunctionExpression' || current.type === 'ArrowFunctionExpression') {
|
|
301
|
-
// Search for variable declarations in this scope
|
|
301
|
+
// Search for variable declarations in this scope. The
|
|
302
|
+
// enclosing `if` already narrowed `current` to Program or
|
|
303
|
+
// one of the three function node types, so a non-Program
|
|
304
|
+
// node here is always a function.
|
|
302
305
|
const scopeBody = current.type === 'Program' ? current.body :
|
|
303
|
-
(current.
|
|
304
|
-
(current.body.type === 'BlockStatement' ? current.body.body : []) : [];
|
|
306
|
+
(current.body.type === 'BlockStatement' ? current.body.body : []);
|
|
305
307
|
for (const stmt of scopeBody) {
|
|
306
308
|
if (stmt.type === 'VariableDeclaration') {
|
|
307
309
|
for (const declarator of stmt.declarations) {
|
|
@@ -70,9 +70,9 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
|
|
|
70
70
|
collectHeaders(astNode.expression);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
// scopeNode is always set: either the enclosing function or (fallback
|
|
74
|
+
// above) the Program node itself.
|
|
75
|
+
collectHeaders(scopeNode);
|
|
76
76
|
// Return missing headers
|
|
77
77
|
return requiredHeaders.filter(header => !setHeaders.has(header));
|
|
78
78
|
}
|
|
@@ -100,10 +100,8 @@ exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
100
100
|
node.property.name === 'data') {
|
|
101
101
|
return true;
|
|
102
102
|
}
|
|
103
|
-
/* c8 ignore next - Recursive call for nested event.data.property */
|
|
104
103
|
return referencesEventData(node.object, eventName);
|
|
105
104
|
}
|
|
106
|
-
/* c8 ignore next 3 - Direct event identifier reference edge case */
|
|
107
105
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.name === eventName) {
|
|
108
106
|
return true;
|
|
109
107
|
}
|
|
@@ -121,7 +121,6 @@ exports.noSensitiveCookieJs = (0, eslint_devkit_1.createRule)({
|
|
|
121
121
|
obj.name !== 'document') {
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
|
-
/* c8 ignore next 3 - Guard for non-cookie property */
|
|
125
124
|
if (prop.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
126
125
|
prop.name !== 'cookie') {
|
|
127
126
|
return;
|
|
@@ -116,7 +116,6 @@ exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
|
|
|
116
116
|
callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
117
117
|
callee.property.name === 'setItem') {
|
|
118
118
|
const keyArg = node.arguments[0];
|
|
119
|
-
/* c8 ignore next 3 - Guard for missing key argument */
|
|
120
119
|
if (!keyArg) {
|
|
121
120
|
return;
|
|
122
121
|
}
|
|
@@ -152,7 +151,6 @@ exports.noSensitiveLocalstorage = (0, eslint_devkit_1.createRule)({
|
|
|
152
151
|
return;
|
|
153
152
|
}
|
|
154
153
|
const obj = node.left.object;
|
|
155
|
-
/* c8 ignore next 3 - Guard for non-storage objects */
|
|
156
154
|
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier || !storageObjects.includes(obj.name)) {
|
|
157
155
|
return;
|
|
158
156
|
}
|
|
@@ -35,7 +35,6 @@ const SENSITIVE_PATTERNS = [
|
|
|
35
35
|
function isSensitiveKey(key, additionalPatterns = []) {
|
|
36
36
|
const allPatterns = [
|
|
37
37
|
...SENSITIVE_PATTERNS,
|
|
38
|
-
/* c8 ignore next - Additional patterns are optional config */
|
|
39
38
|
...additionalPatterns.map((p) => new RegExp(p, 'i')),
|
|
40
39
|
];
|
|
41
40
|
return allPatterns.some((pattern) => pattern.test(key));
|
|
@@ -128,7 +127,6 @@ exports.noSensitiveSessionstorage = (0, eslint_devkit_1.createRule)({
|
|
|
128
127
|
const obj = node.left.object;
|
|
129
128
|
if (obj.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier ||
|
|
130
129
|
obj.name !== 'sessionStorage') {
|
|
131
|
-
/* c8 ignore next - Guard for non-sessionStorage objects */
|
|
132
130
|
return;
|
|
133
131
|
}
|
|
134
132
|
let keyValue = null;
|
|
@@ -60,7 +60,6 @@ function containsInsecureProtocol(value, insecureProtocols, secureAlternatives)
|
|
|
60
60
|
/**
|
|
61
61
|
* Check if a string matches any ignore pattern
|
|
62
62
|
*/
|
|
63
|
-
/* c8 ignore start -- ignore-pattern matching is defensive */
|
|
64
63
|
function matchesIgnorePattern(text, patterns) {
|
|
65
64
|
return patterns.some(pattern => {
|
|
66
65
|
try {
|
|
@@ -72,7 +71,6 @@ function matchesIgnorePattern(text, patterns) {
|
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
|
-
/* c8 ignore stop */
|
|
76
74
|
exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
77
75
|
name: 'no-unencrypted-transmission',
|
|
78
76
|
meta: {
|
|
@@ -175,10 +173,8 @@ exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
|
|
|
175
173
|
}
|
|
176
174
|
const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
|
|
177
175
|
if (isInsecure) {
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
176
|
+
// NOTE: localhost URLs in test files already returned above, so no
|
|
177
|
+
// second `isTestFile && localhost` check is needed here.
|
|
182
178
|
const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
|
|
183
179
|
const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
|
|
184
180
|
context.report({
|
|
@@ -117,10 +117,8 @@ exports.noWebsocketEval = (0, eslint_devkit_1.createRule)({
|
|
|
117
117
|
node.property.name === 'data') {
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
|
-
/* c8 ignore next - Recursive call for nested event.data.property */
|
|
121
120
|
return referencesEventData(node.object, eventName);
|
|
122
121
|
}
|
|
123
|
-
/* c8 ignore next 3 - Direct event identifier reference edge case */
|
|
124
122
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier && node.name === eventName) {
|
|
125
123
|
return true;
|
|
126
124
|
}
|
|
@@ -135,13 +133,8 @@ exports.noWebsocketEval = (0, eslint_devkit_1.createRule)({
|
|
|
135
133
|
EVAL_FUNCTIONS.has(node.callee.name)) {
|
|
136
134
|
return node.callee.name;
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
141
|
-
node.callee.name === 'Function') {
|
|
142
|
-
return 'Function';
|
|
143
|
-
}
|
|
144
|
-
/* c8 ignore stop */
|
|
136
|
+
// NOTE: no separate `Function` check is needed here — `Function` is a
|
|
137
|
+
// member of EVAL_FUNCTIONS, so the branch above already handles it.
|
|
145
138
|
return null;
|
|
146
139
|
}
|
|
147
140
|
return {
|
|
@@ -131,7 +131,6 @@ exports.noWorkerMessageInnerhtml = (0, eslint_devkit_1.createRule)({
|
|
|
131
131
|
node.property.name === 'data') {
|
|
132
132
|
return true;
|
|
133
133
|
}
|
|
134
|
-
/* c8 ignore next - Recursive call for deeply nested expressions */
|
|
135
134
|
return referencesEventData(node.object, eventName);
|
|
136
135
|
}
|
|
137
136
|
return false;
|
|
@@ -93,7 +93,7 @@ exports.requireBlobUrlRevocation = (0, eslint_devkit_1.createRule)({
|
|
|
93
93
|
context.report({
|
|
94
94
|
node: declaratorNode,
|
|
95
95
|
messageId: 'missingRevoke',
|
|
96
|
-
suggest: [{ messageId: 'addRevocation', fix:
|
|
96
|
+
suggest: [{ messageId: 'addRevocation', fix: () => null }],
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
}
|