eslint-plugin-browser-security 1.2.4 → 1.2.6

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 CHANGED
@@ -1,5 +1,34 @@
1
1
  ## [1.2.3] - 2026-02-08
2
2
 
3
+ ## 1.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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).
8
+
9
+ ## 1.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#213](https://github.com/ofri-peretz/eslint/pull/213) [`391dbe6`](https://github.com/ofri-peretz/eslint/commit/391dbe6b39f78d549379218567cb959649f8c614) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Align every security rule's `meta.docs.cvss` to the CVSS its finding actually
14
+ emits. The emitted machine-readable message sources its `CVSS:x` from
15
+ `CWE_MAPPING` via `formatLLMMessage` → `enrichFromCWE`, but the static
16
+ `meta.docs.cvss` documentation field had drifted on 45 rules across these 7
17
+ plugins — e.g. `no-hardcoded-credentials` documented `9.5` while emitting
18
+ `CVSS:9.8` (the value the published article and SARIF/LLM consumers already
19
+ read).
20
+
21
+ This corrects the **documentation metadata only** — no emitted finding changes.
22
+ Locked by `security-cvss-docs-consistency.lock.test.ts` (cross-plugin: every
23
+ security rule's `meta.docs.cvss` must equal the CVSS it emits), the
24
+ `no-hardcoded-credentials` rule lock (real ESLint `Linter` emission), and a
25
+ devkit `enrichFromCWE` contract test pinning `CWE-798 → 9.8`.
26
+
27
+ Follow-up (not in scope): 50 security rules document a CVSS that never appears
28
+ in any emitted message (their messages carry no CWE), and several rules emit the
29
+ generic CWE score where a rule-specific score may be warranted — both change
30
+ emitted output and are separate decisions.
31
+
3
32
  ## 1.2.4
4
33
 
5
34
  ### 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/tree/main" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?flag=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.4",
3
+ "version": "1.2.6",
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
@@ -127,7 +127,7 @@ exports.rules = {
127
127
  exports.plugin = {
128
128
  meta: {
129
129
  name: 'eslint-plugin-browser-security',
130
- version: '1.2.4',
130
+ version: '1.2.6',
131
131
  },
132
132
  rules: exports.rules,
133
133
  };
@@ -20,7 +20,7 @@ exports.detectMixedContent = (0, eslint_devkit_1.createRule)({
20
20
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/detect-mixed-content.md',
21
21
  description: 'Detect HTTP resources in HTTPS pages',
22
22
  cwe: 'CWE-311',
23
- cvss: 5,
23
+ cvss: 7.5,
24
24
  },
25
25
  messages: {
26
26
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -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',
@@ -18,7 +18,7 @@ exports.noClientSideAuthLogic = (0, eslint_devkit_1.createRule)({
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-client-side-auth-logic.md',
19
19
  description: 'Prevent authentication logic in client code',
20
20
  cwe: 'CWE-602',
21
- cvss: 9.5,
21
+ cvss: 6.5,
22
22
  },
23
23
  messages: {
24
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -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: /* c8 ignore next */ () => null }],
115
+ suggest: [{ messageId: 'useHttpOnlyCookie', fix: () => null }],
116
116
  });
117
117
  }
118
118
  }
@@ -20,7 +20,7 @@ exports.noCredentialsInQueryParams = (0, eslint_devkit_1.createRule)({
20
20
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-credentials-in-query-params.md',
21
21
  description: 'Disallow credentials in URL query parameters',
22
22
  cwe: 'CWE-798',
23
- cvss: 9.5,
23
+ cvss: 9.8,
24
24
  },
25
25
  messages: {
26
26
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -24,7 +24,7 @@ exports.noEval = (0, eslint_devkit_1.createRule)({
24
24
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-eval.md',
25
25
  description: 'Disallow eval(), Function(), and other code execution patterns',
26
26
  cwe: 'CWE-95',
27
- cvss: 9.5,
27
+ cvss: 9.8,
28
28
  },
29
29
  hasSuggestions: true,
30
30
  messages: {
@@ -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
  });
@@ -41,7 +41,7 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
41
41
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-innerhtml.md',
42
42
  description: 'Disallow dangerous innerHTML/outerHTML assignments that can lead to XSS',
43
43
  cwe: 'CWE-79',
44
- cvss: 9.5,
44
+ cvss: 6.1,
45
45
  confidence: 'medium',
46
46
  },
47
47
  hasSuggestions: true,
@@ -143,7 +143,6 @@ exports.noInnerhtml = (0, eslint_devkit_1.createRule)({
143
143
  return;
144
144
  }
145
145
  const property = node.left.property;
146
- /* c8 ignore next 3 - Guard for non-identifier property access */
147
146
  if (property.type !== 'Identifier') {
148
147
  return;
149
148
  }
@@ -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.type === 'FunctionDeclaration' || current.type === 'FunctionExpression' || current.type === 'ArrowFunctionExpression') ?
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) {
@@ -49,7 +49,7 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
49
49
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-missing-csrf-protection.md',
50
50
  description: 'Detects missing CSRF token validation in POST/PUT/DELETE requests',
51
51
  cwe: 'CWE-352',
52
- cvss: 7.5,
52
+ cvss: 8.8,
53
53
  },
54
54
  hasSuggestions: true,
55
55
  messages: {
@@ -70,9 +70,9 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
70
70
  collectHeaders(astNode.expression);
71
71
  }
72
72
  }
73
- if (scopeNode) {
74
- collectHeaders(scopeNode);
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
  }
@@ -20,7 +20,7 @@ exports.noPasswordInUrl = (0, eslint_devkit_1.createRule)({
20
20
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-password-in-url.md',
21
21
  description: 'Prevent passwords in URLs',
22
22
  cwe: 'CWE-521',
23
- cvss: 9.5,
23
+ cvss: 5.3,
24
24
  },
25
25
  messages: {
26
26
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -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
- // Allow localhost URLs in test files
179
- if (isTestFile && text.includes('localhost')) {
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({
@@ -88,7 +88,7 @@ exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
88
88
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-browser-security/docs/rules/no-unescaped-url-parameter.md',
89
89
  description: 'Detects unescaped URL parameters',
90
90
  cwe: 'CWE-79',
91
- cvss: 7.5,
91
+ cvss: 6.1,
92
92
  },
93
93
  hasSuggestions: true,
94
94
  messages: {
@@ -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
- /* c8 ignore start - Duplicate Function check for call expression pattern */
139
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
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: /* c8 ignore next */ () => null }],
96
+ suggest: [{ messageId: 'addRevocation', fix: () => null }],
97
97
  });
98
98
  }
99
99
  }