eslint-plugin-secure-coding 3.0.1 → 3.0.2

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 (130) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +60 -226
  3. package/package.json +6 -5
  4. package/src/index.d.ts +2 -2
  5. package/src/index.js +29 -263
  6. package/src/rules/detect-non-literal-regexp/index.d.ts +3 -1
  7. package/src/rules/detect-object-injection/index.d.ts +3 -1
  8. package/src/rules/detect-weak-password-validation/index.d.ts +3 -1
  9. package/src/rules/no-directive-injection/index.d.ts +3 -1
  10. package/src/rules/no-electron-security-issues/index.d.ts +3 -1
  11. package/src/rules/no-format-string-injection/index.d.ts +3 -1
  12. package/src/rules/no-graphql-injection/index.d.ts +3 -1
  13. package/src/rules/no-hardcoded-credentials/index.d.ts +3 -1
  14. package/src/rules/no-hardcoded-session-tokens/index.d.ts +3 -1
  15. package/src/rules/no-improper-sanitization/index.d.ts +3 -1
  16. package/src/rules/no-improper-type-validation/index.d.ts +3 -1
  17. package/src/rules/no-insecure-comparison/index.d.ts +3 -1
  18. package/src/rules/no-ldap-injection/index.d.ts +3 -1
  19. package/src/rules/no-missing-authentication/index.d.ts +3 -1
  20. package/src/rules/no-missing-authentication/index.js +0 -1
  21. package/src/rules/no-pii-in-logs/index.d.ts +3 -1
  22. package/src/rules/no-privilege-escalation/index.d.ts +3 -1
  23. package/src/rules/no-redos-vulnerable-regex/index.d.ts +3 -1
  24. package/src/rules/no-sensitive-data-exposure/index.d.ts +3 -1
  25. package/src/rules/no-unchecked-loop-condition/index.d.ts +3 -1
  26. package/src/rules/no-unlimited-resource-allocation/index.d.ts +3 -1
  27. package/src/rules/no-unsafe-deserialization/index.d.ts +3 -1
  28. package/src/rules/no-unsafe-regex-construction/index.d.ts +3 -1
  29. package/src/rules/no-weak-password-recovery/index.d.ts +3 -1
  30. package/src/rules/no-xpath-injection/index.d.ts +3 -1
  31. package/src/rules/no-xxe-injection/index.d.ts +3 -1
  32. package/src/rules/require-backend-authorization/index.d.ts +3 -1
  33. package/src/rules/require-secure-defaults/index.d.ts +3 -1
  34. package/src/types/index.d.ts +5 -52
  35. package/src/rules/detect-child-process/index.d.ts +0 -28
  36. package/src/rules/detect-child-process/index.js +0 -534
  37. package/src/rules/detect-eval-with-expression/index.d.ts +0 -26
  38. package/src/rules/detect-eval-with-expression/index.js +0 -397
  39. package/src/rules/detect-mixed-content/index.d.ts +0 -10
  40. package/src/rules/detect-mixed-content/index.js +0 -45
  41. package/src/rules/detect-non-literal-fs-filename/index.d.ts +0 -24
  42. package/src/rules/detect-non-literal-fs-filename/index.js +0 -459
  43. package/src/rules/detect-suspicious-dependencies/index.d.ts +0 -10
  44. package/src/rules/detect-suspicious-dependencies/index.js +0 -76
  45. package/src/rules/no-allow-arbitrary-loads/index.d.ts +0 -10
  46. package/src/rules/no-allow-arbitrary-loads/index.js +0 -48
  47. package/src/rules/no-arbitrary-file-access/index.d.ts +0 -10
  48. package/src/rules/no-arbitrary-file-access/index.js +0 -200
  49. package/src/rules/no-buffer-overread/index.d.ts +0 -37
  50. package/src/rules/no-buffer-overread/index.js +0 -611
  51. package/src/rules/no-clickjacking/index.d.ts +0 -34
  52. package/src/rules/no-clickjacking/index.js +0 -401
  53. package/src/rules/no-client-side-auth-logic/index.d.ts +0 -10
  54. package/src/rules/no-client-side-auth-logic/index.js +0 -74
  55. package/src/rules/no-credentials-in-query-params/index.d.ts +0 -10
  56. package/src/rules/no-credentials-in-query-params/index.js +0 -62
  57. package/src/rules/no-data-in-temp-storage/index.d.ts +0 -10
  58. package/src/rules/no-data-in-temp-storage/index.js +0 -69
  59. package/src/rules/no-debug-code-in-production/index.d.ts +0 -10
  60. package/src/rules/no-debug-code-in-production/index.js +0 -54
  61. package/src/rules/no-disabled-certificate-validation/index.d.ts +0 -10
  62. package/src/rules/no-disabled-certificate-validation/index.js +0 -66
  63. package/src/rules/no-dynamic-dependency-loading/index.d.ts +0 -10
  64. package/src/rules/no-dynamic-dependency-loading/index.js +0 -54
  65. package/src/rules/no-exposed-debug-endpoints/index.d.ts +0 -10
  66. package/src/rules/no-exposed-debug-endpoints/index.js +0 -67
  67. package/src/rules/no-exposed-sensitive-data/index.d.ts +0 -28
  68. package/src/rules/no-exposed-sensitive-data/index.js +0 -345
  69. package/src/rules/no-http-urls/index.d.ts +0 -15
  70. package/src/rules/no-http-urls/index.js +0 -119
  71. package/src/rules/no-insecure-redirects/index.d.ts +0 -24
  72. package/src/rules/no-insecure-redirects/index.js +0 -221
  73. package/src/rules/no-insecure-websocket/index.d.ts +0 -10
  74. package/src/rules/no-insecure-websocket/index.js +0 -66
  75. package/src/rules/no-missing-cors-check/index.d.ts +0 -26
  76. package/src/rules/no-missing-cors-check/index.js +0 -404
  77. package/src/rules/no-missing-csrf-protection/index.d.ts +0 -28
  78. package/src/rules/no-missing-csrf-protection/index.js +0 -185
  79. package/src/rules/no-missing-security-headers/index.d.ts +0 -24
  80. package/src/rules/no-missing-security-headers/index.js +0 -223
  81. package/src/rules/no-password-in-url/index.d.ts +0 -10
  82. package/src/rules/no-password-in-url/index.js +0 -55
  83. package/src/rules/no-permissive-cors/index.d.ts +0 -10
  84. package/src/rules/no-permissive-cors/index.js +0 -74
  85. package/src/rules/no-sensitive-data-in-analytics/index.d.ts +0 -10
  86. package/src/rules/no-sensitive-data-in-analytics/index.js +0 -66
  87. package/src/rules/no-sensitive-data-in-cache/index.d.ts +0 -10
  88. package/src/rules/no-sensitive-data-in-cache/index.js +0 -53
  89. package/src/rules/no-toctou-vulnerability/index.d.ts +0 -24
  90. package/src/rules/no-toctou-vulnerability/index.js +0 -213
  91. package/src/rules/no-tracking-without-consent/index.d.ts +0 -10
  92. package/src/rules/no-tracking-without-consent/index.js +0 -72
  93. package/src/rules/no-unencrypted-transmission/index.d.ts +0 -28
  94. package/src/rules/no-unencrypted-transmission/index.js +0 -241
  95. package/src/rules/no-unescaped-url-parameter/index.d.ts +0 -26
  96. package/src/rules/no-unescaped-url-parameter/index.js +0 -360
  97. package/src/rules/no-unsafe-dynamic-require/index.d.ts +0 -17
  98. package/src/rules/no-unsafe-dynamic-require/index.js +0 -111
  99. package/src/rules/no-unvalidated-deeplinks/index.d.ts +0 -10
  100. package/src/rules/no-unvalidated-deeplinks/index.js +0 -67
  101. package/src/rules/no-unvalidated-user-input/index.d.ts +0 -26
  102. package/src/rules/no-unvalidated-user-input/index.js +0 -425
  103. package/src/rules/no-verbose-error-messages/index.d.ts +0 -10
  104. package/src/rules/no-verbose-error-messages/index.js +0 -73
  105. package/src/rules/no-zip-slip/index.d.ts +0 -33
  106. package/src/rules/no-zip-slip/index.js +0 -450
  107. package/src/rules/require-code-minification/index.d.ts +0 -10
  108. package/src/rules/require-code-minification/index.js +0 -48
  109. package/src/rules/require-csp-headers/index.d.ts +0 -10
  110. package/src/rules/require-csp-headers/index.js +0 -69
  111. package/src/rules/require-data-minimization/index.d.ts +0 -10
  112. package/src/rules/require-data-minimization/index.js +0 -55
  113. package/src/rules/require-dependency-integrity/index.d.ts +0 -10
  114. package/src/rules/require-dependency-integrity/index.js +0 -69
  115. package/src/rules/require-https-only/index.d.ts +0 -10
  116. package/src/rules/require-https-only/index.js +0 -67
  117. package/src/rules/require-mime-type-validation/index.d.ts +0 -10
  118. package/src/rules/require-mime-type-validation/index.js +0 -71
  119. package/src/rules/require-network-timeout/index.d.ts +0 -10
  120. package/src/rules/require-network-timeout/index.js +0 -57
  121. package/src/rules/require-package-lock/index.d.ts +0 -10
  122. package/src/rules/require-package-lock/index.js +0 -64
  123. package/src/rules/require-secure-credential-storage/index.d.ts +0 -10
  124. package/src/rules/require-secure-credential-storage/index.js +0 -53
  125. package/src/rules/require-secure-deletion/index.d.ts +0 -10
  126. package/src/rules/require-secure-deletion/index.js +0 -45
  127. package/src/rules/require-storage-encryption/index.d.ts +0 -10
  128. package/src/rules/require-storage-encryption/index.js +0 -53
  129. package/src/rules/require-url-validation/index.d.ts +0 -10
  130. package/src/rules/require-url-validation/index.js +0 -77
@@ -1,213 +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.noToctouVulnerability = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- exports.noToctouVulnerability = (0, eslint_devkit_2.createRule)({
12
- name: 'no-toctou-vulnerability',
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Detects Time-of-Check-Time-of-Use vulnerabilities',
17
- },
18
- hasSuggestions: true,
19
- messages: {
20
- toctouVulnerability: (0, eslint_devkit_1.formatLLMMessage)({
21
- icon: eslint_devkit_1.MessageIcons.SECURITY,
22
- issueName: 'TOCTOU vulnerability',
23
- cwe: 'CWE-367',
24
- description: 'Time-of-check Time-of-use race condition detected',
25
- severity: 'HIGH',
26
- fix: 'Use atomic operations or fs.promises for file operations',
27
- documentationLink: 'https://cwe.mitre.org/data/definitions/367.html',
28
- }),
29
- useAtomicOperations: (0, eslint_devkit_1.formatLLMMessage)({
30
- icon: eslint_devkit_1.MessageIcons.INFO,
31
- issueName: 'Use Atomic Operations',
32
- description: 'Use atomic file operations',
33
- severity: 'LOW',
34
- fix: 'fs.promises.access() then fs.promises.readFile()',
35
- documentationLink: 'https://nodejs.org/api/fs.html#fspromisesaccesspath-mode',
36
- }),
37
- useFsPromises: (0, eslint_devkit_1.formatLLMMessage)({
38
- icon: eslint_devkit_1.MessageIcons.INFO,
39
- issueName: 'Use fs.promises',
40
- description: 'Use fs.promises API',
41
- severity: 'LOW',
42
- fix: 'await fs.promises.readFile() instead of sync operations',
43
- documentationLink: 'https://nodejs.org/api/fs.html#promises-api',
44
- }),
45
- addProperLocking: (0, eslint_devkit_1.formatLLMMessage)({
46
- icon: eslint_devkit_1.MessageIcons.INFO,
47
- issueName: 'Add File Locking',
48
- description: 'Add proper locking mechanism',
49
- severity: 'LOW',
50
- fix: 'Use proper-lockfile or similar for concurrent access',
51
- documentationLink: 'https://github.com/moxystudio/node-proper-lockfile',
52
- }),
53
- },
54
- schema: [
55
- {
56
- type: 'object',
57
- properties: {
58
- ignoreInTests: {
59
- type: 'boolean',
60
- default: true,
61
- },
62
- fsMethods: {
63
- type: 'array',
64
- items: { type: 'string' },
65
- default: ['fs.existsSync', 'fs.statSync', 'fs.accessSync'],
66
- },
67
- },
68
- additionalProperties: false,
69
- },
70
- ],
71
- },
72
- defaultOptions: [
73
- {
74
- ignoreInTests: true,
75
- fsMethods: ['fs.existsSync', 'fs.statSync', 'fs.accessSync'],
76
- },
77
- ],
78
- create(context, [options = {}]) {
79
- const { ignoreInTests = true } = options || {};
80
- const filename = context.getFilename();
81
- const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
82
- if (isTestFile) {
83
- return {};
84
- }
85
- const sourceCode = context.sourceCode || context.sourceCode;
86
- /**
87
- * Check for TOCTOU patterns
88
- */
89
- function checkCallExpression(node) {
90
- // 1. Identify the file operation (Use)
91
- let useMethodName = '';
92
- if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier') {
93
- const objectName = node.callee.object.type === 'Identifier' ? node.callee.object.name : '';
94
- if (objectName === 'fs' || objectName === 'fsPromises') {
95
- useMethodName = node.callee.property.name;
96
- }
97
- }
98
- else if (node.callee.type === 'Identifier') {
99
- useMethodName = node.callee.name;
100
- }
101
- const riskyUseMethods = ['readFileSync', 'writeFileSync', 'readFile', 'writeFile', 'openSync', 'open', 'unlinkSync', 'unlink'];
102
- if (!riskyUseMethods.includes(useMethodName)) {
103
- return;
104
- }
105
- const useArg = node.arguments[0];
106
- if (!useArg)
107
- return;
108
- // 2. Walk up to find the condition (Check)
109
- let current = node.parent;
110
- while (current) {
111
- if (current.type === 'IfStatement') {
112
- // Extract the condition node
113
- let condition = current.test;
114
- // Handle negated condition: if (!exists(path)) { create(path) } -> also TOCTOU but different logic?
115
- // Actually TOCTOU is usually Check(exists) -> Use(read).
116
- // If (!exists) -> create is Check -> Use.
117
- // But strict TOCTOU is checking state then acting.
118
- // If checking for negation
119
- if (condition.type === 'UnaryExpression' && condition.operator === '!') {
120
- condition = condition.argument;
121
- }
122
- if (condition.type === 'CallExpression') {
123
- // Check if it's a file check method
124
- let checkMethodName = '';
125
- if (condition.callee.type === 'MemberExpression' && condition.callee.property.type === 'Identifier') {
126
- checkMethodName = condition.callee.property.name;
127
- }
128
- else if (condition.callee.type === 'Identifier') {
129
- checkMethodName = condition.callee.name;
130
- }
131
- const checkMethods = ['existsSync', 'statSync', 'accessSync', 'exists', 'stat', 'access'];
132
- if (checkMethods.includes(checkMethodName)) {
133
- // Compare arguments
134
- const checkArg = condition.arguments[0];
135
- if (checkArg) {
136
- // Method 1: Identifier match (same variable)
137
- if (checkArg.type === 'Identifier' && useArg.type === 'Identifier' && checkArg.name === useArg.name) {
138
- reportToctou(node);
139
- return;
140
- }
141
- // Method 2: Text match (fallback)
142
- const checkArgText = sourceCode.getText(checkArg).replace(/\s/g, '');
143
- const useArgText = sourceCode.getText(useArg).replace(/\s/g, '');
144
- if (checkArgText === useArgText) {
145
- reportToctou(node);
146
- return;
147
- }
148
- }
149
- }
150
- // Handle stats.isFile() / stats.isDirectory() pattern
151
- if (condition.callee.type === 'MemberExpression' &&
152
- condition.callee.property.type === 'Identifier' &&
153
- ['isFile', 'isDirectory'].includes(condition.callee.property.name) &&
154
- condition.callee.object.type === 'Identifier') {
155
- const statsVarName = condition.callee.object.name;
156
- let currentScope = sourceCode.getScope(condition);
157
- let variable = null;
158
- while (currentScope) {
159
- variable = currentScope.variables.find(v => v.name === statsVarName);
160
- if (variable)
161
- break;
162
- currentScope = currentScope.upper;
163
- }
164
- if (variable && variable.defs.length > 0) {
165
- const def = variable.defs[0];
166
- if (def.type === 'Variable' && def.node.init && def.node.init.type === 'CallExpression') {
167
- const init = def.node.init;
168
- if (init.callee.type === 'MemberExpression' &&
169
- init.callee.property.type === 'Identifier' &&
170
- ['statSync', 'lstatSync', 'stat', 'lstat'].includes(init.callee.property.name)) {
171
- const statArg = init.arguments[0];
172
- if (statArg) {
173
- const checkArgText = sourceCode.getText(statArg).replace(/\s/g, '');
174
- const useArgText = sourceCode.getText(useArg).replace(/\s/g, '');
175
- if (checkArgText === useArgText) {
176
- reportToctou(node);
177
- return;
178
- }
179
- }
180
- }
181
- }
182
- }
183
- }
184
- }
185
- }
186
- current = current.parent;
187
- }
188
- }
189
- function reportToctou(node) {
190
- context.report({
191
- node,
192
- messageId: 'toctouVulnerability',
193
- suggest: [
194
- {
195
- messageId: 'useAtomicOperations',
196
- fix: () => null,
197
- },
198
- {
199
- messageId: 'useFsPromises',
200
- fix: () => null,
201
- },
202
- {
203
- messageId: 'addProperLocking',
204
- fix: () => null,
205
- },
206
- ],
207
- });
208
- }
209
- return {
210
- CallExpression: checkCallExpression,
211
- };
212
- },
213
- });
@@ -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 noTrackingWithoutConsent: import("@typescript-eslint/utils/ts-eslint").RuleModule<"violationDetected", RuleOptions, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
10
- export {};
@@ -1,72 +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.noTrackingWithoutConsent = void 0;
9
- /**
10
- * @fileoverview Require consent before tracking
11
- */
12
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
- exports.noTrackingWithoutConsent = (0, eslint_devkit_1.createRule)({
14
- name: 'no-tracking-without-consent',
15
- meta: {
16
- type: 'problem',
17
- docs: {
18
- description: 'Require consent before analytics tracking',
19
- },
20
- messages: {
21
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
22
- icon: eslint_devkit_1.MessageIcons.SECURITY,
23
- issueName: 'Tracking Without Consent',
24
- cwe: 'CWE-359',
25
- description: 'Analytics tracking without consent check - violates privacy regulations',
26
- severity: 'MEDIUM',
27
- fix: 'Wrap tracking calls in consent check: if (hasConsent) { analytics.track(...) }',
28
- documentationLink: 'https://cwe.mitre.org/data/definitions/359.html',
29
- })
30
- },
31
- schema: [],
32
- },
33
- defaultOptions: [],
34
- create(context) {
35
- function report(node) {
36
- context.report({ node, messageId: 'violationDetected' });
37
- }
38
- function isInsideConsentCheck(node) {
39
- let current = node.parent;
40
- while (current) {
41
- if (current.type === 'IfStatement') {
42
- return true;
43
- }
44
- if (current.type === 'ConditionalExpression') {
45
- return true;
46
- }
47
- current = current.parent;
48
- }
49
- return false;
50
- }
51
- return {
52
- CallExpression(node) {
53
- // Detect analytics.track() or similar
54
- if (node.callee.type === 'MemberExpression' &&
55
- node.callee.object.type === 'Identifier' &&
56
- node.callee.object.name === 'analytics' &&
57
- node.callee.property.type === 'Identifier' &&
58
- ['track', 'identify', 'page'].includes(node.callee.property.name)) {
59
- if (!isInsideConsentCheck(node)) {
60
- report(node);
61
- }
62
- }
63
- // Google Analytics gtag
64
- if (node.callee.type === 'Identifier' && node.callee.name === 'gtag') {
65
- if (!isInsideConsentCheck(node)) {
66
- report(node);
67
- }
68
- }
69
- },
70
- };
71
- },
72
- });
@@ -1,28 +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
- /**
7
- * ESLint Rule: no-unencrypted-transmission
8
- * Detects unencrypted data transmission (HTTP vs HTTPS, plain text protocols)
9
- * CWE-319: Cleartext Transmission of Sensitive Information
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/319.html
12
- * @see https://owasp.org/www-community/vulnerabilities/Insecure_Transport
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'unencryptedTransmission' | 'useHttps';
16
- export interface Options {
17
- /** Allow unencrypted transmission in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** Insecure protocol patterns. Default: ['http://', 'ws://', 'ftp://', 'tcp://', 'mongodb://', 'redis://', 'mysql://'] */
20
- insecureProtocols?: string[];
21
- /** Secure protocol alternatives mapping. Default: { 'http://': 'https://', 'ws://': 'wss://', ... } */
22
- secureAlternatives?: Record<string, string>;
23
- /** Additional safe patterns to ignore. Default: [] */
24
- ignorePatterns?: string[];
25
- }
26
- type RuleOptions = [Options?];
27
- export declare const noUnencryptedTransmission: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
28
- export {};
@@ -1,241 +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.noUnencryptedTransmission = void 0;
9
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Default insecure protocol patterns
13
- */
14
- const DEFAULT_INSECURE_PROTOCOLS = [
15
- 'http://',
16
- 'ws://',
17
- 'ftp://',
18
- 'tcp://',
19
- 'mongodb://',
20
- 'redis://',
21
- 'mysql://',
22
- ];
23
- /**
24
- * Secure protocol alternatives
25
- */
26
- const SECURE_ALTERNATIVES = {
27
- 'http://': 'https://',
28
- 'ws://': 'wss://',
29
- 'ftp://': 'ftps://',
30
- 'tcp://': 'tls://',
31
- 'mongodb://': 'mongodb+srv://',
32
- 'redis://': 'rediss://',
33
- 'mysql://': 'mysqls://',
34
- };
35
- /**
36
- * Check if a string contains insecure protocol
37
- */
38
- function containsInsecureProtocol(value, insecureProtocols, secureAlternatives) {
39
- const lowerValue = value.toLowerCase();
40
- for (const protocol of insecureProtocols) {
41
- const lowerProtocol = protocol.toLowerCase();
42
- // Check if the protocol appears in the value (as a URL scheme)
43
- if (lowerValue.includes(lowerProtocol)) {
44
- // Check if it's not already using the secure version
45
- const secureAlternative = secureAlternatives[lowerProtocol];
46
- if (secureAlternative) {
47
- // Only report if secure version is not present
48
- if (!lowerValue.includes(secureAlternative.toLowerCase())) {
49
- return { isInsecure: true, protocol };
50
- }
51
- }
52
- else {
53
- // No secure alternative defined, so it's insecure
54
- return { isInsecure: true, protocol };
55
- }
56
- }
57
- }
58
- return { isInsecure: false, protocol: '' };
59
- }
60
- /**
61
- * Check if a string matches any ignore pattern
62
- */
63
- /* c8 ignore start -- ignore-pattern matching is defensive */
64
- function matchesIgnorePattern(text, patterns) {
65
- return patterns.some(pattern => {
66
- try {
67
- const regex = new RegExp(pattern, 'i');
68
- return regex.test(text);
69
- }
70
- catch {
71
- return false;
72
- }
73
- });
74
- }
75
- /* c8 ignore stop */
76
- exports.noUnencryptedTransmission = (0, eslint_devkit_2.createRule)({
77
- name: 'no-unencrypted-transmission',
78
- meta: {
79
- type: 'problem',
80
- docs: {
81
- description: 'Detects unencrypted data transmission (HTTP vs HTTPS, plain text protocols)',
82
- },
83
- hasSuggestions: true,
84
- messages: {
85
- unencryptedTransmission: (0, eslint_devkit_1.formatLLMMessage)({
86
- icon: eslint_devkit_1.MessageIcons.SECURITY,
87
- issueName: 'Unencrypted Transmission',
88
- cwe: 'CWE-319',
89
- description: 'Unencrypted transmission detected: {{issue}}',
90
- severity: 'HIGH',
91
- fix: '{{safeAlternative}}',
92
- documentationLink: 'https://cwe.mitre.org/data/definitions/319.html',
93
- }),
94
- useHttps: (0, eslint_devkit_1.formatLLMMessage)({
95
- icon: eslint_devkit_1.MessageIcons.INFO,
96
- issueName: 'Use HTTPS',
97
- description: 'Use secure protocol',
98
- severity: 'LOW',
99
- fix: 'Replace http:// with https://',
100
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/Security/Transport_Layer_Security',
101
- }),
102
- },
103
- schema: [
104
- {
105
- type: 'object',
106
- properties: {
107
- allowInTests: {
108
- type: 'boolean',
109
- default: false,
110
- description: 'Allow unencrypted transmission in test files',
111
- },
112
- insecureProtocols: {
113
- type: 'array',
114
- items: { type: 'string' },
115
- default: [],
116
- description: 'Insecure protocol patterns to detect',
117
- },
118
- secureAlternatives: {
119
- type: 'object',
120
- additionalProperties: { type: 'string' },
121
- default: {},
122
- description: 'Mapping of insecure protocols to their secure alternatives',
123
- },
124
- ignorePatterns: {
125
- type: 'array',
126
- items: { type: 'string' },
127
- default: [],
128
- description: 'Additional safe patterns to ignore',
129
- },
130
- },
131
- additionalProperties: false,
132
- },
133
- ],
134
- },
135
- defaultOptions: [
136
- {
137
- allowInTests: false,
138
- insecureProtocols: [],
139
- secureAlternatives: {},
140
- ignorePatterns: [],
141
- },
142
- ],
143
- create(context, [options = {}]) {
144
- const { allowInTests = false, insecureProtocols, secureAlternatives, ignorePatterns = [], } = options;
145
- const protocolsToCheck = insecureProtocols && insecureProtocols.length > 0
146
- ? insecureProtocols
147
- : DEFAULT_INSECURE_PROTOCOLS;
148
- // Merge user-provided secure alternatives with defaults
149
- const secureAlternativesToUse = secureAlternatives && Object.keys(secureAlternatives).length > 0
150
- ? { ...SECURE_ALTERNATIVES, ...secureAlternatives }
151
- : SECURE_ALTERNATIVES;
152
- const filename = context.getFilename();
153
- const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
154
- const sourceCode = context.sourceCode || context.sourceCode;
155
- function checkLiteral(node) {
156
- if (typeof node.value !== 'string') {
157
- return;
158
- }
159
- const value = node.value;
160
- const text = sourceCode.getText(node);
161
- // Check if it matches any ignore pattern
162
- if (matchesIgnorePattern(text, ignorePatterns)) {
163
- return;
164
- }
165
- // Skip test files (allow localhost in test files)
166
- if (isTestFile) {
167
- // Only allow localhost URLs in test files
168
- if (text.includes('localhost')) {
169
- return;
170
- }
171
- // For other URLs in test files, still check them
172
- }
173
- const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
174
- if (isInsecure) {
175
- // Allow localhost URLs in test files
176
- if (isTestFile && text.includes('localhost')) {
177
- return;
178
- }
179
- const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
180
- const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
181
- context.report({
182
- node,
183
- messageId: 'unencryptedTransmission',
184
- data: {
185
- issue: `using insecure protocol ${protocol}`,
186
- safeAlternative,
187
- },
188
- suggest: [
189
- {
190
- messageId: 'useHttps',
191
- data: {
192
- protocol,
193
- secureProtocol,
194
- },
195
- fix(fixer) {
196
- if (secureProtocol && secureProtocol !== 'secure protocol') {
197
- // Replace the insecure protocol with secure one
198
- const newValue = value.replace(new RegExp(protocol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), secureProtocol);
199
- return fixer.replaceText(node, JSON.stringify(newValue));
200
- }
201
- return null;
202
- },
203
- },
204
- ],
205
- });
206
- }
207
- }
208
- function checkTemplateLiteral(node) {
209
- if (isTestFile) {
210
- return;
211
- }
212
- const text = sourceCode.getText(node);
213
- // Check if it matches any ignore pattern
214
- if (matchesIgnorePattern(text, ignorePatterns)) {
215
- return;
216
- }
217
- // Check each quasis (static parts) and expressions
218
- for (const quasi of node.quasis) {
219
- const value = quasi.value.raw;
220
- const { isInsecure, protocol } = containsInsecureProtocol(value, protocolsToCheck, secureAlternativesToUse);
221
- if (isInsecure) {
222
- const secureProtocol = secureAlternativesToUse[protocol.toLowerCase()] || 'secure protocol';
223
- const safeAlternative = `Use ${secureProtocol} instead of ${protocol}`;
224
- context.report({
225
- node: quasi,
226
- messageId: 'unencryptedTransmission',
227
- data: {
228
- issue: `using insecure protocol ${protocol} in template literal`,
229
- safeAlternative,
230
- },
231
- // Don't provide auto-fix for template literals (too risky - might break interpolation)
232
- });
233
- }
234
- }
235
- }
236
- return {
237
- Literal: checkLiteral,
238
- TemplateLiteral: checkTemplateLiteral,
239
- };
240
- },
241
- });
@@ -1,26 +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
- /**
7
- * ESLint Rule: no-unescaped-url-parameter
8
- * Detects unescaped URL parameters
9
- * CWE-79: Cross-site Scripting (XSS)
10
- *
11
- * @see https://cwe.mitre.org/data/definitions/79.html
12
- * @see https://owasp.org/www-community/attacks/xss/
13
- */
14
- import type { TSESLint } from '@interlace/eslint-devkit';
15
- type MessageIds = 'unescapedUrlParameter' | 'useEncodeURIComponent' | 'useURLSearchParams';
16
- export interface Options {
17
- /** Allow unescaped URL parameters in test files. Default: false */
18
- allowInTests?: boolean;
19
- /** Trusted URL construction libraries. Default: ['url', 'querystring'] */
20
- trustedLibraries?: string[];
21
- /** Additional safe patterns to ignore. Default: [] */
22
- ignorePatterns?: string[];
23
- }
24
- type RuleOptions = [Options?];
25
- export declare const noUnescapedUrlParameter: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener>;
26
- export {};