eslint-plugin-browser-security 1.2.9 → 1.2.10

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.
Files changed (97) hide show
  1. package/package.json +5 -22
  2. package/src/index.d.ts +17 -64
  3. package/src/index.js +1 -76
  4. package/src/oxlint.d.ts +17 -20
  5. package/src/oxlint.js +0 -18
  6. package/src/rules/detect-mixed-content/index.js +0 -10
  7. package/src/rules/no-allow-arbitrary-loads/index.js +0 -10
  8. package/src/rules/no-clickjacking/index.js +0 -37
  9. package/src/rules/no-client-side-auth-logic/index.js +0 -11
  10. package/src/rules/no-cookie-auth-tokens/index.js +0 -13
  11. package/src/rules/no-credentials-in-query-params/index.js +0 -10
  12. package/src/rules/no-disabled-certificate-validation/index.js +0 -10
  13. package/src/rules/no-dynamic-service-worker-url/index.js +0 -9
  14. package/src/rules/no-eval/index.js +1 -14
  15. package/src/rules/no-filereader-innerhtml/index.js +0 -23
  16. package/src/rules/no-http-urls/index.js +0 -13
  17. package/src/rules/no-innerhtml/index.js +0 -25
  18. package/src/rules/no-insecure-redirects/index.js +3 -39
  19. package/src/rules/no-insecure-websocket/index.js +0 -12
  20. package/src/rules/no-jwt-in-storage/index.js +19 -42
  21. package/src/rules/no-missing-cors-check/index.js +4 -57
  22. package/src/rules/no-missing-csrf-protection/index.js +0 -23
  23. package/src/rules/no-missing-security-headers/index.js +0 -29
  24. package/src/rules/no-password-in-url/index.js +0 -11
  25. package/src/rules/no-permissive-cors/index.js +0 -13
  26. package/src/rules/no-postmessage-innerhtml/index.js +0 -18
  27. package/src/rules/no-postmessage-wildcard-origin/index.js +0 -10
  28. package/src/rules/no-sensitive-cookie-js/index.js +0 -18
  29. package/src/rules/no-sensitive-data-in-analytics/index.js +0 -11
  30. package/src/rules/no-sensitive-data-in-cache/index.js +0 -10
  31. package/src/rules/no-sensitive-indexeddb/index.js +0 -8
  32. package/src/rules/no-sensitive-localstorage/index.js +0 -11
  33. package/src/rules/no-sensitive-sessionstorage/index.js +0 -9
  34. package/src/rules/no-tracking-without-consent/index.js +0 -10
  35. package/src/rules/no-unencrypted-transmission/index.js +0 -32
  36. package/src/rules/no-unescaped-url-parameter/index.js +5 -47
  37. package/src/rules/no-unsafe-eval-csp/index.js +0 -10
  38. package/src/rules/no-unsafe-inline-csp/index.js +0 -10
  39. package/src/rules/no-unvalidated-deeplinks/index.js +0 -11
  40. package/src/rules/no-websocket-eval/index.js +0 -26
  41. package/src/rules/no-websocket-innerhtml/index.js +0 -20
  42. package/src/rules/no-worker-message-innerhtml/index.js +0 -23
  43. package/src/rules/require-blob-url-revocation/index.js +0 -10
  44. package/src/rules/require-cookie-secure-attrs/index.js +0 -7
  45. package/src/rules/require-csp-headers/index.js +0 -13
  46. package/src/rules/require-https-only/index.js +0 -13
  47. package/src/rules/require-mime-type-validation/index.js +0 -13
  48. package/src/rules/require-postmessage-origin-check/index.js +0 -17
  49. package/src/rules/require-url-validation/index.js +0 -12
  50. package/src/rules/require-websocket-wss/index.js +0 -17
  51. package/AGENTS.md +0 -97
  52. package/CHANGELOG.md +0 -188
  53. package/src/rules/detect-mixed-content/index.d.ts +0 -12
  54. package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -12
  55. package/src/rules/no-clickjacking/index.d.ts +0 -36
  56. package/src/rules/no-client-side-auth-logic/index.d.ts +0 -12
  57. package/src/rules/no-cookie-auth-tokens/index.d.ts +0 -23
  58. package/src/rules/no-credentials-in-query-params/index.d.ts +0 -12
  59. package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -12
  60. package/src/rules/no-dynamic-service-worker-url/index.d.ts +0 -23
  61. package/src/rules/no-eval/index.d.ts +0 -26
  62. package/src/rules/no-filereader-innerhtml/index.d.ts +0 -24
  63. package/src/rules/no-http-urls/index.d.ts +0 -17
  64. package/src/rules/no-innerhtml/index.d.ts +0 -28
  65. package/src/rules/no-insecure-redirects/index.d.ts +0 -26
  66. package/src/rules/no-insecure-websocket/index.d.ts +0 -12
  67. package/src/rules/no-jwt-in-storage/index.d.ts +0 -24
  68. package/src/rules/no-missing-cors-check/index.d.ts +0 -28
  69. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -30
  70. package/src/rules/no-missing-security-headers/index.d.ts +0 -26
  71. package/src/rules/no-password-in-url/index.d.ts +0 -12
  72. package/src/rules/no-permissive-cors/index.d.ts +0 -12
  73. package/src/rules/no-postmessage-innerhtml/index.d.ts +0 -24
  74. package/src/rules/no-postmessage-wildcard-origin/index.d.ts +0 -24
  75. package/src/rules/no-sensitive-cookie-js/index.d.ts +0 -26
  76. package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -12
  77. package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -12
  78. package/src/rules/no-sensitive-indexeddb/index.d.ts +0 -23
  79. package/src/rules/no-sensitive-localstorage/index.d.ts +0 -28
  80. package/src/rules/no-sensitive-sessionstorage/index.d.ts +0 -25
  81. package/src/rules/no-tracking-without-consent/index.d.ts +0 -12
  82. package/src/rules/no-unencrypted-transmission/index.d.ts +0 -30
  83. package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -28
  84. package/src/rules/no-unsafe-eval-csp/index.d.ts +0 -24
  85. package/src/rules/no-unsafe-inline-csp/index.d.ts +0 -24
  86. package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -12
  87. package/src/rules/no-websocket-eval/index.d.ts +0 -24
  88. package/src/rules/no-websocket-innerhtml/index.d.ts +0 -24
  89. package/src/rules/no-worker-message-innerhtml/index.d.ts +0 -24
  90. package/src/rules/require-blob-url-revocation/index.d.ts +0 -24
  91. package/src/rules/require-cookie-secure-attrs/index.d.ts +0 -23
  92. package/src/rules/require-csp-headers/index.d.ts +0 -12
  93. package/src/rules/require-https-only/index.d.ts +0 -12
  94. package/src/rules/require-mime-type-validation/index.d.ts +0 -12
  95. package/src/rules/require-postmessage-origin-check/index.d.ts +0 -26
  96. package/src/rules/require-url-validation/index.d.ts +0 -12
  97. package/src/rules/require-websocket-wss/index.d.ts +0 -26
@@ -1,53 +1,37 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noJwtInStorage = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // JWT detection patterns (keys) - these are regex patterns with word boundary semantics
11
5
  const JWT_KEY_PATTERNS = [
12
- /^jwt$/i, // exact 'jwt'
13
- /^token$/i, // exact 'token'
14
- /^access[_-]?token$/i, // access_token, accessToken, access-token
15
- /^refresh[_-]?token$/i, // refresh_token, refreshToken
16
- /^id[_-]?token$/i, // id_token, idToken
17
- /^bearer$/i, // exact 'bearer'
18
- /^auth[_-]?token$/i, // auth_token, authToken
19
- /token$/i, // ends with 'token' (authToken, jwtToken, etc.)
20
- /^jwt[_-]?/i, // starts with 'jwt' (jwt_value, jwtData, etc.)
21
- /[_-]jwt$/i, // ends with '_jwt' or '-jwt'
6
+ /^jwt$/i,
7
+ /^token$/i,
8
+ /^access[_-]?token$/i,
9
+ /^refresh[_-]?token$/i,
10
+ /^id[_-]?token$/i,
11
+ /^bearer$/i,
12
+ /^auth[_-]?token$/i,
13
+ /token$/i,
14
+ /^jwt[_-]?/i,
15
+ /[_-]jwt$/i,
22
16
  ];
23
- // JWT structure regex: base64.base64.base64
24
17
  const JWT_VALUE_REGEX = /^eyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+$/;
25
- // Exclude patterns - known false positives
26
18
  const EXCLUDE_PATTERNS = [
27
- /count$/i, // tokenCount, refreshTokenCount
28
- /length$/i, // tokenLength
29
- /size$/i, // tokenSize
30
- /limit$/i, // tokenLimit
31
- /max$/i, // maxToken, tokenMax
32
- /min$/i, // minToken, tokenMin
33
- /num$/i, // tokenNum, numToken
34
- /index$/i, // tokenIndex
35
- /position$/i, // tokenPosition
19
+ /count$/i,
20
+ /length$/i,
21
+ /size$/i,
22
+ /limit$/i,
23
+ /max$/i,
24
+ /min$/i,
25
+ /num$/i,
26
+ /index$/i,
27
+ /position$/i,
36
28
  ];
37
- /**
38
- * Check if key suggests JWT storage (with false positive filtering)
39
- */
40
29
  function isJwtKey(key) {
41
- // First check exclusion patterns
42
30
  if (EXCLUDE_PATTERNS.some((pattern) => pattern.test(key))) {
43
31
  return false;
44
32
  }
45
- // Then check if it matches any JWT pattern
46
33
  return JWT_KEY_PATTERNS.some((pattern) => pattern.test(key));
47
34
  }
48
- /**
49
- * Check if value looks like a JWT
50
- */
51
35
  function isJwtValue(value) {
52
36
  return JWT_VALUE_REGEX.test(value);
53
37
  }
@@ -108,7 +92,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
108
92
  return {
109
93
  CallExpression(node) {
110
94
  const callee = node.callee;
111
- // Check for localStorage.setItem() or sessionStorage.setItem()
112
95
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
113
96
  callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
114
97
  storageObjects.has(callee.object.name) &&
@@ -120,7 +103,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
120
103
  return;
121
104
  let keyValue = null;
122
105
  let hasJwtValue = false;
123
- // Check key
124
106
  if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
125
107
  typeof keyArg.value === 'string') {
126
108
  keyValue = keyArg.value;
@@ -128,13 +110,11 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
128
110
  else if (keyArg.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
129
111
  keyValue = keyArg.name;
130
112
  }
131
- // Check value for JWT pattern
132
113
  if (valueArg &&
133
114
  valueArg.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
134
115
  typeof valueArg.value === 'string') {
135
116
  hasJwtValue = isJwtValue(valueArg.value);
136
117
  }
137
- // Flag if key suggests JWT or value looks like JWT
138
118
  if ((keyValue && isJwtKey(keyValue)) ||
139
119
  hasJwtValue) {
140
120
  context.report({
@@ -154,7 +134,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
154
134
  }
155
135
  }
156
136
  },
157
- // Also check direct assignment: localStorage['token'] = jwt
158
137
  AssignmentExpression(node) {
159
138
  if (node.left.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
160
139
  return;
@@ -166,7 +145,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
166
145
  }
167
146
  let keyValue = null;
168
147
  let hasJwtValue = false;
169
- // Check key
170
148
  if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
171
149
  typeof node.left.property.value === 'string') {
172
150
  keyValue = node.left.property.value;
@@ -174,7 +152,6 @@ exports.noJwtInStorage = (0, eslint_devkit_1.createRule)({
174
152
  else if (node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
175
153
  keyValue = node.left.property.name;
176
154
  }
177
- // Check value for JWT pattern
178
155
  if (node.right.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
179
156
  typeof node.right.value === 'string') {
180
157
  hasJwtValue = isJwtValue(node.right.value);
@@ -1,16 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noMissingCorsCheck = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Check if a string matches any ignore pattern
13
- */
14
6
  function matchesIgnorePattern(text, ignorePatterns) {
15
7
  return ignorePatterns.some(pattern => {
16
8
  try {
@@ -91,7 +83,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
91
83
  defaultOptions: [
92
84
  {
93
85
  allowInTests: false,
94
- trustedLibraries: [], // Empty by default - users can add custom CORS libraries they trust
86
+ trustedLibraries: [],
95
87
  ignorePatterns: [],
96
88
  },
97
89
  ],
@@ -105,31 +97,22 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
105
97
  if (isTestFile) {
106
98
  return;
107
99
  }
108
- // Check for wildcard CORS origin
109
100
  if (node.value === '*' && typeof node.value === 'string') {
110
101
  const text = sourceCode.getText(node);
111
- // Check if it matches any ignore pattern
112
102
  if (matchesIgnorePattern(text, ignorePatterns)) {
113
103
  return;
114
104
  }
115
- // Check if it's in contexts handled by other checkers
116
- // 1. setHeader/header calls - checkMemberExpression handles these
117
- // 2. app.use(cors({ origin: "*" })) - checkCallExpression handles these with suggestions
118
105
  let shouldSkip = false;
119
106
  let current = node;
120
107
  while (current && current.parent) {
121
108
  current = current.parent;
122
109
  if (current.type === 'CallExpression') {
123
110
  const callText = sourceCode.getText(current);
124
- // Check if it's a setHeader/header call with Access-Control-Allow-Origin
125
- // Skip these - checkMemberExpression handles them
126
111
  if (/\b(setHeader|header)\s*\(/i.test(callText) && /\bAccess-Control-Allow-Origin\b/i.test(callText)) {
127
112
  shouldSkip = true;
128
113
  break;
129
114
  }
130
- // Check if it's app.use(cors({ origin: "*" })) - checkCallExpression handles these with suggestions
131
115
  if (/\buse\s*\(/i.test(callText) && /\bcors\s*\(/i.test(callText)) {
132
- // Check if the literal is in an object property named "origin"
133
116
  if (node.parent && node.parent.type === 'Property') {
134
117
  const prop = node.parent;
135
118
  if (prop.key.type === 'Identifier' && prop.key.name === 'origin') {
@@ -140,35 +123,26 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
140
123
  }
141
124
  }
142
125
  }
143
- // Skip if it's in a context handled by another checker
144
126
  if (shouldSkip) {
145
127
  return;
146
128
  }
147
- // Check if it's in a CORS-related context
148
- // Only report if it's actually in a CORS configuration (app.use(cors(...)), etc.)
149
- // Not just any object with origin: "*"
150
129
  let isActualCorsContext = false;
151
- // Check if it's in app.use(cors(...)) or similar
152
130
  current = node;
153
131
  while (current && current.parent) {
154
132
  current = current.parent;
155
133
  if (current.type === 'CallExpression') {
156
134
  const callText = sourceCode.getText(current);
157
- // Check if it's a CORS middleware call
158
135
  if (/\b(use|cors)\s*\(/i.test(callText) && /\bcors\s*\(/i.test(callText)) {
159
136
  isActualCorsContext = true;
160
137
  break;
161
138
  }
162
139
  }
163
140
  }
164
- // Also check if it's in an object property with name "origin" or "allowedOrigins"
165
- // but only if it's in a CORS-related call expression
166
141
  if (node.parent && node.parent.type === 'Property') {
167
142
  const prop = node.parent;
168
143
  if (prop.key.type === 'Identifier') {
169
144
  const keyName = prop.key.name.toLowerCase();
170
145
  if (keyName === 'origin' || keyName === 'allowedorigins') {
171
- // Check if this property is in a CORS call context
172
146
  let inCorsCall = false;
173
147
  let checkNode = prop;
174
148
  while (checkNode && checkNode.parent) {
@@ -183,7 +157,6 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
183
157
  }
184
158
  }
185
159
  if (inCorsCall) {
186
- // Always report wildcard CORS origin - it's never safe
187
160
  context.report({
188
161
  node,
189
162
  messageId: 'missingCorsCheck',
@@ -203,9 +176,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
203
176
  }
204
177
  }
205
178
  }
206
- // Only report if it's in an actual CORS context
207
179
  if (isActualCorsContext) {
208
- // Always report wildcard CORS origin - it's never safe
209
180
  context.report({
210
181
  node,
211
182
  messageId: 'missingCorsCheck',
@@ -227,46 +198,35 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
227
198
  if (isTestFile) {
228
199
  return;
229
200
  }
230
- // Check for app.use(cors({ origin: "*" })) or similar
231
201
  if (node.callee.type === 'MemberExpression') {
232
202
  const property = node.callee.property;
233
203
  if (property.type === 'Identifier' && property.name === 'use') {
234
- // Check if CORS is being used
235
204
  const text = sourceCode.getText(node);
236
- // Check if it matches any ignore pattern
237
205
  if (matchesIgnorePattern(text, ignorePatterns)) {
238
206
  return;
239
207
  }
240
- // Check if it's a CORS middleware call
241
- // Check for cors() or trusted library calls
242
208
  const firstArg = node.arguments.length > 0 ? node.arguments[0] : null;
243
209
  let isCorsCall = /\bcors\s*\(/i.test(text);
244
210
  if (!isCorsCall && firstArg && firstArg.type === 'CallExpression' && firstArg.callee.type === 'Identifier') {
245
211
  const callee = firstArg.callee;
246
212
  const calleeName = callee.name.toLowerCase();
247
- // Check if it's the standard 'cors' library or a trusted library
248
213
  isCorsCall = calleeName === 'cors' || trustedLibraries.some(lib => {
249
214
  return calleeName.includes(lib.toLowerCase());
250
215
  });
251
216
  }
252
- // Check if it's a trusted library - skip if explicitly trusted
253
217
  let isTrustedLibrary = false;
254
218
  if (firstArg && firstArg.type === 'CallExpression' && firstArg.callee.type === 'Identifier') {
255
219
  const calleeName = firstArg.callee.name.toLowerCase();
256
220
  isTrustedLibrary = trustedLibraries.some(lib => calleeName.includes(lib.toLowerCase()));
257
221
  }
258
222
  if (isTrustedLibrary) {
259
- return; // Trusted library, skip
223
+ return;
260
224
  }
261
- // Check if it's a CORS call
262
225
  if (/\bcors\s*\(/i.test(text) || isCorsCall) {
263
- // Check arguments for wildcard origin
264
- // For app.use(cors({ origin: "*" })), we need to check the arguments to cors(), not app.use()
265
226
  const corsCallArg = firstArg && firstArg.type === 'CallExpression' ? firstArg : null;
266
227
  const argsToCheck = corsCallArg ? corsCallArg.arguments : node.arguments;
267
228
  for (const arg of argsToCheck) {
268
229
  if (arg.type === 'ObjectExpression') {
269
- // Check for origin property with wildcard value
270
230
  for (const prop of arg.properties) {
271
231
  if (prop.type === 'Property' &&
272
232
  prop.key.type === 'Identifier' &&
@@ -291,24 +251,16 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
291
251
  }
292
252
  }
293
253
  else if (arg.type === 'Identifier') {
294
- // Check if this identifier was assigned an object literal with origin: "*"
295
- // For cases like: const config = { origin: "*" }; app.use(cors(config));
296
254
  const varName = arg.name;
297
- // Traverse the AST to find the variable declaration
298
255
  let current = node;
299
256
  while (current) {
300
257
  if (current.type === 'Program' || current.type === 'FunctionDeclaration' || current.type === 'FunctionExpression' || current.type === 'ArrowFunctionExpression') {
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.
305
258
  const scopeBody = current.type === 'Program' ? current.body :
306
259
  (current.body.type === 'BlockStatement' ? current.body.body : []);
307
260
  for (const stmt of scopeBody) {
308
261
  if (stmt.type === 'VariableDeclaration') {
309
262
  for (const declarator of stmt.declarations) {
310
263
  if (declarator.id.type === 'Identifier' && declarator.id.name === varName && declarator.init) {
311
- // Check if init is an object literal with origin: "*"
312
264
  if (declarator.init.type === 'ObjectExpression') {
313
265
  for (const prop of declarator.init.properties) {
314
266
  if (prop.type === 'Property' &&
@@ -330,7 +282,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
330
282
  },
331
283
  ],
332
284
  });
333
- return; // Found and reported, exit
285
+ return;
334
286
  }
335
287
  }
336
288
  }
@@ -338,7 +290,7 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
338
290
  }
339
291
  }
340
292
  }
341
- break; // Only check the immediate scope
293
+ break;
342
294
  }
343
295
  if (current.parent) {
344
296
  current = current.parent;
@@ -357,22 +309,17 @@ exports.noMissingCorsCheck = (0, eslint_devkit_2.createRule)({
357
309
  if (isTestFile) {
358
310
  return;
359
311
  }
360
- // Check for Access-Control-Allow-Origin header without validation
361
312
  if (node.property.type === 'Identifier') {
362
313
  const propertyName = node.property.name;
363
314
  if (propertyName === 'setHeader' || propertyName === 'header') {
364
- // Check if it matches any ignore pattern
365
315
  const text = sourceCode.getText(node);
366
316
  if (matchesIgnorePattern(text, ignorePatterns)) {
367
317
  return;
368
318
  }
369
- // Check if it's setting CORS headers
370
- // Need to check the full call expression, not just the member expression
371
319
  const parent = node.parent;
372
320
  if (parent && parent.type === 'CallExpression') {
373
321
  const callText = sourceCode.getText(parent);
374
322
  if (/\bAccess-Control-Allow-Origin\b/i.test(callText)) {
375
- // Check if the value is a wildcard
376
323
  const args = parent.arguments;
377
324
  if (args.length >= 2 && args[1].type === 'Literal' && args[1].value === '*') {
378
325
  context.report({
@@ -1,16 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noMissingCsrfProtection = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Default CSRF middleware patterns
13
- */
14
6
  const DEFAULT_CSRF_MIDDLEWARE_PATTERNS = [
15
7
  'csrf',
16
8
  'csurf',
@@ -21,13 +13,7 @@ const DEFAULT_CSRF_MIDDLEWARE_PATTERNS = [
21
13
  'checkCsrf',
22
14
  'csrfMiddleware',
23
15
  ];
24
- /**
25
- * Default HTTP methods that require CSRF protection
26
- */
27
16
  const DEFAULT_PROTECTED_METHODS = ['post', 'put', 'delete', 'patch'];
28
- /**
29
- * Check if a string matches any ignore pattern
30
- */
31
17
  function matchesIgnorePattern(text, patterns) {
32
18
  return patterns.some(pattern => {
33
19
  try {
@@ -119,7 +105,6 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
119
105
  const protectedMethods = customProtectedMethods && customProtectedMethods.length > 0
120
106
  ? customProtectedMethods
121
107
  : DEFAULT_PROTECTED_METHODS;
122
- // Pre-compute Set for O(1) lookups (performance optimization)
123
108
  const protectedMethodsSet = new Set(protectedMethods.map(m => m.toLowerCase()));
124
109
  const filename = context.filename;
125
110
  const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
@@ -130,23 +115,16 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
130
115
  }
131
116
  const callee = node.callee;
132
117
  const callText = sourceCode.getText(node);
133
- // Check if it matches any ignore pattern
134
118
  if (matchesIgnorePattern(callText, ignorePatterns)) {
135
119
  return;
136
120
  }
137
- // Check for route handler methods (app.post, router.put, etc.)
138
121
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
139
122
  const methodName = callee.property.name;
140
- // Only check if it's a route handler that requires CSRF (O(1) Set lookup)
141
123
  if (protectedMethodsSet.has(methodName.toLowerCase())) {
142
- // Must have at least 2 arguments (path and handler)
143
124
  if (node.arguments.length < 2) {
144
125
  return;
145
126
  }
146
- // Check if CSRF middleware is in the route chain arguments
147
127
  let hasCsrfInChain = false;
148
- // Check if any argument (after the first path argument) is a CSRF middleware
149
- // Skip the first argument (path) and check the rest
150
128
  for (let i = 1; i < node.arguments.length; i++) {
151
129
  const arg = node.arguments[i];
152
130
  const argText = sourceCode.getText(arg);
@@ -167,7 +145,6 @@ exports.noMissingCsrfProtection = (0, eslint_devkit_2.createRule)({
167
145
  {
168
146
  messageId: 'addCsrfValidation',
169
147
  fix(fixer) {
170
- // Add CSRF middleware after the first argument (path)
171
148
  const firstArg = node.arguments[0];
172
149
  if (firstArg) {
173
150
  return fixer.insertTextAfter(firstArg, ', csrf()');
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noMissingSecurityHeaders = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -13,21 +8,14 @@ const DEFAULT_REQUIRED_HEADERS = [
13
8
  'X-Frame-Options',
14
9
  'X-Content-Type-Options',
15
10
  ];
16
- /**
17
- * Extract header name from setHeader call
18
- */
19
11
  function extractHeaderName(node) {
20
12
  if (node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
21
13
  return String(node.arguments[0].value);
22
14
  }
23
15
  return null;
24
16
  }
25
- /**
26
- * Check if all security headers are set in the current scope
27
- */
28
17
  function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
29
18
  const setHeaders = new Set();
30
- // Find the function that contains this setHeader call
31
19
  let current = node;
32
20
  let scopeNode = null;
33
21
  while (current) {
@@ -39,11 +27,9 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
39
27
  }
40
28
  current = current.parent ?? null;
41
29
  }
42
- // If no function found, use the program scope (for test cases)
43
30
  if (!scopeNode) {
44
31
  scopeNode = context.sourceCode.ast;
45
32
  }
46
- // Collect all setHeader calls in this scope
47
33
  function collectHeaders(astNode) {
48
34
  if (astNode.type === 'CallExpression' &&
49
35
  astNode.callee.type === 'MemberExpression' &&
@@ -54,7 +40,6 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
54
40
  setHeaders.add(headerName);
55
41
  }
56
42
  }
57
- // Recursively check children - only traverse standard AST properties
58
43
  if (astNode.type === 'Program' && astNode.body) {
59
44
  astNode.body.forEach(collectHeaders);
60
45
  }
@@ -70,10 +55,7 @@ function checkFunctionForSecurityHeaders(node, requiredHeaders, context) {
70
55
  collectHeaders(astNode.expression);
71
56
  }
72
57
  }
73
- // scopeNode is always set: either the enclosing function or (fallback
74
- // above) the Program node itself.
75
58
  collectHeaders(scopeNode);
76
- // Return missing headers
77
59
  return requiredHeaders.filter(header => !setHeaders.has(header));
78
60
  }
79
61
  exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
@@ -156,11 +138,7 @@ exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
156
138
  return {};
157
139
  }
158
140
  const reportedScopes = new Set();
159
- /**
160
- * Get a unique key for the current scope
161
- */
162
141
  function getScopeKey(node) {
163
- // Find the function that contains this call
164
142
  let current = node;
165
143
  while (current) {
166
144
  if (current.type === 'FunctionDeclaration' ||
@@ -170,20 +148,14 @@ exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
170
148
  }
171
149
  current = current.parent ?? null;
172
150
  }
173
- // If no function found, use program scope
174
151
  return 'program';
175
152
  }
176
- /**
177
- * Check for response header setting
178
- */
179
153
  function checkCallExpression(node) {
180
- // Check for res.setHeader, res.header, res.set
181
154
  if (node.callee.type === 'MemberExpression' &&
182
155
  node.callee.property.type === 'Identifier') {
183
156
  const methodName = node.callee.property.name;
184
157
  if (['setHeader', 'header', 'set'].includes(methodName)) {
185
158
  const scopeKey = getScopeKey(node);
186
- // Only check once per scope
187
159
  if (reportedScopes.has(scopeKey)) {
188
160
  return;
189
161
  }
@@ -213,7 +185,6 @@ exports.noMissingSecurityHeaders = (0, eslint_devkit_2.createRule)({
213
185
  });
214
186
  }
215
187
  else {
216
- // Mark as checked even if no error
217
188
  reportedScopes.add(scopeKey);
218
189
  }
219
190
  }
@@ -1,16 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noPasswordInUrl = void 0;
9
- /**
10
- * @fileoverview Prevent passwords in URLs
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/598.html
13
- */
14
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
5
  exports.noPasswordInUrl = (0, eslint_devkit_1.createRule)({
16
6
  name: 'no-password-in-url',
@@ -45,7 +35,6 @@ exports.noPasswordInUrl = (0, eslint_devkit_1.createRule)({
45
35
  }
46
36
  return {
47
37
  Literal(node) {
48
- // Check for http://user:password@host patterns
49
38
  if (node.type === 'Literal' && typeof node.value === 'string') {
50
39
  const urlPattern = /https?:\/\/[^:]+:[^@]+@/;
51
40
  if (urlPattern.test(node.value)) {
@@ -1,16 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noPermissiveCors = void 0;
9
- /**
10
- * @fileoverview Prevent overly permissive CORS configuration
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/942.html
13
- */
14
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
5
  exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
16
6
  name: 'no-permissive-cors',
@@ -48,8 +38,6 @@ exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
48
38
  }
49
39
  return {
50
40
  CallExpression(node) {
51
- // Check for Access-Control-Allow-Origin: *
52
- // res.setHeader('Access-Control-Allow-Origin', '*')
53
41
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
54
42
  node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
55
43
  node.callee.property.name === 'setHeader' &&
@@ -59,7 +47,6 @@ exports.noPermissiveCors = (0, eslint_devkit_1.createRule)({
59
47
  node.arguments[1].value === '*') {
60
48
  report(node);
61
49
  }
62
- // Check cors({ origin: '*' })
63
50
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
64
51
  node.callee.name === 'cors' &&
65
52
  node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression) {
@@ -1,13 +1,7 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.noPostmessageInnerhtml = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- // Dangerous DOM properties
11
5
  const DANGEROUS_PROPERTIES = new Set(['innerHTML', 'outerHTML']);
12
6
  const DANGEROUS_METHODS = new Set(['insertAdjacentHTML', 'write', 'writeln']);
13
7
  exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
@@ -63,12 +57,8 @@ exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
63
57
  if (allowInTests && isTestFile) {
64
58
  return {};
65
59
  }
66
- // Track message event handlers
67
60
  let inMessageHandler = false;
68
61
  let eventParamName = null;
69
- /**
70
- * Check if we're entering a message event handler
71
- */
72
62
  function checkMessageHandler(node) {
73
63
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
74
64
  node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -89,9 +79,6 @@ exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
89
79
  }
90
80
  return { isMessageHandler: false, eventParam: null };
91
81
  }
92
- /**
93
- * Check if expression references event.data
94
- */
95
82
  function referencesEventData(node, eventName) {
96
83
  if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
97
84
  if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -109,19 +96,16 @@ exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
109
96
  }
110
97
  return {
111
98
  CallExpression(node) {
112
- // Check if entering message handler
113
99
  const { isMessageHandler, eventParam } = checkMessageHandler(node);
114
100
  if (isMessageHandler) {
115
101
  inMessageHandler = true;
116
102
  eventParamName = eventParam;
117
103
  }
118
- // Check for dangerous methods: insertAdjacentHTML, document.write
119
104
  if (!inMessageHandler || !eventParamName)
120
105
  return;
121
106
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
122
107
  node.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
123
108
  DANGEROUS_METHODS.has(node.callee.property.name)) {
124
- // Check if any argument references event.data
125
109
  for (const arg of node.arguments) {
126
110
  if (referencesEventData(arg, eventParamName)) {
127
111
  context.report({
@@ -152,11 +136,9 @@ exports.noPostmessageInnerhtml = (0, eslint_devkit_1.createRule)({
152
136
  AssignmentExpression(node) {
153
137
  if (!inMessageHandler || !eventParamName)
154
138
  return;
155
- // Check for innerHTML/outerHTML assignment
156
139
  if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
157
140
  node.left.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
158
141
  DANGEROUS_PROPERTIES.has(node.left.property.name)) {
159
- // Check if right side references event.data
160
142
  if (referencesEventData(node.right, eventParamName)) {
161
143
  context.report({
162
144
  node,