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