eslint-plugin-browser-security 1.1.1 → 1.2.0

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 (73) hide show
  1. package/README.md +13 -11
  2. package/package.json +4 -3
  3. package/src/index.js +62 -0
  4. package/src/rules/detect-mixed-content/index.d.ts +12 -0
  5. package/src/rules/detect-mixed-content/index.js +45 -0
  6. package/src/rules/no-allow-arbitrary-loads/index.d.ts +12 -0
  7. package/src/rules/no-allow-arbitrary-loads/index.js +48 -0
  8. package/src/rules/no-clickjacking/index.d.ts +36 -0
  9. package/src/rules/no-clickjacking/index.js +401 -0
  10. package/src/rules/no-client-side-auth-logic/index.d.ts +12 -0
  11. package/src/rules/no-client-side-auth-logic/index.js +74 -0
  12. package/src/rules/no-cookie-auth-tokens/index.d.ts +3 -1
  13. package/src/rules/no-credentials-in-query-params/index.d.ts +12 -0
  14. package/src/rules/no-credentials-in-query-params/index.js +62 -0
  15. package/src/rules/no-disabled-certificate-validation/index.d.ts +12 -0
  16. package/src/rules/no-disabled-certificate-validation/index.js +66 -0
  17. package/src/rules/no-dynamic-service-worker-url/index.d.ts +3 -1
  18. package/src/rules/no-eval/index.d.ts +3 -1
  19. package/src/rules/no-filereader-innerhtml/index.d.ts +3 -1
  20. package/src/rules/no-http-urls/index.d.ts +17 -0
  21. package/src/rules/no-http-urls/index.js +119 -0
  22. package/src/rules/no-innerhtml/index.d.ts +3 -1
  23. package/src/rules/no-insecure-redirects/index.d.ts +26 -0
  24. package/src/rules/no-insecure-redirects/index.js +221 -0
  25. package/src/rules/no-insecure-websocket/index.d.ts +12 -0
  26. package/src/rules/no-insecure-websocket/index.js +66 -0
  27. package/src/rules/no-jwt-in-storage/index.d.ts +3 -1
  28. package/src/rules/no-missing-cors-check/index.d.ts +28 -0
  29. package/src/rules/no-missing-cors-check/index.js +404 -0
  30. package/src/rules/no-missing-csrf-protection/index.d.ts +30 -0
  31. package/src/rules/no-missing-csrf-protection/index.js +185 -0
  32. package/src/rules/no-missing-security-headers/index.d.ts +26 -0
  33. package/src/rules/no-missing-security-headers/index.js +223 -0
  34. package/src/rules/no-password-in-url/index.d.ts +12 -0
  35. package/src/rules/no-password-in-url/index.js +55 -0
  36. package/src/rules/no-permissive-cors/index.d.ts +12 -0
  37. package/src/rules/no-permissive-cors/index.js +74 -0
  38. package/src/rules/no-postmessage-innerhtml/index.d.ts +3 -1
  39. package/src/rules/no-postmessage-wildcard-origin/index.d.ts +3 -1
  40. package/src/rules/no-sensitive-cookie-js/index.d.ts +3 -1
  41. package/src/rules/no-sensitive-data-in-analytics/index.d.ts +12 -0
  42. package/src/rules/no-sensitive-data-in-analytics/index.js +66 -0
  43. package/src/rules/no-sensitive-data-in-cache/index.d.ts +12 -0
  44. package/src/rules/no-sensitive-data-in-cache/index.js +53 -0
  45. package/src/rules/no-sensitive-indexeddb/index.d.ts +3 -1
  46. package/src/rules/no-sensitive-localstorage/index.d.ts +3 -1
  47. package/src/rules/no-sensitive-sessionstorage/index.d.ts +3 -1
  48. package/src/rules/no-tracking-without-consent/index.d.ts +12 -0
  49. package/src/rules/no-tracking-without-consent/index.js +72 -0
  50. package/src/rules/no-unencrypted-transmission/index.d.ts +30 -0
  51. package/src/rules/no-unencrypted-transmission/index.js +241 -0
  52. package/src/rules/no-unescaped-url-parameter/index.d.ts +28 -0
  53. package/src/rules/no-unescaped-url-parameter/index.js +360 -0
  54. package/src/rules/no-unsafe-eval-csp/index.d.ts +3 -1
  55. package/src/rules/no-unsafe-inline-csp/index.d.ts +3 -1
  56. package/src/rules/no-unvalidated-deeplinks/index.d.ts +12 -0
  57. package/src/rules/no-unvalidated-deeplinks/index.js +67 -0
  58. package/src/rules/no-websocket-eval/index.d.ts +3 -1
  59. package/src/rules/no-websocket-innerhtml/index.d.ts +3 -1
  60. package/src/rules/no-worker-message-innerhtml/index.d.ts +3 -1
  61. package/src/rules/require-blob-url-revocation/index.d.ts +3 -1
  62. package/src/rules/require-cookie-secure-attrs/index.d.ts +3 -1
  63. package/src/rules/require-csp-headers/index.d.ts +12 -0
  64. package/src/rules/require-csp-headers/index.js +69 -0
  65. package/src/rules/require-https-only/index.d.ts +12 -0
  66. package/src/rules/require-https-only/index.js +67 -0
  67. package/src/rules/require-mime-type-validation/index.d.ts +12 -0
  68. package/src/rules/require-mime-type-validation/index.js +71 -0
  69. package/src/rules/require-postmessage-origin-check/index.d.ts +3 -1
  70. package/src/rules/require-url-validation/index.d.ts +12 -0
  71. package/src/rules/require-url-validation/index.js +77 -0
  72. package/src/rules/require-websocket-wss/index.d.ts +3 -1
  73. package/LICENSE +0 -21
@@ -0,0 +1,401 @@
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.noClickjacking = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ const eslint_devkit_3 = require("@interlace/eslint-devkit");
12
+ exports.noClickjacking = (0, eslint_devkit_1.createRule)({
13
+ name: 'no-clickjacking',
14
+ meta: {
15
+ type: 'problem',
16
+ deprecated: true,
17
+ replacedBy: ['@see eslint-plugin-express-security/require-helmet'],
18
+ docs: {
19
+ description: 'Detects clickjacking vulnerabilities and missing frame protections',
20
+ },
21
+ fixable: 'code',
22
+ hasSuggestions: true,
23
+ messages: {
24
+ clickjackingVulnerability: (0, eslint_devkit_2.formatLLMMessage)({
25
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
26
+ issueName: 'Clickjacking Vulnerability',
27
+ cwe: 'CWE-1021',
28
+ description: 'Clickjacking protection missing',
29
+ severity: '{{severity}}',
30
+ fix: '{{safeAlternative}}',
31
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
32
+ }),
33
+ missingFrameBusting: (0, eslint_devkit_2.formatLLMMessage)({
34
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
35
+ issueName: 'Missing Frame Busting',
36
+ cwe: 'CWE-1021',
37
+ description: 'No frame-busting code to prevent clickjacking',
38
+ severity: 'HIGH',
39
+ fix: 'Add frame-busting JavaScript to prevent framing',
40
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
41
+ }),
42
+ unsafeIframeUsage: (0, eslint_devkit_2.formatLLMMessage)({
43
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
44
+ issueName: 'Unsafe iframe Usage',
45
+ cwe: 'CWE-1021',
46
+ description: 'iframe may enable clickjacking attacks',
47
+ severity: 'MEDIUM',
48
+ fix: 'Add X-Frame-Options or CSP frame-ancestors protection',
49
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
50
+ }),
51
+ missingXFrameOptions: (0, eslint_devkit_2.formatLLMMessage)({
52
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
53
+ issueName: 'Missing X-Frame-Options',
54
+ cwe: 'CWE-1021',
55
+ description: 'X-Frame-Options header not set',
56
+ severity: 'HIGH',
57
+ fix: 'Set X-Frame-Options: DENY or SAMEORIGIN',
58
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options',
59
+ }),
60
+ missingCspFrameAncestors: (0, eslint_devkit_2.formatLLMMessage)({
61
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
62
+ issueName: 'Missing CSP frame-ancestors',
63
+ cwe: 'CWE-1021',
64
+ description: 'CSP frame-ancestors directive not configured',
65
+ severity: 'HIGH',
66
+ fix: 'Add frame-ancestors to Content-Security-Policy',
67
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors',
68
+ }),
69
+ transparentFrameOverlay: (0, eslint_devkit_2.formatLLMMessage)({
70
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
71
+ issueName: 'Transparent Frame Overlay',
72
+ cwe: 'CWE-1021',
73
+ description: 'Transparent elements may hide clickjacking attacks',
74
+ severity: 'MEDIUM',
75
+ fix: 'Use frame-busting or CSP protections',
76
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
77
+ }),
78
+ frameManipulation: (0, eslint_devkit_2.formatLLMMessage)({
79
+ icon: eslint_devkit_2.MessageIcons.SECURITY,
80
+ issueName: 'Frame Manipulation',
81
+ cwe: 'CWE-1021',
82
+ description: 'Code attempts to manipulate parent frames',
83
+ severity: 'LOW',
84
+ fix: 'Implement proper frame communication or prevent framing',
85
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
86
+ }),
87
+ implementFrameBusting: (0, eslint_devkit_2.formatLLMMessage)({
88
+ icon: eslint_devkit_2.MessageIcons.INFO,
89
+ issueName: 'Implement Frame Busting',
90
+ description: 'Add JavaScript to prevent framing',
91
+ severity: 'LOW',
92
+ fix: 'if (top != self) top.location = location;',
93
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
94
+ }),
95
+ useXFrameOptions: (0, eslint_devkit_2.formatLLMMessage)({
96
+ icon: eslint_devkit_2.MessageIcons.INFO,
97
+ issueName: 'Use X-Frame-Options',
98
+ description: 'Set X-Frame-Options HTTP header',
99
+ severity: 'LOW',
100
+ fix: 'X-Frame-Options: DENY',
101
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options',
102
+ }),
103
+ setCspFrameAncestors: (0, eslint_devkit_2.formatLLMMessage)({
104
+ icon: eslint_devkit_2.MessageIcons.INFO,
105
+ issueName: 'Set CSP frame-ancestors',
106
+ description: 'Configure CSP frame-ancestors directive',
107
+ severity: 'LOW',
108
+ fix: 'frame-ancestors \'self\' https://trusted.com',
109
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors',
110
+ }),
111
+ strategyFrameProtection: (0, eslint_devkit_2.formatLLMMessage)({
112
+ icon: eslint_devkit_2.MessageIcons.STRATEGY,
113
+ issueName: 'Frame Protection Strategy',
114
+ description: 'Implement multiple layers of frame protection',
115
+ severity: 'LOW',
116
+ fix: 'Use X-Frame-Options, CSP, and frame-busting together',
117
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
118
+ }),
119
+ strategyContentSecurity: (0, eslint_devkit_2.formatLLMMessage)({
120
+ icon: eslint_devkit_2.MessageIcons.STRATEGY,
121
+ issueName: 'Content Security Strategy',
122
+ description: 'Use CSP for comprehensive frame control',
123
+ severity: 'LOW',
124
+ fix: 'Implement strict CSP with frame-ancestors',
125
+ documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP',
126
+ }),
127
+ strategyUserInteraction: (0, eslint_devkit_2.formatLLMMessage)({
128
+ icon: eslint_devkit_2.MessageIcons.STRATEGY,
129
+ issueName: 'User Interaction Strategy',
130
+ description: 'Protect user interactions from framing attacks',
131
+ severity: 'LOW',
132
+ fix: 'Validate user intent for sensitive actions',
133
+ documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html',
134
+ })
135
+ },
136
+ schema: [
137
+ {
138
+ type: 'object',
139
+ properties: {
140
+ trustedSources: {
141
+ type: 'array',
142
+ items: { type: 'string' },
143
+ default: ['self', 'same-origin'],
144
+ },
145
+ requireFrameBusting: {
146
+ type: 'boolean',
147
+ default: true,
148
+ },
149
+ detectTransparentOverlays: {
150
+ type: 'boolean',
151
+ default: true,
152
+ },
153
+ trustedSanitizers: {
154
+ type: 'array',
155
+ items: { type: 'string' },
156
+ default: [],
157
+ description: 'Additional function names to consider as frame protectors',
158
+ },
159
+ trustedAnnotations: {
160
+ type: 'array',
161
+ items: { type: 'string' },
162
+ default: [],
163
+ description: 'Additional JSDoc annotations to consider as safe markers',
164
+ },
165
+ strictMode: {
166
+ type: 'boolean',
167
+ default: false,
168
+ description: 'Disable all false positive detection (strict mode)',
169
+ },
170
+ },
171
+ additionalProperties: false,
172
+ },
173
+ ],
174
+ },
175
+ defaultOptions: [
176
+ {
177
+ trustedSources: ['self', 'same-origin'],
178
+ requireFrameBusting: true,
179
+ detectTransparentOverlays: true,
180
+ trustedSanitizers: [],
181
+ trustedAnnotations: [],
182
+ strictMode: false,
183
+ },
184
+ ],
185
+ create(context) {
186
+ const options = context.options[0] || {};
187
+ const { trustedSources = ['self', 'same-origin'], requireFrameBusting = true, detectTransparentOverlays = true, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
188
+ const sourceCode = context.sourceCode || context.sourceCode;
189
+ const filename = context.filename || context.getFilename();
190
+ // Create safety checker for false positive detection
191
+ const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
192
+ trustedSanitizers,
193
+ trustedAnnotations,
194
+ trustedOrmPatterns: [],
195
+ strictMode,
196
+ });
197
+ // Track if frame-busting code is present
198
+ let hasFrameBusting = false;
199
+ /**
200
+ * Check if source is trusted
201
+ */
202
+ const isTrustedSource = (source) => {
203
+ return trustedSources.some(trusted => source.includes(trusted) ||
204
+ (trusted === 'self' && (source === 'self' || source.startsWith('/'))) ||
205
+ (trusted === 'same-origin' && source === 'same-origin'));
206
+ };
207
+ /**
208
+ * Check if this is frame-busting code
209
+ */
210
+ const isFrameBustingCode = (node) => {
211
+ const test = node.test;
212
+ const testText = sourceCode.getText(test).toLowerCase();
213
+ // Look for common frame-busting patterns
214
+ return testText.includes('top != self') ||
215
+ testText.includes('top !== self') ||
216
+ testText.includes('window.top !== window.self') ||
217
+ testText.includes('parent != self') ||
218
+ testText.includes('top.location') ||
219
+ testText.includes('self.location');
220
+ };
221
+ /**
222
+ * Check for transparent/invisible elements that could hide clickjacking
223
+ */
224
+ const hasTransparentStyles = (styleText) => {
225
+ const styles = styleText.toLowerCase();
226
+ return styles.includes('opacity: 0') ||
227
+ styles.includes('opacity:0') ||
228
+ styles.includes('visibility: hidden') ||
229
+ styles.includes('display: none') ||
230
+ styles.includes('z-index: -1') ||
231
+ styles.includes('position: absolute') && styles.includes('top: 0') && styles.includes('left: 0');
232
+ };
233
+ return {
234
+ // Check for frame-busting code
235
+ IfStatement(node) {
236
+ if (isFrameBustingCode(node)) {
237
+ hasFrameBusting = true;
238
+ }
239
+ },
240
+ // Check iframe elements (in JSX/TSX)
241
+ JSXElement(node) {
242
+ if (node.openingElement.name.type === 'JSXIdentifier' &&
243
+ node.openingElement.name.name === 'iframe') {
244
+ // Check iframe attributes
245
+ const attributes = node.openingElement.attributes;
246
+ let hasSrc = false;
247
+ let srcValue = '';
248
+ for (const attr of attributes) {
249
+ if (attr.type === 'JSXAttribute' &&
250
+ attr.name.type === 'JSXIdentifier' &&
251
+ attr.name.name === 'src' &&
252
+ attr.value) {
253
+ hasSrc = true;
254
+ if (attr.value.type === 'Literal' && typeof attr.value.value === 'string') {
255
+ srcValue = attr.value.value;
256
+ }
257
+ }
258
+ }
259
+ if (hasSrc && srcValue && !isTrustedSource(srcValue)) {
260
+ /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
261
+ if (safetyChecker.isSafe(node, context)) {
262
+ return;
263
+ }
264
+ /* c8 ignore stop */
265
+ context.report({
266
+ node: node.openingElement,
267
+ messageId: 'unsafeIframeUsage',
268
+ data: {
269
+ filePath: filename,
270
+ line: String(node.loc?.start.line ?? 0),
271
+ },
272
+ });
273
+ }
274
+ }
275
+ },
276
+ // Check for frame manipulation code
277
+ MemberExpression(node) {
278
+ // Look for top.location or window.top manipulation
279
+ if (node.object.type === 'Identifier' &&
280
+ (node.object.name === 'top' || node.object.name === 'window')) {
281
+ if (node.property.type === 'Identifier' &&
282
+ (node.property.name === 'location' || node.property.name === 'top')) {
283
+ // Check if this is being assigned or compared
284
+ let current = node;
285
+ let isFrameManipulation = false;
286
+ // Walk up to see if this is an assignment or comparison
287
+ while (current && !isFrameManipulation) {
288
+ if (current.type === 'AssignmentExpression' &&
289
+ current.left === node) {
290
+ isFrameManipulation = true;
291
+ break;
292
+ }
293
+ if (current.type === 'BinaryExpression' &&
294
+ (current.left === node || current.right === node)) {
295
+ // Comparison like top != self
296
+ const operator = current.operator;
297
+ if (operator === '!=' || operator === '!==' ||
298
+ operator === '==' || operator === '===') {
299
+ // This might be frame-busting code
300
+ break;
301
+ }
302
+ isFrameManipulation = true;
303
+ break;
304
+ }
305
+ current = current.parent;
306
+ }
307
+ if (isFrameManipulation) {
308
+ /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
309
+ if (safetyChecker.isSafe(node, context)) {
310
+ return;
311
+ }
312
+ /* c8 ignore stop */
313
+ context.report({
314
+ node,
315
+ messageId: 'frameManipulation',
316
+ data: {
317
+ filePath: filename,
318
+ line: String(node.loc?.start.line ?? 0),
319
+ },
320
+ });
321
+ }
322
+ }
323
+ }
324
+ },
325
+ // Check for CSS that could hide clickjacking attacks
326
+ Literal(node) {
327
+ if (typeof node.value === 'string' && detectTransparentOverlays) {
328
+ // Check if this looks like CSS
329
+ const text = node.value.toLowerCase();
330
+ if ((text.includes('style=') || text.includes('css')) &&
331
+ hasTransparentStyles(text)) {
332
+ /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
333
+ if (safetyChecker.isSafe(node, context)) {
334
+ return;
335
+ }
336
+ /* c8 ignore stop */
337
+ context.report({
338
+ node,
339
+ messageId: 'transparentFrameOverlay',
340
+ data: {
341
+ filePath: filename,
342
+ line: String(node.loc?.start.line ?? 0),
343
+ },
344
+ });
345
+ }
346
+ }
347
+ },
348
+ // Check template literals for CSS
349
+ TemplateLiteral(node) {
350
+ if (detectTransparentOverlays) {
351
+ const text = sourceCode.getText(node).toLowerCase();
352
+ if (text.includes('style') && hasTransparentStyles(text)) {
353
+ /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
354
+ if (safetyChecker.isSafe(node, context)) {
355
+ return;
356
+ }
357
+ /* c8 ignore stop */
358
+ context.report({
359
+ node,
360
+ messageId: 'transparentFrameOverlay',
361
+ data: {
362
+ filePath: filename,
363
+ line: String(node.loc?.start.line ?? 0),
364
+ },
365
+ });
366
+ }
367
+ }
368
+ },
369
+ // At the end of the file, check if frame-busting is required but missing
370
+ 'Program:exit'() {
371
+ if (requireFrameBusting && !hasFrameBusting) {
372
+ // Only check files that are likely entry points or render HTML
373
+ const isEntryPoint = /\.(html|htm)$/.test(filename) ||
374
+ /(index|app|main|page)\.(tsx|jsx)$/i.test(filename) ||
375
+ /pages?\/.*\.(tsx|jsx)$/i.test(filename) ||
376
+ /layout\.(tsx|jsx)$/i.test(filename);
377
+ // Skip non-entry point files
378
+ if (!isEntryPoint) {
379
+ return;
380
+ }
381
+ // Check if this file has actual UI rendering (JSX elements with event handlers)
382
+ const fileContent = sourceCode.getText();
383
+ const hasUIElements = fileContent.includes('<button') ||
384
+ fileContent.includes('<form') ||
385
+ fileContent.includes('<input') ||
386
+ (fileContent.includes('onClick') && fileContent.includes('<'));
387
+ if (hasUIElements) {
388
+ context.report({
389
+ node: context.sourceCode.ast,
390
+ messageId: 'missingFrameBusting',
391
+ data: {
392
+ filePath: filename,
393
+ line: '1',
394
+ },
395
+ });
396
+ }
397
+ }
398
+ }
399
+ };
400
+ },
401
+ });
@@ -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 noClientSideAuthLogic: 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,74 @@
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.noClientSideAuthLogic = void 0;
9
+ /**
10
+ * @fileoverview Prevent authentication logic in client code
11
+ */
12
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
+ exports.noClientSideAuthLogic = (0, eslint_devkit_1.createRule)({
14
+ name: 'no-client-side-auth-logic',
15
+ meta: {
16
+ type: 'problem',
17
+ docs: {
18
+ description: 'Prevent authentication logic in client code',
19
+ },
20
+ messages: {
21
+ violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
22
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
23
+ issueName: 'Client-Side Auth Logic',
24
+ cwe: 'CWE-602',
25
+ description: 'Authentication logic in client code - easily bypassed',
26
+ severity: 'CRITICAL',
27
+ fix: 'Move authentication checks to the server',
28
+ documentationLink: 'https://cwe.mitre.org/data/definitions/602.html',
29
+ })
30
+ },
31
+ schema: [],
32
+ },
33
+ defaultOptions: [],
34
+ create(context) {
35
+ function report(node) {
36
+ context.report({ node, messageId: 'violationDetected' });
37
+ }
38
+ const authKeywords = ['admin', 'authenticated', 'authorized', 'isAdmin', 'isAuthenticated', 'role'];
39
+ return {
40
+ IfStatement(node) {
41
+ // Detect role/auth checks from localStorage
42
+ if (node.test.type === 'CallExpression' &&
43
+ node.test.callee.type === 'MemberExpression' &&
44
+ node.test.callee.object.type === 'Identifier' &&
45
+ node.test.callee.object.name === 'localStorage' &&
46
+ node.test.callee.property.type === 'Identifier' &&
47
+ node.test.callee.property.name === 'getItem') {
48
+ const keyArg = node.test.arguments[0];
49
+ if (keyArg && keyArg.type === 'Literal') {
50
+ const key = String(keyArg.value).toLowerCase();
51
+ if (authKeywords.some(kw => key.includes(kw))) {
52
+ report(node);
53
+ }
54
+ }
55
+ }
56
+ // Detect password comparison
57
+ if (node.test.type === 'BinaryExpression') {
58
+ const checkMember = (expr) => {
59
+ if (expr.type === 'MemberExpression' &&
60
+ expr.property.type === 'Identifier' &&
61
+ ['password', 'secret', 'token'].includes(expr.property.name)) {
62
+ return true;
63
+ }
64
+ return false;
65
+ };
66
+ if (checkMember(node.test.left) ||
67
+ checkMember(node.test.right)) {
68
+ report(node);
69
+ }
70
+ }
71
+ },
72
+ };
73
+ },
74
+ });
@@ -17,5 +17,7 @@ export interface Options {
17
17
  allowInTests?: boolean;
18
18
  }
19
19
  type RuleOptions = [Options?];
20
- export declare const noCookieAuthTokens: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
20
+ export declare const noCookieAuthTokens: 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 noCredentialsInQueryParams: 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,62 @@
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.noCredentialsInQueryParams = void 0;
9
+ /**
10
+ * @fileoverview Disallow credentials in URL query parameters
11
+ * @see https://owasp.org/www-project-mobile-top-10/
12
+ * @see https://cwe.mitre.org/data/definitions/598.html
13
+ */
14
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
+ exports.noCredentialsInQueryParams = (0, eslint_devkit_1.createRule)({
16
+ name: 'no-credentials-in-query-params',
17
+ meta: {
18
+ type: 'problem',
19
+ docs: {
20
+ description: 'Disallow credentials in URL query parameters',
21
+ },
22
+ messages: {
23
+ violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
24
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
25
+ issueName: 'Credentials in Query Parameters',
26
+ cwe: 'CWE-798',
27
+ description: 'Credentials detected in URL query parameters - this is a security risk',
28
+ severity: 'CRITICAL',
29
+ fix: 'Use secure methods: POST body, headers (Authorization), or secure cookies',
30
+ documentationLink: 'https://cwe.mitre.org/data/definitions/798.html',
31
+ })
32
+ },
33
+ schema: [],
34
+ },
35
+ defaultOptions: [],
36
+ create(context) {
37
+ const sourceCode = context.sourceCode;
38
+ const sensitiveParams = ['password=', 'token=', 'apikey=', 'secret=', 'auth='];
39
+ function report(node) {
40
+ context.report({
41
+ node,
42
+ messageId: 'violationDetected',
43
+ });
44
+ }
45
+ return {
46
+ Literal(node) {
47
+ if (typeof node.value === 'string') {
48
+ const url = node.value.toLowerCase();
49
+ if (sensitiveParams.some(param => url.includes('?' + param) || url.includes('&' + param))) {
50
+ report(node);
51
+ }
52
+ }
53
+ },
54
+ TemplateLiteral(node) {
55
+ const text = sourceCode.getText(node).toLowerCase();
56
+ if (sensitiveParams.some(param => text.includes(param))) {
57
+ report(node);
58
+ }
59
+ },
60
+ };
61
+ },
62
+ });
@@ -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 noDisabledCertificateValidation: 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,66 @@
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.noDisabledCertificateValidation = void 0;
9
+ /**
10
+ * @fileoverview Prevent disabled SSL/TLS certificate validation
11
+ */
12
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
+ exports.noDisabledCertificateValidation = (0, eslint_devkit_1.createRule)({
14
+ name: 'no-disabled-certificate-validation',
15
+ meta: {
16
+ type: 'problem',
17
+ docs: {
18
+ description: 'Prevent disabled SSL/TLS certificate validation',
19
+ },
20
+ messages: {
21
+ violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
22
+ icon: eslint_devkit_1.MessageIcons.SECURITY,
23
+ issueName: 'Disabled Certificate Validation',
24
+ cwe: 'CWE-295',
25
+ description: 'SSL/TLS certificate validation is disabled - man-in-the-middle attack possible',
26
+ severity: 'CRITICAL',
27
+ fix: 'Remove rejectUnauthorized: false or verify: false, fix certificate issues properly',
28
+ documentationLink: 'https://cwe.mitre.org/data/definitions/295.html',
29
+ })
30
+ },
31
+ schema: [],
32
+ },
33
+ defaultOptions: [],
34
+ create(context) {
35
+ function report(node) {
36
+ context.report({ node, messageId: 'violationDetected' });
37
+ }
38
+ const dangerousProperties = ['rejectUnauthorized', 'strictSSL', 'verify'];
39
+ return {
40
+ Property(node) {
41
+ // Check for dangerous SSL options set to false
42
+ if (node.key.type === 'Identifier' &&
43
+ dangerousProperties.includes(node.key.name) &&
44
+ node.value.type === 'Literal' &&
45
+ node.value.value === false) {
46
+ report(node);
47
+ }
48
+ },
49
+ AssignmentExpression(node) {
50
+ // Check for NODE_TLS_REJECT_UNAUTHORIZED = '0'
51
+ if (node.left.type === 'MemberExpression' &&
52
+ node.left.object.type === 'MemberExpression' &&
53
+ node.left.object.object.type === 'Identifier' &&
54
+ node.left.object.object.name === 'process' &&
55
+ node.left.object.property.type === 'Identifier' &&
56
+ node.left.object.property.name === 'env' &&
57
+ node.left.property.type === 'Identifier' &&
58
+ node.left.property.name === 'NODE_TLS_REJECT_UNAUTHORIZED') {
59
+ if (node.right.type === 'Literal' && node.right.value === '0') {
60
+ report(node);
61
+ }
62
+ }
63
+ },
64
+ };
65
+ },
66
+ });
@@ -17,5 +17,7 @@ export interface Options {
17
17
  allowInTests?: boolean;
18
18
  }
19
19
  type RuleOptions = [Options?];
20
- export declare const noDynamicServiceWorkerUrl: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
20
+ export declare const noDynamicServiceWorkerUrl: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
21
+ name: string;
22
+ };
21
23
  export {};