eslint-plugin-secure-coding 1.0.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.
- package/AGENTS.md +196 -0
- package/CHANGELOG.md +105 -0
- package/LICENSE +23 -0
- package/README.md +377 -0
- package/package.json +80 -0
- package/src/index.d.ts +32 -0
- package/src/index.js +345 -0
- package/src/index.js.map +1 -0
- package/src/rules/security/database-injection.d.ts +13 -0
- package/src/rules/security/database-injection.js +407 -0
- package/src/rules/security/database-injection.js.map +1 -0
- package/src/rules/security/detect-child-process.d.ts +11 -0
- package/src/rules/security/detect-child-process.js +460 -0
- package/src/rules/security/detect-child-process.js.map +1 -0
- package/src/rules/security/detect-eval-with-expression.d.ts +9 -0
- package/src/rules/security/detect-eval-with-expression.js +393 -0
- package/src/rules/security/detect-eval-with-expression.js.map +1 -0
- package/src/rules/security/detect-non-literal-fs-filename.d.ts +7 -0
- package/src/rules/security/detect-non-literal-fs-filename.js +322 -0
- package/src/rules/security/detect-non-literal-fs-filename.js.map +1 -0
- package/src/rules/security/detect-non-literal-regexp.d.ts +9 -0
- package/src/rules/security/detect-non-literal-regexp.js +387 -0
- package/src/rules/security/detect-non-literal-regexp.js.map +1 -0
- package/src/rules/security/detect-object-injection.d.ts +11 -0
- package/src/rules/security/detect-object-injection.js +411 -0
- package/src/rules/security/detect-object-injection.js.map +1 -0
- package/src/rules/security/no-buffer-overread.d.ts +14 -0
- package/src/rules/security/no-buffer-overread.js +519 -0
- package/src/rules/security/no-buffer-overread.js.map +1 -0
- package/src/rules/security/no-clickjacking.d.ts +10 -0
- package/src/rules/security/no-clickjacking.js +381 -0
- package/src/rules/security/no-clickjacking.js.map +1 -0
- package/src/rules/security/no-directive-injection.d.ts +12 -0
- package/src/rules/security/no-directive-injection.js +446 -0
- package/src/rules/security/no-directive-injection.js.map +1 -0
- package/src/rules/security/no-document-cookie.d.ts +5 -0
- package/src/rules/security/no-document-cookie.js +90 -0
- package/src/rules/security/no-document-cookie.js.map +1 -0
- package/src/rules/security/no-electron-security-issues.d.ts +10 -0
- package/src/rules/security/no-electron-security-issues.js +421 -0
- package/src/rules/security/no-electron-security-issues.js.map +1 -0
- package/src/rules/security/no-exposed-sensitive-data.d.ts +11 -0
- package/src/rules/security/no-exposed-sensitive-data.js +341 -0
- package/src/rules/security/no-exposed-sensitive-data.js.map +1 -0
- package/src/rules/security/no-format-string-injection.d.ts +17 -0
- package/src/rules/security/no-format-string-injection.js +653 -0
- package/src/rules/security/no-format-string-injection.js.map +1 -0
- package/src/rules/security/no-graphql-injection.d.ts +12 -0
- package/src/rules/security/no-graphql-injection.js +410 -0
- package/src/rules/security/no-graphql-injection.js.map +1 -0
- package/src/rules/security/no-hardcoded-credentials.d.ts +26 -0
- package/src/rules/security/no-hardcoded-credentials.js +377 -0
- package/src/rules/security/no-hardcoded-credentials.js.map +1 -0
- package/src/rules/security/no-improper-sanitization.d.ts +12 -0
- package/src/rules/security/no-improper-sanitization.js +408 -0
- package/src/rules/security/no-improper-sanitization.js.map +1 -0
- package/src/rules/security/no-improper-type-validation.d.ts +10 -0
- package/src/rules/security/no-improper-type-validation.js +420 -0
- package/src/rules/security/no-improper-type-validation.js.map +1 -0
- package/src/rules/security/no-insecure-comparison.d.ts +7 -0
- package/src/rules/security/no-insecure-comparison.js +125 -0
- package/src/rules/security/no-insecure-comparison.js.map +1 -0
- package/src/rules/security/no-insecure-cookie-settings.d.ts +9 -0
- package/src/rules/security/no-insecure-cookie-settings.js +305 -0
- package/src/rules/security/no-insecure-cookie-settings.js.map +1 -0
- package/src/rules/security/no-insecure-jwt.d.ts +10 -0
- package/src/rules/security/no-insecure-jwt.js +338 -0
- package/src/rules/security/no-insecure-jwt.js.map +1 -0
- package/src/rules/security/no-insecure-redirects.d.ts +7 -0
- package/src/rules/security/no-insecure-redirects.js +215 -0
- package/src/rules/security/no-insecure-redirects.js.map +1 -0
- package/src/rules/security/no-insufficient-postmessage-validation.d.ts +14 -0
- package/src/rules/security/no-insufficient-postmessage-validation.js +390 -0
- package/src/rules/security/no-insufficient-postmessage-validation.js.map +1 -0
- package/src/rules/security/no-insufficient-random.d.ts +9 -0
- package/src/rules/security/no-insufficient-random.js +207 -0
- package/src/rules/security/no-insufficient-random.js.map +1 -0
- package/src/rules/security/no-ldap-injection.d.ts +10 -0
- package/src/rules/security/no-ldap-injection.js +449 -0
- package/src/rules/security/no-ldap-injection.js.map +1 -0
- package/src/rules/security/no-missing-authentication.d.ts +13 -0
- package/src/rules/security/no-missing-authentication.js +322 -0
- package/src/rules/security/no-missing-authentication.js.map +1 -0
- package/src/rules/security/no-missing-cors-check.d.ts +9 -0
- package/src/rules/security/no-missing-cors-check.js +449 -0
- package/src/rules/security/no-missing-cors-check.js.map +1 -0
- package/src/rules/security/no-missing-csrf-protection.d.ts +11 -0
- package/src/rules/security/no-missing-csrf-protection.js +183 -0
- package/src/rules/security/no-missing-csrf-protection.js.map +1 -0
- package/src/rules/security/no-missing-security-headers.d.ts +7 -0
- package/src/rules/security/no-missing-security-headers.js +217 -0
- package/src/rules/security/no-missing-security-headers.js.map +1 -0
- package/src/rules/security/no-privilege-escalation.d.ts +13 -0
- package/src/rules/security/no-privilege-escalation.js +321 -0
- package/src/rules/security/no-privilege-escalation.js.map +1 -0
- package/src/rules/security/no-redos-vulnerable-regex.d.ts +7 -0
- package/src/rules/security/no-redos-vulnerable-regex.js +307 -0
- package/src/rules/security/no-redos-vulnerable-regex.js.map +1 -0
- package/src/rules/security/no-sensitive-data-exposure.d.ts +11 -0
- package/src/rules/security/no-sensitive-data-exposure.js +251 -0
- package/src/rules/security/no-sensitive-data-exposure.js.map +1 -0
- package/src/rules/security/no-sql-injection.d.ts +10 -0
- package/src/rules/security/no-sql-injection.js +332 -0
- package/src/rules/security/no-sql-injection.js.map +1 -0
- package/src/rules/security/no-timing-attack.d.ts +10 -0
- package/src/rules/security/no-timing-attack.js +358 -0
- package/src/rules/security/no-timing-attack.js.map +1 -0
- package/src/rules/security/no-toctou-vulnerability.d.ts +7 -0
- package/src/rules/security/no-toctou-vulnerability.js +165 -0
- package/src/rules/security/no-toctou-vulnerability.js.map +1 -0
- package/src/rules/security/no-unchecked-loop-condition.d.ts +12 -0
- package/src/rules/security/no-unchecked-loop-condition.js +635 -0
- package/src/rules/security/no-unchecked-loop-condition.js.map +1 -0
- package/src/rules/security/no-unencrypted-transmission.d.ts +11 -0
- package/src/rules/security/no-unencrypted-transmission.js +237 -0
- package/src/rules/security/no-unencrypted-transmission.js.map +1 -0
- package/src/rules/security/no-unescaped-url-parameter.d.ts +9 -0
- package/src/rules/security/no-unescaped-url-parameter.js +266 -0
- package/src/rules/security/no-unescaped-url-parameter.js.map +1 -0
- package/src/rules/security/no-unlimited-resource-allocation.d.ts +12 -0
- package/src/rules/security/no-unlimited-resource-allocation.js +659 -0
- package/src/rules/security/no-unlimited-resource-allocation.js.map +1 -0
- package/src/rules/security/no-unsafe-deserialization.d.ts +10 -0
- package/src/rules/security/no-unsafe-deserialization.js +501 -0
- package/src/rules/security/no-unsafe-deserialization.js.map +1 -0
- package/src/rules/security/no-unsafe-dynamic-require.d.ts +5 -0
- package/src/rules/security/no-unsafe-dynamic-require.js +107 -0
- package/src/rules/security/no-unsafe-dynamic-require.js.map +1 -0
- package/src/rules/security/no-unsafe-regex-construction.d.ts +9 -0
- package/src/rules/security/no-unsafe-regex-construction.js +292 -0
- package/src/rules/security/no-unsafe-regex-construction.js.map +1 -0
- package/src/rules/security/no-unsanitized-html.d.ts +9 -0
- package/src/rules/security/no-unsanitized-html.js +347 -0
- package/src/rules/security/no-unsanitized-html.js.map +1 -0
- package/src/rules/security/no-unvalidated-user-input.d.ts +9 -0
- package/src/rules/security/no-unvalidated-user-input.js +418 -0
- package/src/rules/security/no-unvalidated-user-input.js.map +1 -0
- package/src/rules/security/no-weak-crypto.d.ts +11 -0
- package/src/rules/security/no-weak-crypto.js +350 -0
- package/src/rules/security/no-weak-crypto.js.map +1 -0
- package/src/rules/security/no-weak-password-recovery.d.ts +12 -0
- package/src/rules/security/no-weak-password-recovery.js +401 -0
- package/src/rules/security/no-weak-password-recovery.js.map +1 -0
- package/src/rules/security/no-xpath-injection.d.ts +10 -0
- package/src/rules/security/no-xpath-injection.js +487 -0
- package/src/rules/security/no-xpath-injection.js.map +1 -0
- package/src/rules/security/no-xxe-injection.d.ts +7 -0
- package/src/rules/security/no-xxe-injection.js +270 -0
- package/src/rules/security/no-xxe-injection.js.map +1 -0
- package/src/rules/security/no-zip-slip.d.ts +9 -0
- package/src/rules/security/no-zip-slip.js +446 -0
- package/src/rules/security/no-zip-slip.js.map +1 -0
- package/src/types/index.d.ts +131 -0
- package/src/types/index.js +18 -0
- package/src/types/index.js.map +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
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>;
|
|
@@ -0,0 +1,237 @@
|
|
|
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
|
+
});
|
|
237
|
+
//# sourceMappingURL=no-unencrypted-transmission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-unencrypted-transmission.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-secure-coding/src/rules/security/no-unencrypted-transmission.ts"],"names":[],"mappings":";;;AASA,4DAA0E;AAC1E,4DAAsD;AAoBtD;;GAEG;AACH,MAAM,0BAA0B,GAAG;IACjC,SAAS;IACT,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,UAAU;IACV,UAAU;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAA2B;IAClD,SAAS,EAAE,UAAU;IACrB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,QAAQ;IAClB,YAAY,EAAE,gBAAgB;IAC9B,UAAU,EAAE,WAAW;IACvB,UAAU,EAAE,WAAW;CACxB,CAAC;AAEF;;GAEG;AACH,SAAS,wBAAwB,CAC/B,KAAa,EACb,iBAA2B,EAC3B,kBAA0C;IAE1C,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAEvC,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;QACzC,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC7C,+DAA+D;QAC/D,IAAI,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;YACvC,qDAAqD;YACrD,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;YAC5D,IAAI,iBAAiB,EAAE,CAAC;gBACtB,+CAA+C;gBAC/C,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;oBAC1D,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBACxC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,kDAAkD;gBAClD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU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AAE,CAAC,IAAI,iBAAiB,CAAC;oBAC5F,MAAM,eAAe,GAAG,OAAO,cAAc,eAAe,QAAQ,EAAE,CAAC;oBAEvE,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,KAAK;wBACX,SAAS,EAAE,yBAAyB;wBACpC,IAAI,EAAE;4BACJ,KAAK,EAAE,2BAA2B,QAAQ,sBAAsB;4BAChE,eAAe;yBAChB;wBACD,uFAAuF;qBACxF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,YAAY;YACrB,eAAe,EAAE,oBAAoB;SACtC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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>;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noUnescapedUrlParameter = void 0;
|
|
4
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
+
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
+
/**
|
|
7
|
+
* Check if a node is inside a URL encoding function call
|
|
8
|
+
*/
|
|
9
|
+
function isInsideEncodingCall(node, sourceCode, trustedLibraries) {
|
|
10
|
+
let current = node;
|
|
11
|
+
while (current) {
|
|
12
|
+
if (current.type === 'CallExpression') {
|
|
13
|
+
const callee = current.callee;
|
|
14
|
+
// Check for encodeURIComponent, encodeURI
|
|
15
|
+
if (callee.type === 'Identifier') {
|
|
16
|
+
const calleeName = callee.name;
|
|
17
|
+
if (['encodeURIComponent', 'encodeURI', 'escape'].includes(calleeName)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Check if it's a trusted library call
|
|
22
|
+
if (callee.type === 'MemberExpression') {
|
|
23
|
+
const object = callee.object;
|
|
24
|
+
if (object.type === 'Identifier') {
|
|
25
|
+
const objectName = object.name.toLowerCase();
|
|
26
|
+
if (trustedLibraries.some(lib => objectName.includes(lib.toLowerCase()))) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Traverse up the AST
|
|
33
|
+
if ('parent' in current && current.parent) {
|
|
34
|
+
current = current.parent;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a string matches any ignore pattern
|
|
44
|
+
*/
|
|
45
|
+
function matchesIgnorePattern(text, ignorePatterns) {
|
|
46
|
+
return ignorePatterns.some(pattern => {
|
|
47
|
+
try {
|
|
48
|
+
const regex = new RegExp(pattern, 'i');
|
|
49
|
+
return regex.test(text);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if a node is a URL construction pattern
|
|
58
|
+
*/
|
|
59
|
+
function isUrlConstruction(node, sourceCode) {
|
|
60
|
+
const text = sourceCode.getText(node);
|
|
61
|
+
// Check for URL construction patterns
|
|
62
|
+
const urlPatterns = [
|
|
63
|
+
/\bhttps?:\/\//, // HTTP/HTTPS URLs
|
|
64
|
+
/\bnew\s+URL\s*\(/,
|
|
65
|
+
/\burl\s*[=:]\s*/, // url = or url:
|
|
66
|
+
/\burl\s*\+/, // url +
|
|
67
|
+
/\bwindow\.location/,
|
|
68
|
+
/\blocation\.href/,
|
|
69
|
+
/\bwindow\.open\s*\(/,
|
|
70
|
+
/\?[^=]+=/, // Query parameters
|
|
71
|
+
];
|
|
72
|
+
return urlPatterns.some(pattern => pattern.test(text));
|
|
73
|
+
}
|
|
74
|
+
exports.noUnescapedUrlParameter = (0, eslint_devkit_2.createRule)({
|
|
75
|
+
name: 'no-unescaped-url-parameter',
|
|
76
|
+
meta: {
|
|
77
|
+
type: 'problem',
|
|
78
|
+
docs: {
|
|
79
|
+
description: 'Detects unescaped URL parameters',
|
|
80
|
+
},
|
|
81
|
+
hasSuggestions: true,
|
|
82
|
+
messages: {
|
|
83
|
+
unescapedUrlParameter: (0, eslint_devkit_1.formatLLMMessage)({
|
|
84
|
+
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
85
|
+
issueName: 'Unescaped URL Parameter',
|
|
86
|
+
cwe: 'CWE-79',
|
|
87
|
+
description: 'Unescaped URL parameter detected: {{parameter}}',
|
|
88
|
+
severity: 'HIGH',
|
|
89
|
+
fix: '{{safeAlternative}}',
|
|
90
|
+
documentationLink: 'https://cwe.mitre.org/data/definitions/79.html',
|
|
91
|
+
}),
|
|
92
|
+
useEncodeURIComponent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
93
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
94
|
+
issueName: 'Use encodeURIComponent',
|
|
95
|
+
description: 'Use encodeURIComponent for URL params',
|
|
96
|
+
severity: 'LOW',
|
|
97
|
+
fix: '`https://example.com?q=${encodeURIComponent(param)}`',
|
|
98
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent',
|
|
99
|
+
}),
|
|
100
|
+
useURLSearchParams: (0, eslint_devkit_1.formatLLMMessage)({
|
|
101
|
+
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
102
|
+
issueName: 'Use URLSearchParams',
|
|
103
|
+
description: 'Use URLSearchParams for safe URL construction',
|
|
104
|
+
severity: 'LOW',
|
|
105
|
+
fix: 'new URLSearchParams({ q: param }).toString()',
|
|
106
|
+
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams',
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
schema: [
|
|
110
|
+
{
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
allowInTests: {
|
|
114
|
+
type: 'boolean',
|
|
115
|
+
default: false,
|
|
116
|
+
description: 'Allow unescaped URL parameters in test files',
|
|
117
|
+
},
|
|
118
|
+
trustedLibraries: {
|
|
119
|
+
type: 'array',
|
|
120
|
+
items: { type: 'string' },
|
|
121
|
+
default: ['url', 'querystring'],
|
|
122
|
+
description: 'Trusted URL construction libraries',
|
|
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
|
+
trustedLibraries: ['url', 'querystring'],
|
|
139
|
+
ignorePatterns: [],
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
create(context, [options = {}]) {
|
|
143
|
+
const { allowInTests = false, trustedLibraries = ['url', 'querystring'], ignorePatterns = [], } = options;
|
|
144
|
+
const filename = context.getFilename();
|
|
145
|
+
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
146
|
+
const sourceCode = context.sourceCode || context.sourceCode;
|
|
147
|
+
function checkTemplateLiteral(node) {
|
|
148
|
+
if (isTestFile) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// Check if this is a URL construction
|
|
152
|
+
if (!isUrlConstruction(node, sourceCode)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Check each expression in the template
|
|
156
|
+
for (const expression of node.expressions) {
|
|
157
|
+
const text = sourceCode.getText(expression);
|
|
158
|
+
// Check if it matches any ignore pattern
|
|
159
|
+
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
// Check if it's already encoded
|
|
163
|
+
if (isInsideEncodingCall(expression, sourceCode, trustedLibraries)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
// Check if it's a user input pattern
|
|
167
|
+
const userInputPatterns = [
|
|
168
|
+
/\breq\.(query|params|body|headers|cookies)/,
|
|
169
|
+
/\brequest\.(query|params|body)/,
|
|
170
|
+
/\buserInput\b/i,
|
|
171
|
+
/\binput\b/i,
|
|
172
|
+
/\bsearchParams\b/,
|
|
173
|
+
/\bparam\b/i, // Generic param variable
|
|
174
|
+
];
|
|
175
|
+
// Check both the expression text and the full template literal
|
|
176
|
+
// This catches nested patterns like req.query.id
|
|
177
|
+
const fullText = sourceCode.getText(node);
|
|
178
|
+
const exprText = sourceCode.getText(expression);
|
|
179
|
+
const isUserInput = userInputPatterns.some(pattern => pattern.test(text)) ||
|
|
180
|
+
userInputPatterns.some(pattern => pattern.test(fullText)) ||
|
|
181
|
+
userInputPatterns.some(pattern => pattern.test(exprText)) ||
|
|
182
|
+
// Also check for nested member expressions like req.query.id
|
|
183
|
+
(expression.type === 'MemberExpression' &&
|
|
184
|
+
userInputPatterns.some(pattern => {
|
|
185
|
+
// Check the full expression including nested properties
|
|
186
|
+
return pattern.test(exprText);
|
|
187
|
+
}));
|
|
188
|
+
if (isUserInput) {
|
|
189
|
+
context.report({
|
|
190
|
+
node: expression,
|
|
191
|
+
messageId: 'unescapedUrlParameter',
|
|
192
|
+
data: {
|
|
193
|
+
parameter: text,
|
|
194
|
+
safeAlternative: `Use encodeURIComponent() or URLSearchParams: const url = \`https://example.com?q=\${encodeURIComponent(${text})}\`;`,
|
|
195
|
+
},
|
|
196
|
+
suggest: [
|
|
197
|
+
{
|
|
198
|
+
messageId: 'useEncodeURIComponent',
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
200
|
+
fix: (_fixer) => null,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
messageId: 'useURLSearchParams',
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
205
|
+
fix: (_fixer) => null,
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function checkBinaryExpression(node) {
|
|
213
|
+
if (isTestFile) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Check for string concatenation in URL construction
|
|
217
|
+
if (node.operator === '+') {
|
|
218
|
+
if (!isUrlConstruction(node, sourceCode)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// Check right side (usually the parameter)
|
|
222
|
+
if (node.right.type !== 'Literal') {
|
|
223
|
+
const rightText = sourceCode.getText(node.right);
|
|
224
|
+
// Check if it matches any ignore pattern
|
|
225
|
+
if (matchesIgnorePattern(rightText, ignorePatterns)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Check if it's already encoded
|
|
229
|
+
if (isInsideEncodingCall(node.right, sourceCode, trustedLibraries)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// Check if it's a user input pattern
|
|
233
|
+
const userInputPatterns = [
|
|
234
|
+
/\breq\.(query|params|body)/,
|
|
235
|
+
/\brequest\.(query|params|body)/,
|
|
236
|
+
/\buserInput\b/,
|
|
237
|
+
/\binput\b/,
|
|
238
|
+
];
|
|
239
|
+
const isUserInput = userInputPatterns.some(pattern => pattern.test(rightText));
|
|
240
|
+
if (isUserInput) {
|
|
241
|
+
context.report({
|
|
242
|
+
node: node.right,
|
|
243
|
+
messageId: 'unescapedUrlParameter',
|
|
244
|
+
data: {
|
|
245
|
+
parameter: rightText,
|
|
246
|
+
safeAlternative: `Use encodeURIComponent(): ${sourceCode.getText(node.left)} + encodeURIComponent(${rightText})`,
|
|
247
|
+
},
|
|
248
|
+
suggest: [
|
|
249
|
+
{
|
|
250
|
+
messageId: 'useEncodeURIComponent',
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
252
|
+
fix: (_fixer) => null,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
TemplateLiteral: checkTemplateLiteral,
|
|
262
|
+
BinaryExpression: checkBinaryExpression,
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
//# sourceMappingURL=no-unescaped-url-parameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-unescaped-url-parameter.js","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-secure-coding/src/rules/security/no-unescaped-url-parameter.ts"],"names":[],"mappings":";;;AASA,4DAA0E;AAC1E,4DAAsD;AAiBtD;;GAEG;AACH,SAAS,oBAAoB,CAC3B,IAAmB,EACnB,UAA+B,EAC/B,gBAA0B;IAE1B,IAAI,OAAO,GAAyB,IAAI,CAAC;IAEzC,OAAO,OAAO,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAE9B,0CAA0C;YAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBACjC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;gBAC/B,IAAI,CAAC,oBAAoB,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,UAA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BAED,qCAAqC;oBACrC,MAAM,iBAAiB,GAAG;wBACxB,4BAA4B;wBAC5B,gCAAgC;wBAChC,eAAe;wBACf,WAAW;qBACZ,CAAC;oBAEF,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;oBAE/E,IAAI,WAAW,EAAE,CAAC;wBAChB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,IAAI,CAAC,KAAK;4BAChB,SAAS,EAAE,uBAAuB;4BAClC,IAAI,EAAE;gCACJ,SAAS,EAAE,SAAS;gCACpB,eAAe,EAAE,6BAA6B,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,SAAS,GAAG;6BACjH;4BACD,OAAO,EAAE;gCACP;oCACE,SAAS,EAAE,uBAAuB;oCAClC,6DAA6D;oCAC7D,GAAG,EAAE,CAAC,MAA0B,EAAE,EAAE,CAAC,IAAI;iCAC1C;6BACF;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,eAAe,EAAE,oBAAoB;YACrC,gBAAgB,EAAE,qBAAqB;SACxC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SecurityRuleOptions } from '@interlace/eslint-devkit';
|
|
2
|
+
export interface Options extends SecurityRuleOptions {
|
|
3
|
+
/** Maximum allowed resource size for static analysis */
|
|
4
|
+
maxResourceSize?: number;
|
|
5
|
+
/** Variables that contain user input */
|
|
6
|
+
userInputVariables?: string[];
|
|
7
|
+
/** Safe resource allocation functions */
|
|
8
|
+
safeResourceFunctions?: string[];
|
|
9
|
+
/** Require resource validation */
|
|
10
|
+
requireResourceValidation?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const noUnlimitedResourceAllocation: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|