eslint-plugin-secure-coding 3.0.1 → 3.1.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 (128) hide show
  1. package/README.md +2 -1
  2. package/package.json +4 -3
  3. package/src/index.d.ts +2 -2
  4. package/src/index.js +29 -263
  5. package/src/rules/detect-non-literal-regexp/index.d.ts +3 -1
  6. package/src/rules/detect-object-injection/index.d.ts +3 -1
  7. package/src/rules/detect-weak-password-validation/index.d.ts +3 -1
  8. package/src/rules/no-directive-injection/index.d.ts +3 -1
  9. package/src/rules/no-electron-security-issues/index.d.ts +3 -1
  10. package/src/rules/no-format-string-injection/index.d.ts +3 -1
  11. package/src/rules/no-graphql-injection/index.d.ts +3 -1
  12. package/src/rules/no-hardcoded-credentials/index.d.ts +3 -1
  13. package/src/rules/no-hardcoded-session-tokens/index.d.ts +3 -1
  14. package/src/rules/no-improper-sanitization/index.d.ts +3 -1
  15. package/src/rules/no-improper-type-validation/index.d.ts +3 -1
  16. package/src/rules/no-insecure-comparison/index.d.ts +3 -1
  17. package/src/rules/no-ldap-injection/index.d.ts +3 -1
  18. package/src/rules/no-missing-authentication/index.d.ts +3 -1
  19. package/src/rules/no-pii-in-logs/index.d.ts +3 -1
  20. package/src/rules/no-privilege-escalation/index.d.ts +3 -1
  21. package/src/rules/no-redos-vulnerable-regex/index.d.ts +3 -1
  22. package/src/rules/no-sensitive-data-exposure/index.d.ts +3 -1
  23. package/src/rules/no-unchecked-loop-condition/index.d.ts +3 -1
  24. package/src/rules/no-unlimited-resource-allocation/index.d.ts +3 -1
  25. package/src/rules/no-unsafe-deserialization/index.d.ts +3 -1
  26. package/src/rules/no-unsafe-regex-construction/index.d.ts +3 -1
  27. package/src/rules/no-weak-password-recovery/index.d.ts +3 -1
  28. package/src/rules/no-xpath-injection/index.d.ts +3 -1
  29. package/src/rules/no-xxe-injection/index.d.ts +3 -1
  30. package/src/rules/require-backend-authorization/index.d.ts +3 -1
  31. package/src/rules/require-secure-defaults/index.d.ts +3 -1
  32. package/src/types/index.d.ts +5 -52
  33. package/src/rules/detect-child-process/index.d.ts +0 -28
  34. package/src/rules/detect-child-process/index.js +0 -534
  35. package/src/rules/detect-eval-with-expression/index.d.ts +0 -26
  36. package/src/rules/detect-eval-with-expression/index.js +0 -397
  37. package/src/rules/detect-mixed-content/index.d.ts +0 -10
  38. package/src/rules/detect-mixed-content/index.js +0 -45
  39. package/src/rules/detect-non-literal-fs-filename/index.d.ts +0 -24
  40. package/src/rules/detect-non-literal-fs-filename/index.js +0 -459
  41. package/src/rules/detect-suspicious-dependencies/index.d.ts +0 -10
  42. package/src/rules/detect-suspicious-dependencies/index.js +0 -76
  43. package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -10
  44. package/src/rules/no-allow-arbitrary-loads/index.js +0 -48
  45. package/src/rules/no-arbitrary-file-access/index.d.ts +0 -10
  46. package/src/rules/no-arbitrary-file-access/index.js +0 -200
  47. package/src/rules/no-buffer-overread/index.d.ts +0 -37
  48. package/src/rules/no-buffer-overread/index.js +0 -611
  49. package/src/rules/no-clickjacking/index.d.ts +0 -34
  50. package/src/rules/no-clickjacking/index.js +0 -401
  51. package/src/rules/no-client-side-auth-logic/index.d.ts +0 -10
  52. package/src/rules/no-client-side-auth-logic/index.js +0 -74
  53. package/src/rules/no-credentials-in-query-params/index.d.ts +0 -10
  54. package/src/rules/no-credentials-in-query-params/index.js +0 -62
  55. package/src/rules/no-data-in-temp-storage/index.d.ts +0 -10
  56. package/src/rules/no-data-in-temp-storage/index.js +0 -69
  57. package/src/rules/no-debug-code-in-production/index.d.ts +0 -10
  58. package/src/rules/no-debug-code-in-production/index.js +0 -54
  59. package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -10
  60. package/src/rules/no-disabled-certificate-validation/index.js +0 -66
  61. package/src/rules/no-dynamic-dependency-loading/index.d.ts +0 -10
  62. package/src/rules/no-dynamic-dependency-loading/index.js +0 -54
  63. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -10
  64. package/src/rules/no-exposed-debug-endpoints/index.js +0 -67
  65. package/src/rules/no-exposed-sensitive-data/index.d.ts +0 -28
  66. package/src/rules/no-exposed-sensitive-data/index.js +0 -345
  67. package/src/rules/no-http-urls/index.d.ts +0 -15
  68. package/src/rules/no-http-urls/index.js +0 -119
  69. package/src/rules/no-insecure-redirects/index.d.ts +0 -24
  70. package/src/rules/no-insecure-redirects/index.js +0 -221
  71. package/src/rules/no-insecure-websocket/index.d.ts +0 -10
  72. package/src/rules/no-insecure-websocket/index.js +0 -66
  73. package/src/rules/no-missing-cors-check/index.d.ts +0 -26
  74. package/src/rules/no-missing-cors-check/index.js +0 -404
  75. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -28
  76. package/src/rules/no-missing-csrf-protection/index.js +0 -185
  77. package/src/rules/no-missing-security-headers/index.d.ts +0 -24
  78. package/src/rules/no-missing-security-headers/index.js +0 -223
  79. package/src/rules/no-password-in-url/index.d.ts +0 -10
  80. package/src/rules/no-password-in-url/index.js +0 -55
  81. package/src/rules/no-permissive-cors/index.d.ts +0 -10
  82. package/src/rules/no-permissive-cors/index.js +0 -74
  83. package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -10
  84. package/src/rules/no-sensitive-data-in-analytics/index.js +0 -66
  85. package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -10
  86. package/src/rules/no-sensitive-data-in-cache/index.js +0 -53
  87. package/src/rules/no-toctou-vulnerability/index.d.ts +0 -24
  88. package/src/rules/no-toctou-vulnerability/index.js +0 -213
  89. package/src/rules/no-tracking-without-consent/index.d.ts +0 -10
  90. package/src/rules/no-tracking-without-consent/index.js +0 -72
  91. package/src/rules/no-unencrypted-transmission/index.d.ts +0 -28
  92. package/src/rules/no-unencrypted-transmission/index.js +0 -241
  93. package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -26
  94. package/src/rules/no-unescaped-url-parameter/index.js +0 -360
  95. package/src/rules/no-unsafe-dynamic-require/index.d.ts +0 -17
  96. package/src/rules/no-unsafe-dynamic-require/index.js +0 -111
  97. package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -10
  98. package/src/rules/no-unvalidated-deeplinks/index.js +0 -67
  99. package/src/rules/no-unvalidated-user-input/index.d.ts +0 -26
  100. package/src/rules/no-unvalidated-user-input/index.js +0 -425
  101. package/src/rules/no-verbose-error-messages/index.d.ts +0 -10
  102. package/src/rules/no-verbose-error-messages/index.js +0 -73
  103. package/src/rules/no-zip-slip/index.d.ts +0 -33
  104. package/src/rules/no-zip-slip/index.js +0 -450
  105. package/src/rules/require-code-minification/index.d.ts +0 -10
  106. package/src/rules/require-code-minification/index.js +0 -48
  107. package/src/rules/require-csp-headers/index.d.ts +0 -10
  108. package/src/rules/require-csp-headers/index.js +0 -69
  109. package/src/rules/require-data-minimization/index.d.ts +0 -10
  110. package/src/rules/require-data-minimization/index.js +0 -55
  111. package/src/rules/require-dependency-integrity/index.d.ts +0 -10
  112. package/src/rules/require-dependency-integrity/index.js +0 -69
  113. package/src/rules/require-https-only/index.d.ts +0 -10
  114. package/src/rules/require-https-only/index.js +0 -67
  115. package/src/rules/require-mime-type-validation/index.d.ts +0 -10
  116. package/src/rules/require-mime-type-validation/index.js +0 -71
  117. package/src/rules/require-network-timeout/index.d.ts +0 -10
  118. package/src/rules/require-network-timeout/index.js +0 -57
  119. package/src/rules/require-package-lock/index.d.ts +0 -10
  120. package/src/rules/require-package-lock/index.js +0 -64
  121. package/src/rules/require-secure-credential-storage/index.d.ts +0 -10
  122. package/src/rules/require-secure-credential-storage/index.js +0 -53
  123. package/src/rules/require-secure-deletion/index.d.ts +0 -10
  124. package/src/rules/require-secure-deletion/index.js +0 -45
  125. package/src/rules/require-storage-encryption/index.d.ts +0 -10
  126. package/src/rules/require-storage-encryption/index.js +0 -53
  127. package/src/rules/require-url-validation/index.d.ts +0 -10
  128. package/src/rules/require-url-validation/index.js +0 -77
@@ -1,450 +0,0 @@
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.noZipSlip = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- exports.noZipSlip = (0, eslint_devkit_1.createRule)({
12
- name: 'no-zip-slip',
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Detects zip slip/archive extraction vulnerabilities',
17
- },
18
- fixable: 'code',
19
- hasSuggestions: true,
20
- messages: {
21
- zipSlipVulnerability: (0, eslint_devkit_2.formatLLMMessage)({
22
- icon: eslint_devkit_2.MessageIcons.SECURITY,
23
- issueName: 'Zip Slip Vulnerability',
24
- cwe: 'CWE-22',
25
- description: 'Archive extraction vulnerable to path traversal',
26
- severity: '{{severity}}',
27
- fix: '{{safeAlternative}}',
28
- documentationLink: 'https://cwe.mitre.org/data/definitions/22.html',
29
- }),
30
- unsafeArchiveExtraction: (0, eslint_devkit_2.formatLLMMessage)({
31
- icon: eslint_devkit_2.MessageIcons.SECURITY,
32
- issueName: 'Unsafe Archive Extraction',
33
- cwe: 'CWE-22',
34
- description: 'Archive extraction without path validation',
35
- severity: 'HIGH',
36
- fix: 'Use safe extraction libraries or validate all paths',
37
- documentationLink: 'https://snyk.io/research/zip-slip-vulnerability',
38
- }),
39
- pathTraversalInArchive: (0, eslint_devkit_2.formatLLMMessage)({
40
- icon: eslint_devkit_2.MessageIcons.SECURITY,
41
- issueName: 'Path Traversal in Archive',
42
- cwe: 'CWE-22',
43
- description: 'Archive contains path traversal sequences',
44
- severity: 'CRITICAL',
45
- fix: 'Reject archives with path traversal or sanitize paths',
46
- documentationLink: 'https://cwe.mitre.org/data/definitions/22.html',
47
- }),
48
- unvalidatedArchivePath: (0, eslint_devkit_2.formatLLMMessage)({
49
- icon: eslint_devkit_2.MessageIcons.SECURITY,
50
- issueName: 'Unvalidated Archive Path',
51
- cwe: 'CWE-22',
52
- description: 'Archive entry path used without validation',
53
- severity: 'HIGH',
54
- fix: 'Validate paths before extraction',
55
- documentationLink: 'https://snyk.io/research/zip-slip-vulnerability',
56
- }),
57
- dangerousArchiveDestination: (0, eslint_devkit_2.formatLLMMessage)({
58
- icon: eslint_devkit_2.MessageIcons.SECURITY,
59
- issueName: 'Dangerous Archive Destination',
60
- cwe: 'CWE-22',
61
- description: 'Archive extracted to sensitive location',
62
- severity: 'MEDIUM',
63
- fix: 'Extract to safe temporary directory',
64
- documentationLink: 'https://cwe.mitre.org/data/definitions/22.html',
65
- }),
66
- useSafeArchiveExtraction: (0, eslint_devkit_2.formatLLMMessage)({
67
- icon: eslint_devkit_2.MessageIcons.INFO,
68
- issueName: 'Use Safe Archive Extraction',
69
- description: 'Use libraries with built-in path validation',
70
- severity: 'LOW',
71
- fix: 'Use yauzl, safe-archive-extract, or similar safe libraries',
72
- documentationLink: 'https://www.npmjs.com/package/yauzl',
73
- }),
74
- validateArchivePaths: (0, eslint_devkit_2.formatLLMMessage)({
75
- icon: eslint_devkit_2.MessageIcons.INFO,
76
- issueName: 'Validate Archive Paths',
77
- description: 'Validate all archive entry paths',
78
- severity: 'LOW',
79
- fix: 'Check paths don\'t contain ../ and are within destination directory',
80
- documentationLink: 'https://snyk.io/research/zip-slip-vulnerability',
81
- }),
82
- sanitizeArchiveNames: (0, eslint_devkit_2.formatLLMMessage)({
83
- icon: eslint_devkit_2.MessageIcons.INFO,
84
- issueName: 'Sanitize Archive Names',
85
- description: 'Sanitize archive entry names',
86
- severity: 'LOW',
87
- fix: 'Use path.basename() or custom sanitization',
88
- documentationLink: 'https://nodejs.org/api/path.html#pathbasenamepath-ext',
89
- }),
90
- strategyPathValidation: (0, eslint_devkit_2.formatLLMMessage)({
91
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
92
- issueName: 'Path Validation Strategy',
93
- description: 'Validate paths before any file operations',
94
- severity: 'LOW',
95
- fix: 'Check path.startsWith(destination) and no ../ sequences',
96
- documentationLink: 'https://cwe.mitre.org/data/definitions/22.html',
97
- }),
98
- strategySafeLibraries: (0, eslint_devkit_2.formatLLMMessage)({
99
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
100
- issueName: 'Safe Libraries Strategy',
101
- description: 'Use archive libraries with built-in safety',
102
- severity: 'LOW',
103
- fix: 'Use yauzl, adm-zip with validation, or safe-archive-extract',
104
- documentationLink: 'https://www.npmjs.com/package/safe-archive-extract',
105
- }),
106
- strategySandboxing: (0, eslint_devkit_2.formatLLMMessage)({
107
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
108
- issueName: 'Sandboxing Strategy',
109
- description: 'Extract archives in sandboxed environment',
110
- severity: 'LOW',
111
- fix: 'Use temporary directories and restrict permissions',
112
- documentationLink: 'https://nodejs.org/api/fs.html#fsopentempdirprefix-options-callback',
113
- })
114
- },
115
- schema: [
116
- {
117
- type: 'object',
118
- properties: {
119
- archiveFunctions: {
120
- type: 'array',
121
- items: { type: 'string' },
122
- default: ['extract', 'extractAll', 'extractAllTo', 'unzip', 'untar', 'extractArchive'],
123
- },
124
- pathValidationFunctions: {
125
- type: 'array',
126
- items: { type: 'string' },
127
- default: ['validatePath', 'sanitizePath', 'checkPath', 'safePath'],
128
- },
129
- safeLibraries: {
130
- type: 'array',
131
- items: { type: 'string' },
132
- default: ['yauzl', 'safe-archive-extract', 'tar-stream', 'unzipper'],
133
- },
134
- },
135
- additionalProperties: false,
136
- },
137
- ],
138
- },
139
- defaultOptions: [
140
- {
141
- archiveFunctions: ['extract', 'extractAll', 'extractAllTo', 'unzip', 'untar', 'extractArchive'],
142
- pathValidationFunctions: ['validatePath', 'sanitizePath', 'checkPath', 'safePath'],
143
- safeLibraries: ['yauzl', 'safe-archive-extract', 'tar-stream', 'unzipper'],
144
- },
145
- ],
146
- create(context) {
147
- const options = context.options[0] || {};
148
- const { archiveFunctions = ['extract', 'extractAll', 'extractAllTo', 'unzip', 'untar', 'extractArchive'], pathValidationFunctions = ['validatePath', 'sanitizePath', 'checkPath', 'safePath'], safeLibraries = ['yauzl', 'safe-archive-extract', 'tar-stream', 'unzipper'], } = options;
149
- const filename = context.filename || context.getFilename();
150
- // Safety checks are implemented directly in the handlers
151
- /**
152
- * Check if this is an archive extraction operation
153
- */
154
- const isArchiveExtraction = (node) => {
155
- const callee = node.callee;
156
- // Check for archive method calls (e.g., zip.extractAllTo)
157
- if (callee.type === 'MemberExpression' &&
158
- callee.property.type === 'Identifier' &&
159
- archiveFunctions.includes(callee.property.name)) {
160
- return true;
161
- }
162
- // Check for standalone archive functions (e.g., extractArchive)
163
- if (callee.type === 'Identifier' &&
164
- archiveFunctions.includes(callee.name)) {
165
- return true;
166
- }
167
- return false;
168
- };
169
- /**
170
- * Check if path contains dangerous traversal sequences
171
- */
172
- const containsPathTraversal = (pathText) => {
173
- // Check for ../ sequences
174
- return /\.\.\//.test(pathText) ||
175
- /\.\.\\/.test(pathText) || // Windows paths
176
- /^\.\./.test(pathText) || // Leading ..
177
- /\/\.\./.test(pathText); // Embedded /..
178
- };
179
- /**
180
- * Check if path has been validated
181
- */
182
- const isPathValidated = (pathNode) => {
183
- let current = pathNode;
184
- while (current) {
185
- if (current.type === 'CallExpression' &&
186
- current.callee.type === 'Identifier' &&
187
- pathValidationFunctions.includes(current.callee.name)) {
188
- return true;
189
- }
190
- current = current.parent;
191
- }
192
- return false;
193
- };
194
- /**
195
- * Check if this uses a safe library
196
- */
197
- const isSafeLibrary = (node) => {
198
- const callee = node.callee;
199
- if (callee.type === 'MemberExpression' &&
200
- callee.object.type === 'Identifier' &&
201
- safeLibraries.includes(callee.object.name)) {
202
- return true;
203
- }
204
- return false;
205
- };
206
- /**
207
- * Check if destination is dangerous
208
- */
209
- const isDangerousDestination = (destText) => {
210
- return destText.includes('/tmp') ||
211
- destText.includes('/var') ||
212
- destText.includes('/usr') ||
213
- destText.includes('/etc') ||
214
- destText.includes('/root') ||
215
- destText.includes('/home') ||
216
- destText.includes('C:\\Windows') ||
217
- destText.includes('C:\\Program Files') ||
218
- destText.includes('C:\\Users');
219
- };
220
- return {
221
- // Check archive extraction calls
222
- CallExpression(node) {
223
- if (isArchiveExtraction(node) && !isSafeLibrary(node)) {
224
- // Check for @safe annotations in the source
225
- const sourceCode = context.sourceCode;
226
- let hasSafeAnnotation = false;
227
- // Look for @safe comments in the source code
228
- const allComments = sourceCode.getAllComments();
229
- for (const comment of allComments) {
230
- if (comment.type === 'Block' && comment.value.includes('@safe')) {
231
- hasSafeAnnotation = true;
232
- break;
233
- }
234
- }
235
- if (hasSafeAnnotation) {
236
- return; // Skip reporting if marked as safe
237
- }
238
- // Check if destination is dangerous
239
- const args = node.arguments;
240
- let destArg;
241
- // Determine which argument is the destination based on the function
242
- if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier') {
243
- const methodName = node.callee.property.name;
244
- if (['extractAllTo', 'unzip'].includes(methodName)) {
245
- // Destination is the first argument
246
- destArg = args[0];
247
- }
248
- else if (archiveFunctions.includes(methodName)) {
249
- // For other archive functions, destination is typically the second argument
250
- destArg = args.length >= 2 ? args[1] : undefined;
251
- }
252
- }
253
- else if (node.callee.type === 'Identifier' && archiveFunctions.includes(node.callee.name)) {
254
- // For standalone functions like extractArchive(file, dest)
255
- destArg = args.length >= 2 ? args[1] : undefined;
256
- }
257
- const destText = destArg && destArg.type === 'Literal' && typeof destArg.value === 'string' ? destArg.value : '';
258
- const isDestDangerous = isDangerousDestination(destText);
259
- const isMethodCall = node.callee.type === 'MemberExpression';
260
- if (isMethodCall) {
261
- // Method calls report unsafeArchiveExtraction unless destination is a safe relative path
262
- const isSafeRelativePath = destText.startsWith('./') || destText.startsWith('../');
263
- if (!isSafeRelativePath) {
264
- context.report({
265
- node,
266
- messageId: 'unsafeArchiveExtraction',
267
- data: {
268
- filePath: filename,
269
- line: String(node.loc?.start.line ?? 0),
270
- },
271
- suggest: [
272
- {
273
- messageId: 'useSafeArchiveExtraction',
274
- fix: () => null,
275
- },
276
- ],
277
- });
278
- }
279
- // For safe relative paths, don't report any error
280
- // Additionally report dangerous destination for dangerous destinations
281
- if (isDestDangerous) {
282
- context.report({
283
- node: destArg || node,
284
- messageId: 'dangerousArchiveDestination',
285
- data: {
286
- filePath: filename,
287
- line: String(node.loc?.start.line ?? 0),
288
- },
289
- });
290
- }
291
- }
292
- else {
293
- // Standalone calls: report dangerousArchiveDestination for dangerous destinations, unsafeArchiveExtraction otherwise
294
- if (isDestDangerous) {
295
- context.report({
296
- node,
297
- messageId: 'dangerousArchiveDestination',
298
- data: {
299
- filePath: filename,
300
- line: String(node.loc?.start.line ?? 0),
301
- },
302
- });
303
- }
304
- else {
305
- context.report({
306
- node,
307
- messageId: 'unsafeArchiveExtraction',
308
- data: {
309
- filePath: filename,
310
- line: String(node.loc?.start.line ?? 0),
311
- },
312
- suggest: [
313
- {
314
- messageId: 'useSafeArchiveExtraction',
315
- fix: () => null
316
- },
317
- ],
318
- });
319
- }
320
- }
321
- }
322
- // Check for path.join or similar operations with archive entry names
323
- const callee = node.callee;
324
- if (callee.type === 'MemberExpression' &&
325
- callee.property.type === 'Identifier' &&
326
- ['join', 'resolve', 'relative', 'normalize'].includes(callee.property.name)) {
327
- // Check arguments for potential archive entry usage
328
- const args = node.arguments;
329
- for (const arg of args) {
330
- if (arg.type === 'MemberExpression' &&
331
- arg.property.type === 'Identifier' &&
332
- ['name', 'path', 'fileName', 'entryName', 'relativePath', 'filename', 'pathname'].includes(arg.property.name)) {
333
- // This looks like path.join(dest, entry.name) - check if validated
334
- if (!isPathValidated(arg)) {
335
- context.report({
336
- node: arg,
337
- messageId: 'unvalidatedArchivePath',
338
- data: {
339
- filePath: filename,
340
- line: String(node.loc?.start.line ?? 0),
341
- },
342
- });
343
- }
344
- }
345
- }
346
- }
347
- },
348
- // Check string literals for dangerous paths
349
- Literal(node) {
350
- if (typeof node.value !== 'string') {
351
- return;
352
- }
353
- const text = node.value;
354
- // Check for path traversal in strings that look like file paths
355
- if ((text.includes('/') || text.includes('\\')) && containsPathTraversal(text)) {
356
- // Check if this is in an archive-related context
357
- let current = node;
358
- let isArchiveContext = false;
359
- while (current && !isArchiveContext) {
360
- if (current.type === 'CallExpression' && isArchiveExtraction(current)) {
361
- isArchiveContext = true;
362
- break;
363
- }
364
- if (current.type === 'VariableDeclarator' &&
365
- current.id.type === 'Identifier' &&
366
- (current.id.name.includes('archive') ||
367
- current.id.name.includes('zip') ||
368
- current.id.name.includes('tar') ||
369
- current.id.name.includes('path') ||
370
- current.id.name.includes('file') ||
371
- current.id.name.includes('entry'))) {
372
- isArchiveContext = true;
373
- break;
374
- }
375
- current = current.parent;
376
- }
377
- // Also check if the variable name suggests archive usage
378
- const parent = node.parent;
379
- if (parent && parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {
380
- const varName = parent.id.name.toLowerCase();
381
- if (varName.includes('archive') || varName.includes('zip') || varName.includes('tar') ||
382
- varName.includes('path') || varName.includes('file') || varName.includes('extract') ||
383
- varName.includes('entry')) {
384
- isArchiveContext = true;
385
- }
386
- }
387
- if (isArchiveContext) {
388
- context.report({
389
- node,
390
- messageId: 'pathTraversalInArchive',
391
- data: {
392
- filePath: filename,
393
- line: String(node.loc?.start.line ?? 0),
394
- },
395
- });
396
- }
397
- }
398
- // Dangerous destinations are handled by the CallExpression handler to avoid duplicates
399
- // Only check for dangerous destinations not related to archive extraction
400
- if (isDangerousDestination(text) && !containsPathTraversal(text)) {
401
- // Check if this is used as an extraction destination
402
- let current = node;
403
- let isExtractionDest = false;
404
- while (current && !isExtractionDest) {
405
- if (current.type === 'CallExpression' && isArchiveExtraction(current)) {
406
- // Check if this node is a destination argument
407
- const args = current.arguments;
408
- const callee = current.callee;
409
- const isMethodCall = callee.type === 'MemberExpression';
410
- if ((isMethodCall && args.length >= 1 && args[0] === node) ||
411
- (!isMethodCall && args.length >= 2 && args[1] === node)) {
412
- isExtractionDest = true;
413
- break;
414
- }
415
- }
416
- current = current.parent;
417
- }
418
- // Only report if not already handled by CallExpression handler
419
- if (!isExtractionDest) {
420
- context.report({
421
- node,
422
- messageId: 'dangerousArchiveDestination',
423
- data: {
424
- filePath: filename,
425
- line: String(node.loc?.start.line ?? 0),
426
- },
427
- });
428
- }
429
- }
430
- },
431
- // Check variable assignments
432
- VariableDeclarator(node) {
433
- if (!node.init || node.id.type !== 'Identifier') {
434
- return;
435
- }
436
- const varName = node.id.name.toLowerCase();
437
- // Check if this variable holds archive-related data
438
- if (varName.includes('entry') || varName.includes('file') || varName.includes('path')) {
439
- if (node.init.type === 'MemberExpression' &&
440
- node.init.property.type === 'Identifier' &&
441
- ['name', 'path'].includes(node.init.property.name)) {
442
- // This looks like: const entryName = entry.name;
443
- // Check if this variable is used unsafely later
444
- // This is a simplified check - in practice we'd need more sophisticated analysis
445
- }
446
- }
447
- }
448
- };
449
- },
450
- });
@@ -1,10 +0,0 @@
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 requireCodeMinification: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
10
- export {};
@@ -1,48 +0,0 @@
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.requireCodeMinification = void 0;
9
- /**
10
- * @fileoverview Require minification configuration
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/656.html
13
- */
14
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
- exports.requireCodeMinification = (0, eslint_devkit_1.createRule)({
16
- name: 'require-code-minification',
17
- meta: {
18
- type: 'problem',
19
- docs: {
20
- description: 'Require minification configuration',
21
- },
22
- messages: {
23
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
24
- icon: eslint_devkit_1.MessageIcons.SECURITY,
25
- issueName: 'violation Detected',
26
- cwe: 'CWE-656',
27
- description: 'Require minification configuration detected - Build config without minification',
28
- severity: 'LOW',
29
- fix: 'Review and apply secure practices',
30
- documentationLink: 'https://cwe.mitre.org/data/definitions/656.html',
31
- })
32
- },
33
- schema: [],
34
- },
35
- defaultOptions: [],
36
- create(context) {
37
- return {
38
- Property(node) {
39
- if (node.key.type === 'Identifier' &&
40
- node.key.name === 'minimize' &&
41
- node.value.type === 'Literal' &&
42
- node.value.value === false) {
43
- context.report({ node, messageId: 'violationDetected' });
44
- }
45
- },
46
- };
47
- },
48
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) 2025 Ofri Peretz
3
- * Licensed under the MIT License. Use of this source code is governed by the
4
- * MIT license that can be found in the LICENSE file.
5
- */
6
- export interface Options {
7
- }
8
- type RuleOptions = [Options?];
9
- export declare const requireCspHeaders: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
10
- export {};
@@ -1,69 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) 2025 Ofri Peretz
4
- * Licensed under the MIT License. Use of this source code is governed by the
5
- * MIT license that can be found in the LICENSE file.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.requireCspHeaders = void 0;
9
- /**
10
- * @fileoverview Require Content Security Policy
11
- */
12
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
- exports.requireCspHeaders = (0, eslint_devkit_1.createRule)({
14
- name: 'require-csp-headers',
15
- meta: {
16
- type: 'problem',
17
- docs: {
18
- description: 'Require Content Security Policy headers',
19
- },
20
- messages: {
21
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
22
- icon: eslint_devkit_1.MessageIcons.SECURITY,
23
- issueName: 'Missing CSP',
24
- cwe: 'CWE-1021',
25
- description: 'HTML response without Content-Security-Policy header',
26
- severity: 'MEDIUM',
27
- fix: 'Use helmet.contentSecurityPolicy() or set CSP header manually',
28
- documentationLink: 'https://cwe.mitre.org/data/definitions/1021.html',
29
- })
30
- },
31
- schema: [],
32
- },
33
- defaultOptions: [],
34
- create(context) {
35
- function report(node) {
36
- context.report({ node, messageId: 'violationDetected' });
37
- }
38
- return {
39
- CallExpression(node) {
40
- // Detect res.send(html) with HTML content without CSP
41
- if (node.callee.type === 'MemberExpression' &&
42
- node.callee.property.type === 'Identifier' &&
43
- node.callee.property.name === 'send') {
44
- const arg = node.arguments[0];
45
- // Check if sending HTML string
46
- if (arg && arg.type === 'TemplateLiteral') {
47
- const quasi = arg.quasis[0]?.value?.raw || '';
48
- if (quasi.includes('<html') || quasi.includes('<!DOCTYPE')) {
49
- report(node);
50
- }
51
- }
52
- if (arg && arg.type === 'Literal' && typeof arg.value === 'string') {
53
- if (arg.value.includes('<html') || arg.value.includes('<!DOCTYPE')) {
54
- report(node);
55
- }
56
- }
57
- }
58
- // Detect res.render() without CSP middleware
59
- if (node.callee.type === 'MemberExpression' &&
60
- node.callee.property.type === 'Identifier' &&
61
- node.callee.property.name === 'render') {
62
- // This is a heuristic - flag render calls as a reminder
63
- // In real projects, you'd check for helmet middleware
64
- report(node);
65
- }
66
- },
67
- };
68
- },
69
- });
@@ -1,10 +0,0 @@
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 requireDataMinimization: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
10
- export {};
@@ -1,55 +0,0 @@
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.requireDataMinimization = void 0;
9
- /**
10
- * @fileoverview Identify excessive data collection
11
- * @see https://owasp.org/www-project-mobile-top-10/
12
- * @see https://cwe.mitre.org/data/definitions/213.html
13
- */
14
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
15
- exports.requireDataMinimization = (0, eslint_devkit_1.createRule)({
16
- name: 'require-data-minimization',
17
- meta: {
18
- type: 'suggestion',
19
- docs: {
20
- description: 'Identify excessive data collection patterns',
21
- },
22
- messages: {
23
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
24
- icon: eslint_devkit_1.MessageIcons.SECURITY,
25
- issueName: 'violation Detected',
26
- cwe: 'CWE-213',
27
- description: 'Excessive data collection detected - only collect data that is necessary',
28
- severity: 'MEDIUM',
29
- fix: 'Review and apply secure practices',
30
- documentationLink: 'https://cwe.mitre.org/data/definitions/213.html',
31
- })
32
- },
33
- schema: [],
34
- },
35
- defaultOptions: [],
36
- create(context) {
37
- function report(node) {
38
- context.report({ node, messageId: 'violationDetected' });
39
- }
40
- return {
41
- ObjectExpression(node) {
42
- // Flag objects with >10 properties being collected
43
- if (node.properties.length > 10) {
44
- // Check if this looks like user data collection
45
- const hasUserData = node.properties.some(p => p.type === eslint_devkit_1.AST_NODE_TYPES.Property &&
46
- p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
47
- ['email', 'name', 'phone', 'address'].includes(p.key.name));
48
- if (hasUserData) {
49
- report(node);
50
- }
51
- }
52
- },
53
- };
54
- },
55
- });
@@ -1,10 +0,0 @@
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 requireDependencyIntegrity: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
10
- export {};