@platform-sec/eslint-plugin-sensitive-string 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +193 -2
- package/dist/ast.d.ts +172 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +418 -0
- package/dist/ast.js.map +1 -0
- package/dist/configs.d.ts +38 -0
- package/dist/configs.d.ts.map +1 -0
- package/dist/configs.js +131 -0
- package/dist/configs.js.map +1 -0
- package/dist/docs.d.ts +28 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +33 -0
- package/dist/docs.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/log-calls.d.ts +28 -0
- package/dist/log-calls.d.ts.map +1 -0
- package/dist/log-calls.js +80 -0
- package/dist/log-calls.js.map +1 -0
- package/dist/options.d.ts +32 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +56 -0
- package/dist/options.js.map +1 -0
- package/dist/rules/explicit-class.d.ts +3 -0
- package/dist/rules/explicit-class.d.ts.map +1 -0
- package/dist/rules/explicit-class.js +93 -0
- package/dist/rules/explicit-class.js.map +1 -0
- package/dist/rules/no-allow-unaudited.d.ts +3 -0
- package/dist/rules/no-allow-unaudited.d.ts.map +1 -0
- package/dist/rules/no-allow-unaudited.js +92 -0
- package/dist/rules/no-allow-unaudited.js.map +1 -0
- package/dist/rules/no-credential-equality.d.ts +3 -0
- package/dist/rules/no-credential-equality.d.ts.map +1 -0
- package/dist/rules/no-credential-equality.js +146 -0
- package/dist/rules/no-credential-equality.js.map +1 -0
- package/dist/rules/no-log-reveal.d.ts +3 -0
- package/dist/rules/no-log-reveal.d.ts.map +1 -0
- package/dist/rules/no-log-reveal.js +67 -0
- package/dist/rules/no-log-reveal.js.map +1 -0
- package/dist/rules/no-network-sensitive.d.ts +3 -0
- package/dist/rules/no-network-sensitive.d.ts.map +1 -0
- package/dist/rules/no-network-sensitive.js +106 -0
- package/dist/rules/no-network-sensitive.js.map +1 -0
- package/dist/rules/no-password-fast-hash.d.ts +3 -0
- package/dist/rules/no-password-fast-hash.d.ts.map +1 -0
- package/dist/rules/no-password-fast-hash.js +84 -0
- package/dist/rules/no-password-fast-hash.js.map +1 -0
- package/dist/rules/no-stringify-sensitive.d.ts +3 -0
- package/dist/rules/no-stringify-sensitive.d.ts.map +1 -0
- package/dist/rules/no-stringify-sensitive.js +96 -0
- package/dist/rules/no-stringify-sensitive.js.map +1 -0
- package/dist/rules/prefer-safe-log.d.ts +3 -0
- package/dist/rules/prefer-safe-log.d.ts.map +1 -0
- package/dist/rules/prefer-safe-log.js +85 -0
- package/dist/rules/prefer-safe-log.js.map +1 -0
- package/dist/rules/require-reveal-context.d.ts +3 -0
- package/dist/rules/require-reveal-context.d.ts.map +1 -0
- package/dist/rules/require-reveal-context.js +149 -0
- package/dist/rules/require-reveal-context.js.map +1 -0
- package/dist/type-info.d.ts +134 -0
- package/dist/type-info.d.ts.map +1 -0
- package/dist/type-info.js +282 -0
- package/dist/type-info.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/docs/rules/explicit-class.md +62 -0
- package/docs/rules/no-allow-unaudited.md +93 -0
- package/docs/rules/no-credential-equality.md +69 -0
- package/docs/rules/no-log-reveal.md +104 -0
- package/docs/rules/no-network-sensitive.md +74 -0
- package/docs/rules/no-password-fast-hash.md +95 -0
- package/docs/rules/no-stringify-sensitive.md +144 -0
- package/docs/rules/prefer-safe-log.md +131 -0
- package/docs/rules/require-reveal-context.md +128 -0
- package/package.json +49 -3
package/dist/ast.js
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REVEAL_METHOD = void 0;
|
|
4
|
+
exports.unwrap = unwrap;
|
|
5
|
+
exports.identifierName = identifierName;
|
|
6
|
+
exports.staticPropertyName = staticPropertyName;
|
|
7
|
+
exports.staticKeyName = staticKeyName;
|
|
8
|
+
exports.literalString = literalString;
|
|
9
|
+
exports.objectProperties = objectProperties;
|
|
10
|
+
exports.operatorOf = operatorOf;
|
|
11
|
+
exports.operandsOf = operandsOf;
|
|
12
|
+
exports.discriminantOf = discriminantOf;
|
|
13
|
+
exports.isExplicitUndefined = isExplicitUndefined;
|
|
14
|
+
exports.isSpread = isSpread;
|
|
15
|
+
exports.callArguments = callArguments;
|
|
16
|
+
exports.calleeOf = calleeOf;
|
|
17
|
+
exports.hasSpreadArgument = hasSpreadArgument;
|
|
18
|
+
exports.asMethodCall = asMethodCall;
|
|
19
|
+
exports.isMethodCallNamed = isMethodCallNamed;
|
|
20
|
+
exports.calleeChainNames = calleeChainNames;
|
|
21
|
+
exports.getSourceCode = getSourceCode;
|
|
22
|
+
exports.getAncestors = getAncestors;
|
|
23
|
+
exports.childNodes = childNodes;
|
|
24
|
+
exports.findMethodCalls = findMethodCalls;
|
|
25
|
+
/**
|
|
26
|
+
* The method that hands out the raw value.
|
|
27
|
+
*
|
|
28
|
+
* Every rule keys off this name. It is a method name rather than a type, which
|
|
29
|
+
* is the whole tradeoff of an untyped rule: `magician.reveal()` looks the same
|
|
30
|
+
* as `apiKey.reveal()` to a parser. The rules that can narrow further (by
|
|
31
|
+
* requiring a log call or a network call around it) do; the ones that cannot
|
|
32
|
+
* say so in their documentation.
|
|
33
|
+
*/
|
|
34
|
+
exports.REVEAL_METHOD = 'reveal';
|
|
35
|
+
/**
|
|
36
|
+
* Node types that wrap an expression without changing its value, each holding
|
|
37
|
+
* the wrapped expression in `expression`.
|
|
38
|
+
*
|
|
39
|
+
* `ChainExpression` is how ESTree represents an optional chain, so `x?.reveal()`
|
|
40
|
+
* arrives as a `ChainExpression` and not as the `CallExpression` a rule is
|
|
41
|
+
* looking for. The `TS*` entries are `@typescript-eslint/parser` nodes: without
|
|
42
|
+
* unwrapping them, `(x.reveal() as string) === y` and `x!.reveal() === y` both
|
|
43
|
+
* slip past a rule that only checks whether an operand is a `CallExpression`.
|
|
44
|
+
* Casting a revealed secret is not a rare thing to write, so missing it would
|
|
45
|
+
* be a bypass rather than an edge case.
|
|
46
|
+
*/
|
|
47
|
+
const TRANSPARENT_WRAPPERS = new Set([
|
|
48
|
+
'ChainExpression',
|
|
49
|
+
'ParenthesizedExpression',
|
|
50
|
+
'TSAsExpression',
|
|
51
|
+
'TSSatisfiesExpression',
|
|
52
|
+
'TSNonNullExpression',
|
|
53
|
+
'TSTypeAssertion',
|
|
54
|
+
'TSInstantiationExpression',
|
|
55
|
+
]);
|
|
56
|
+
/** Fields never followed when walking, whatever a parser puts in them. */
|
|
57
|
+
const NON_CHILD_KEYS = new Set(['parent', 'loc', 'range', 'type']);
|
|
58
|
+
/** Read one field of a node without pretending to know the node's shape. */
|
|
59
|
+
function field(node, key) {
|
|
60
|
+
return node[key];
|
|
61
|
+
}
|
|
62
|
+
/** Whether a value is a node: an object carrying a `type` string. */
|
|
63
|
+
function isNode(value) {
|
|
64
|
+
return (typeof value === 'object' &&
|
|
65
|
+
value !== null &&
|
|
66
|
+
typeof value.type === 'string');
|
|
67
|
+
}
|
|
68
|
+
/** A node's field as a node, or `undefined` if it does not hold one. */
|
|
69
|
+
function nodeField(node, key) {
|
|
70
|
+
const value = field(node, key);
|
|
71
|
+
return isNode(value) ? value : undefined;
|
|
72
|
+
}
|
|
73
|
+
/** A node's field as a list of nodes, skipping the holes an array may contain. */
|
|
74
|
+
function nodeListField(node, key) {
|
|
75
|
+
const value = field(node, key);
|
|
76
|
+
return Array.isArray(value) ? value.filter(isNode) : [];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The expression inside any number of value-preserving wrappers.
|
|
80
|
+
*
|
|
81
|
+
* Idempotent and safe on a cyclic-looking tree: it only ever descends, and each
|
|
82
|
+
* step moves strictly inward.
|
|
83
|
+
*/
|
|
84
|
+
function unwrap(node) {
|
|
85
|
+
let current = node;
|
|
86
|
+
while (TRANSPARENT_WRAPPERS.has(current.type)) {
|
|
87
|
+
const inner = nodeField(current, 'expression');
|
|
88
|
+
if (inner === undefined) {
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
current = inner;
|
|
92
|
+
}
|
|
93
|
+
return current;
|
|
94
|
+
}
|
|
95
|
+
/** An `Identifier`'s name, or `undefined` for any other node. */
|
|
96
|
+
function identifierName(node) {
|
|
97
|
+
if (node.type !== 'Identifier') {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const name = field(node, 'name');
|
|
101
|
+
return typeof name === 'string' ? name : undefined;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The property name a member expression reads, when it is knowable statically.
|
|
105
|
+
*
|
|
106
|
+
* `x.reveal` and `x['reveal']` name the same method and both resolve here;
|
|
107
|
+
* `x[key]` does not, and yields `undefined` rather than a guess. Handling the
|
|
108
|
+
* computed-string form matters because it is the shortest way to write a call
|
|
109
|
+
* that a name-matching rule would otherwise miss.
|
|
110
|
+
*/
|
|
111
|
+
function staticPropertyName(member) {
|
|
112
|
+
const property = nodeField(member, 'property');
|
|
113
|
+
if (property === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (field(member, 'computed') !== true) {
|
|
117
|
+
return identifierName(property);
|
|
118
|
+
}
|
|
119
|
+
return property.type === 'Literal' ? literalString(property) : undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The property name an object-literal entry defines, when it is knowable
|
|
123
|
+
* statically. `{ reason: r }` and `{ 'reason': r }` both resolve; `{ [k]: r }`
|
|
124
|
+
* does not.
|
|
125
|
+
*/
|
|
126
|
+
function staticKeyName(property) {
|
|
127
|
+
const key = nodeField(property, 'key');
|
|
128
|
+
if (key === undefined) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (field(property, 'computed') !== true) {
|
|
132
|
+
return identifierName(key) ?? literalString(key);
|
|
133
|
+
}
|
|
134
|
+
return key.type === 'Literal' ? literalString(key) : undefined;
|
|
135
|
+
}
|
|
136
|
+
/** A `Literal`'s value when it is a string, otherwise `undefined`. */
|
|
137
|
+
function literalString(node) {
|
|
138
|
+
if (node.type !== 'Literal') {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const value = field(node, 'value');
|
|
142
|
+
return typeof value === 'string' ? value : undefined;
|
|
143
|
+
}
|
|
144
|
+
/** An object expression's entries, or an empty list for any other node. */
|
|
145
|
+
function objectProperties(node) {
|
|
146
|
+
return nodeListField(node, 'properties');
|
|
147
|
+
}
|
|
148
|
+
/** A binary or unary expression's operator, or `undefined` for any other node. */
|
|
149
|
+
function operatorOf(node) {
|
|
150
|
+
const operator = field(node, 'operator');
|
|
151
|
+
return typeof operator === 'string' ? operator : undefined;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A binary expression's operands, or `undefined` if it has none.
|
|
155
|
+
*
|
|
156
|
+
* Returned exactly as written, not unwrapped. Detection does not need them
|
|
157
|
+
* unwrapped, because {@link asMethodCall} unwraps whatever it is handed, while
|
|
158
|
+
* a rule that quotes an operand back into a suggestion does need the text the
|
|
159
|
+
* author wrote: unwrapping first would silently drop a cast from the rewrite.
|
|
160
|
+
*/
|
|
161
|
+
function operandsOf(node) {
|
|
162
|
+
const left = nodeField(node, 'left');
|
|
163
|
+
const right = nodeField(node, 'right');
|
|
164
|
+
if (left === undefined || right === undefined) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
return { left, right };
|
|
168
|
+
}
|
|
169
|
+
/** A switch statement's discriminant, as written, or `undefined`. */
|
|
170
|
+
function discriminantOf(node) {
|
|
171
|
+
return nodeField(node, 'discriminant');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Whether an argument is an explicit `undefined`, written either way.
|
|
175
|
+
*
|
|
176
|
+
* `reveal(undefined)` and `new SensitiveString(v, undefined)` satisfy a
|
|
177
|
+
* signature without deciding anything, so every rule that asks for an argument
|
|
178
|
+
* has to treat them as the absence of one. Otherwise the shortest way to
|
|
179
|
+
* silence any of those rules is to pass `undefined`, which reads like
|
|
180
|
+
* compliance and is not.
|
|
181
|
+
*/
|
|
182
|
+
function isExplicitUndefined(node) {
|
|
183
|
+
const value = unwrap(node);
|
|
184
|
+
return (identifierName(value) === 'undefined' ||
|
|
185
|
+
(value.type === 'UnaryExpression' && operatorOf(value) === 'void'));
|
|
186
|
+
}
|
|
187
|
+
/** Whether a node is a spread, in either the ESTree or the legacy spelling. */
|
|
188
|
+
function isSpread(node) {
|
|
189
|
+
return node.type === 'SpreadElement' || node.type === 'ExperimentalSpreadProperty';
|
|
190
|
+
}
|
|
191
|
+
/** A call expression's arguments, or an empty list for any other node. */
|
|
192
|
+
function callArguments(node) {
|
|
193
|
+
return nodeListField(node, 'arguments');
|
|
194
|
+
}
|
|
195
|
+
/** A call or `new` expression's callee, unwrapped, or `undefined`. */
|
|
196
|
+
function calleeOf(node) {
|
|
197
|
+
const callee = nodeField(node, 'callee');
|
|
198
|
+
return callee === undefined ? undefined : unwrap(callee);
|
|
199
|
+
}
|
|
200
|
+
/** Whether any argument is a spread, which makes the argument count unknowable. */
|
|
201
|
+
function hasSpreadArgument(node) {
|
|
202
|
+
return callArguments(node).some(isSpread);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Whether any link of a member or call chain is optional.
|
|
206
|
+
*
|
|
207
|
+
* Checking only the call and the member access nearest it is not enough:
|
|
208
|
+
* `a?.b.reveal()` marks neither, because the `?.` sits one link further down,
|
|
209
|
+
* and the whole expression is still `undefined` when `a` is. Only `object` and
|
|
210
|
+
* `callee` are followed, so a `?.` inside an argument does not count.
|
|
211
|
+
*/
|
|
212
|
+
function hasOptionalLink(node) {
|
|
213
|
+
let current = unwrap(node);
|
|
214
|
+
while (current !== undefined) {
|
|
215
|
+
if (field(current, 'optional') === true) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
if (current.type === 'MemberExpression') {
|
|
219
|
+
const object = nodeField(current, 'object');
|
|
220
|
+
current = object === undefined ? undefined : unwrap(object);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (current.type === 'CallExpression') {
|
|
224
|
+
const callee = nodeField(current, 'callee');
|
|
225
|
+
current = callee === undefined ? undefined : unwrap(callee);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* A node read as a method call, or `undefined` if it is not one.
|
|
234
|
+
*
|
|
235
|
+
* `optional` is reported rather than ignored so a rule that rewrites code can
|
|
236
|
+
* decline to: `x?.reveal() === y` and `x?.equals(y)` differ when `x` is nullish
|
|
237
|
+
* (`false` against `undefined`), and a suggestion is not the place to change
|
|
238
|
+
* that.
|
|
239
|
+
*/
|
|
240
|
+
function asMethodCall(node) {
|
|
241
|
+
const optionalOuter = node.type === 'ChainExpression';
|
|
242
|
+
const call = unwrap(node);
|
|
243
|
+
if (call.type !== 'CallExpression') {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
const rawCallee = nodeField(call, 'callee');
|
|
247
|
+
if (rawCallee === undefined) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
const callee = unwrap(rawCallee);
|
|
251
|
+
if (callee.type !== 'MemberExpression') {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
const method = staticPropertyName(callee);
|
|
255
|
+
const receiver = nodeField(callee, 'object');
|
|
256
|
+
if (method === undefined || receiver === undefined) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
call,
|
|
261
|
+
callee,
|
|
262
|
+
receiver,
|
|
263
|
+
method,
|
|
264
|
+
optional: optionalOuter || hasOptionalLink(call),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/** Whether a node is a call to one of `methods` on some receiver. */
|
|
268
|
+
function isMethodCallNamed(node, methods) {
|
|
269
|
+
const call = asMethodCall(node);
|
|
270
|
+
return call !== undefined && methods.has(call.method);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Every identifier and static property name along a callee chain.
|
|
274
|
+
*
|
|
275
|
+
* `console.log` yields `['log', 'console']`, `this.logger.info` yields
|
|
276
|
+
* `['info', 'logger']`, and `logger.child({ req }).info` yields
|
|
277
|
+
* `['info', 'child', 'logger']`. Matching against the whole chain rather than
|
|
278
|
+
* against a leading identifier is what lets a rule recognise the ways a logger
|
|
279
|
+
* or an HTTP client is actually reached: as a field of `this`, as a property of
|
|
280
|
+
* a request, or through a builder call.
|
|
281
|
+
*
|
|
282
|
+
* A link whose name is not statically knowable is stepped over rather than
|
|
283
|
+
* stopped at: `handlers[i].logger.info` still yields `['info', 'logger']`, so an
|
|
284
|
+
* index into a collection does not hide the object behind it. The walk ends at
|
|
285
|
+
* the first node that is neither a member access nor a call, which is an
|
|
286
|
+
* identifier (collected) or `this` (not).
|
|
287
|
+
*/
|
|
288
|
+
function calleeChainNames(callee) {
|
|
289
|
+
const names = [];
|
|
290
|
+
let current = unwrap(callee);
|
|
291
|
+
while (current !== undefined) {
|
|
292
|
+
if (current.type === 'MemberExpression') {
|
|
293
|
+
const name = staticPropertyName(current);
|
|
294
|
+
if (name !== undefined) {
|
|
295
|
+
names.push(name);
|
|
296
|
+
}
|
|
297
|
+
const object = nodeField(current, 'object');
|
|
298
|
+
current = object === undefined ? undefined : unwrap(object);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (current.type === 'CallExpression' || current.type === 'NewExpression') {
|
|
302
|
+
const inner = nodeField(current, 'callee');
|
|
303
|
+
current = inner === undefined ? undefined : unwrap(inner);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const name = identifierName(current);
|
|
307
|
+
if (name !== undefined) {
|
|
308
|
+
names.push(name);
|
|
309
|
+
}
|
|
310
|
+
current = undefined;
|
|
311
|
+
}
|
|
312
|
+
return names;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The `SourceCode` for the file being linted, across ESLint majors.
|
|
316
|
+
*
|
|
317
|
+
* ESLint 9 exposes it as a property and removed the getter; ESLint 8 has the
|
|
318
|
+
* getter from the start and gained the property in 8.40.
|
|
319
|
+
*/
|
|
320
|
+
function getSourceCode(context) {
|
|
321
|
+
if (context.sourceCode !== undefined) {
|
|
322
|
+
return context.sourceCode;
|
|
323
|
+
}
|
|
324
|
+
return typeof context.getSourceCode === 'function' ? context.getSourceCode() : undefined;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The ancestors of the node being visited, outermost first, across ESLint
|
|
328
|
+
* majors.
|
|
329
|
+
*
|
|
330
|
+
* ESLint 9 moved the call from the context onto `SourceCode` and made it take
|
|
331
|
+
* the node. The `SourceCode` form is tried first because ESLint 8.40, the
|
|
332
|
+
* oldest release this plugin supports, has both and warns on every use of the
|
|
333
|
+
* older one; a lint rule that prints a deprecation notice on each run is a rule
|
|
334
|
+
* people turn off.
|
|
335
|
+
*/
|
|
336
|
+
function getAncestors(context, node) {
|
|
337
|
+
const sourceCode = getSourceCode(context);
|
|
338
|
+
if (sourceCode !== undefined && typeof sourceCode.getAncestors === 'function') {
|
|
339
|
+
return sourceCode.getAncestors(node);
|
|
340
|
+
}
|
|
341
|
+
if (typeof context.getAncestors === 'function') {
|
|
342
|
+
return context.getAncestors();
|
|
343
|
+
}
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The children of a node, according to the parser that produced it.
|
|
348
|
+
*
|
|
349
|
+
* The `visitorKeys` map is the parser's own answer, so a TypeScript-only or
|
|
350
|
+
* JSX-only field is followed without this package listing it.
|
|
351
|
+
*
|
|
352
|
+
* The fallback enumerates the node's own fields, and it runs both when the
|
|
353
|
+
* parser supplies no keys at all and when it supplies keys that say nothing
|
|
354
|
+
* about *this* node type. The second case is the one that matters: a custom
|
|
355
|
+
* parser or a syntax plugin can produce a node the map does not describe, and
|
|
356
|
+
* pruning that subtree would silently stop the search inside it. Enumerating is
|
|
357
|
+
* the safe direction to be wrong in. `parent` is excluded because following it
|
|
358
|
+
* would walk back up the tree and never terminate.
|
|
359
|
+
*/
|
|
360
|
+
function childNodes(node, visitorKeys) {
|
|
361
|
+
const keys = visitorKeys?.[node.type];
|
|
362
|
+
const source = keys ?? Object.keys(node);
|
|
363
|
+
const children = [];
|
|
364
|
+
for (const key of source) {
|
|
365
|
+
if (keys === undefined && NON_CHILD_KEYS.has(key)) {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const value = field(node, key);
|
|
369
|
+
if (isNode(value)) {
|
|
370
|
+
children.push(value);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (Array.isArray(value)) {
|
|
374
|
+
for (const entry of value) {
|
|
375
|
+
if (isNode(entry)) {
|
|
376
|
+
children.push(entry);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return children;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Every call to one of `methods` inside `root`, `root` itself included, in
|
|
385
|
+
* source order.
|
|
386
|
+
*
|
|
387
|
+
* The search descends through everything, including function bodies. That is
|
|
388
|
+
* deliberate: `console.log(ids.map((id) => id.reveal()))` leaks exactly as much
|
|
389
|
+
* as `console.log(id.reveal())` does, and a callback is the ordinary way to
|
|
390
|
+
* write it. The cost is that logging a function that is never called, as in
|
|
391
|
+
* `console.log(() => secret.reveal())`, is reported too. Reporting an unused
|
|
392
|
+
* closure is a nuisance; missing a `map` over a list of secrets is a leak.
|
|
393
|
+
*
|
|
394
|
+
* A match does not end the descent into that node: `a.reveal().concat(b.reveal())`
|
|
395
|
+
* reports both. Each node is visited once, so the walk is linear in the size of
|
|
396
|
+
* the subtree.
|
|
397
|
+
*/
|
|
398
|
+
function findMethodCalls(root, methods, visitorKeys) {
|
|
399
|
+
const found = [];
|
|
400
|
+
const pending = [root];
|
|
401
|
+
const seen = new Set();
|
|
402
|
+
while (pending.length > 0) {
|
|
403
|
+
const node = pending.pop();
|
|
404
|
+
if (node === undefined || seen.has(node)) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
seen.add(node);
|
|
408
|
+
if (node.type === 'CallExpression' && isMethodCallNamed(node, methods)) {
|
|
409
|
+
found.push(node);
|
|
410
|
+
}
|
|
411
|
+
const children = childNodes(node, visitorKeys);
|
|
412
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
413
|
+
pending.push(children[index]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return found;
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=ast.js.map
|
package/dist/ast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":";;;AA8EA,wBAUC;AAGD,wCAMC;AAUD,gDAWC;AAOD,sCAWC;AAGD,sCAMC;AAGD,4CAEC;AAGD,gCAGC;AAUD,gCASC;AAGD,wCAEC;AAWD,kDAMC;AAGD,4BAEC;AAGD,sCAEC;AAGD,4BAGC;AAGD,8CAEC;AA0DD,oCA8BC;AAGD,8CAGC;AAkBD,4CA6BC;AAQD,sCAKC;AAYD,oCAWC;AAgBD,gCA6BC;AAiBD,0CA2BC;AA1dD;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,QAAQ,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACxD,iBAAiB;IACjB,yBAAyB;IACzB,gBAAgB;IAChB,uBAAuB;IACvB,qBAAqB;IACrB,iBAAiB;IACjB,2BAA2B;CAC5B,CAAC,CAAC;AAEH,0EAA0E;A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;QAED,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC/C,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAC7D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAY,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shipped presets.
|
|
3
|
+
*
|
|
4
|
+
* Two shapes of the same presets. ESLint 9 reads flat config and ESLint 8
|
|
5
|
+
* reads eslintrc, and the difference is not cosmetic: a flat config names the
|
|
6
|
+
* plugin by holding the plugin object, an eslintrc names it by a string that
|
|
7
|
+
* ESLint resolves itself. A preset written for one is silently inert in the
|
|
8
|
+
* other, so both are built here from one list of rule settings and cannot drift
|
|
9
|
+
* apart.
|
|
10
|
+
*
|
|
11
|
+
* The other split is type information. `no-stringify-sensitive` and
|
|
12
|
+
* `prefer-safe-log` have to ask what a value's type contains, so they belong
|
|
13
|
+
* only in a preset whose consumer has configured a TypeScript program. Put in
|
|
14
|
+
* `recommended`, they would report a misconfiguration on every plain
|
|
15
|
+
* JavaScript file, which is the noise that gets a plugin removed. They live in
|
|
16
|
+
* the `-type-checked` presets instead, and `disable-type-checked` turns them
|
|
17
|
+
* back off for the files in a mixed project that have no program.
|
|
18
|
+
*/
|
|
19
|
+
import type { Plugin } from './types.js';
|
|
20
|
+
/**
|
|
21
|
+
* The name a config file uses to reach these rules.
|
|
22
|
+
*
|
|
23
|
+
* ESLint derives it from the package name by dropping `eslint-plugin-`, so
|
|
24
|
+
* `@platform-sec/eslint-plugin-sensitive-string` is written as
|
|
25
|
+
* `@platform-sec/sensitive-string`. Spelling it out here keeps the flat and
|
|
26
|
+
* eslintrc presets addressing the same rules.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PLUGIN_NAMESPACE = "@platform-sec/sensitive-string";
|
|
29
|
+
/**
|
|
30
|
+
* Every preset, built against the finished plugin object.
|
|
31
|
+
*
|
|
32
|
+
* A flat preset has to hold the plugin it configures, and the plugin has to
|
|
33
|
+
* hold its presets, so one of the two references is filled in after the fact.
|
|
34
|
+
* Taking the plugin as an argument keeps that knot in `index.ts`, where it is
|
|
35
|
+
* visible, rather than hiding it behind a lazy getter.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildConfigs(plugin: Plugin): Record<string, unknown>;
|
|
38
|
+
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../src/configs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AAgHjE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBpE"}
|
package/dist/configs.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_NAMESPACE = void 0;
|
|
4
|
+
exports.buildConfigs = buildConfigs;
|
|
5
|
+
/**
|
|
6
|
+
* The name a config file uses to reach these rules.
|
|
7
|
+
*
|
|
8
|
+
* ESLint derives it from the package name by dropping `eslint-plugin-`, so
|
|
9
|
+
* `@platform-sec/eslint-plugin-sensitive-string` is written as
|
|
10
|
+
* `@platform-sec/sensitive-string`. Spelling it out here keeps the flat and
|
|
11
|
+
* eslintrc presets addressing the same rules.
|
|
12
|
+
*/
|
|
13
|
+
exports.PLUGIN_NAMESPACE = '@platform-sec/sensitive-string';
|
|
14
|
+
/**
|
|
15
|
+
* The default posture.
|
|
16
|
+
*
|
|
17
|
+
* The three rules that catch a value actually escaping are errors, and so is
|
|
18
|
+
* the one that catches an audit control being switched off: `allowUnaudited`
|
|
19
|
+
* is never written by accident, so the finding is never wrong, and a disable
|
|
20
|
+
* comment is where the reason belongs. The three that reason about something
|
|
21
|
+
* they cannot see are warnings, and a warning is the honest severity for a
|
|
22
|
+
* check that can be wrong: a context installed in a caller, a class supplied
|
|
23
|
+
* through a spread, and a password recognised by what the variable holding it
|
|
24
|
+
* is called.
|
|
25
|
+
*/
|
|
26
|
+
const RECOMMENDED_RULES = {
|
|
27
|
+
'no-log-reveal': 'error',
|
|
28
|
+
'no-credential-equality': 'error',
|
|
29
|
+
'no-network-sensitive': 'error',
|
|
30
|
+
'no-allow-unaudited': 'error',
|
|
31
|
+
'explicit-class': 'warn',
|
|
32
|
+
'require-reveal-context': 'warn',
|
|
33
|
+
'no-password-fast-hash': 'warn',
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Everything on, at error, with the reveal context required to say why.
|
|
37
|
+
*
|
|
38
|
+
* `allowWithContext: false` also drops the exemption that lets an audited
|
|
39
|
+
* reveal reach the network, so the only way a value leaves the process is
|
|
40
|
+
* through `serialize()`.
|
|
41
|
+
*/
|
|
42
|
+
const STRICT_RULES = {
|
|
43
|
+
'no-log-reveal': 'error',
|
|
44
|
+
'no-credential-equality': 'error',
|
|
45
|
+
'no-network-sensitive': ['error', { allowWithContext: false }],
|
|
46
|
+
'no-allow-unaudited': 'error',
|
|
47
|
+
'explicit-class': 'error',
|
|
48
|
+
'require-reveal-context': ['error', { requireReason: true }],
|
|
49
|
+
'no-password-fast-hash': 'error',
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The two rules that need a program, at the severity `recommended` would give
|
|
53
|
+
* them.
|
|
54
|
+
*
|
|
55
|
+
* `no-stringify-sensitive` is an error because both things it catches are
|
|
56
|
+
* definite: a `serialize()` result written out in the clear, and a redaction
|
|
57
|
+
* substituted for a value that was supposed to arrive somewhere. Neither is a
|
|
58
|
+
* judgement call.
|
|
59
|
+
*
|
|
60
|
+
* `prefer-safe-log` is a warning because most of what it reports is not yet a
|
|
61
|
+
* leak. A `SensitiveString` inside a logged object redacts itself today,
|
|
62
|
+
* through whichever of `toJSON` and `util.inspect` the transport reaches for;
|
|
63
|
+
* the rule is about not depending on that. The one case that is a leak, a
|
|
64
|
+
* `serialize()` result in a log line, gets its own message.
|
|
65
|
+
*/
|
|
66
|
+
const TYPE_AWARE_RULES = {
|
|
67
|
+
'no-stringify-sensitive': 'error',
|
|
68
|
+
'prefer-safe-log': 'warn',
|
|
69
|
+
};
|
|
70
|
+
/** The same two at error, for `strict-type-checked`. */
|
|
71
|
+
const STRICT_TYPE_AWARE_RULES = {
|
|
72
|
+
'no-stringify-sensitive': 'error',
|
|
73
|
+
'prefer-safe-log': 'error',
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The type-aware rules off.
|
|
77
|
+
*
|
|
78
|
+
* For the block of a flat config that matches the files a program does not
|
|
79
|
+
* cover: plain JavaScript, generated code, anything outside `tsconfig.json`.
|
|
80
|
+
* Layered after a `-type-checked` preset it silences the two rules there,
|
|
81
|
+
* which is what those rules do instead of failing quietly on a file whose
|
|
82
|
+
* types they cannot see.
|
|
83
|
+
*/
|
|
84
|
+
const DISABLED_TYPE_AWARE_RULES = {
|
|
85
|
+
'no-stringify-sensitive': 'off',
|
|
86
|
+
'prefer-safe-log': 'off',
|
|
87
|
+
};
|
|
88
|
+
/** Rule settings keyed by their fully qualified name. */
|
|
89
|
+
function qualify(rules) {
|
|
90
|
+
return Object.fromEntries(Object.entries(rules).map(([name, entry]) => [`${exports.PLUGIN_NAMESPACE}/${name}`, entry]));
|
|
91
|
+
}
|
|
92
|
+
/** A flat-config object, for `eslint.config.js`. */
|
|
93
|
+
function flatConfig(plugin, name, rules) {
|
|
94
|
+
return {
|
|
95
|
+
name: `${exports.PLUGIN_NAMESPACE}/${name}`,
|
|
96
|
+
plugins: { [exports.PLUGIN_NAMESPACE]: plugin },
|
|
97
|
+
rules: qualify(rules),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** An eslintrc config object, for `.eslintrc.*`. */
|
|
101
|
+
function legacyConfig(rules) {
|
|
102
|
+
return {
|
|
103
|
+
plugins: [exports.PLUGIN_NAMESPACE],
|
|
104
|
+
rules: qualify(rules),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Every preset, built against the finished plugin object.
|
|
109
|
+
*
|
|
110
|
+
* A flat preset has to hold the plugin it configures, and the plugin has to
|
|
111
|
+
* hold its presets, so one of the two references is filled in after the fact.
|
|
112
|
+
* Taking the plugin as an argument keeps that knot in `index.ts`, where it is
|
|
113
|
+
* visible, rather than hiding it behind a lazy getter.
|
|
114
|
+
*/
|
|
115
|
+
function buildConfigs(plugin) {
|
|
116
|
+
const recommendedTypeChecked = { ...RECOMMENDED_RULES, ...TYPE_AWARE_RULES };
|
|
117
|
+
const strictTypeChecked = { ...STRICT_RULES, ...STRICT_TYPE_AWARE_RULES };
|
|
118
|
+
return {
|
|
119
|
+
recommended: flatConfig(plugin, 'recommended', RECOMMENDED_RULES),
|
|
120
|
+
strict: flatConfig(plugin, 'strict', STRICT_RULES),
|
|
121
|
+
'recommended-type-checked': flatConfig(plugin, 'recommended-type-checked', recommendedTypeChecked),
|
|
122
|
+
'strict-type-checked': flatConfig(plugin, 'strict-type-checked', strictTypeChecked),
|
|
123
|
+
'disable-type-checked': flatConfig(plugin, 'disable-type-checked', DISABLED_TYPE_AWARE_RULES),
|
|
124
|
+
'legacy-recommended': legacyConfig(RECOMMENDED_RULES),
|
|
125
|
+
'legacy-strict': legacyConfig(STRICT_RULES),
|
|
126
|
+
'legacy-recommended-type-checked': legacyConfig(recommendedTypeChecked),
|
|
127
|
+
'legacy-strict-type-checked': legacyConfig(strictTypeChecked),
|
|
128
|
+
'legacy-disable-type-checked': legacyConfig(DISABLED_TYPE_AWARE_RULES),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../src/configs.ts"],"names":[],"mappings":";;;AAoJA,oCAoBC;AApJD;;;;;;;GAOG;AACU,QAAA,gBAAgB,GAAG,gCAAgC,CAAC;AAKjE;;;;;;;;;;;GAWG;AACH,MAAM,iBAAiB,GAAwC;IAC7D,eAAe,EAAE,OAAO;IACxB,wBAAwB,EAAE,OAAO;IACjC,sBAAsB,EAAE,OAAO;IAC/B,oBAAoB,EAAE,OAAO;IAC7B,gBAAgB,EAAE,MAAM;IACxB,wBAAwB,EAAE,MAAM;IAChC,uBAAuB,EAAE,MAAM;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,YAAY,GAAwC;IACxD,eAAe,EAAE,OAAO;IACxB,wBAAwB,EAAE,OAAO;IACjC,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IAC9D,oBAAoB,EAAE,OAAO;IAC7B,gBAAgB,EAAE,OAAO;IACzB,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC5D,uBAAuB,EAAE,OAAO;CACjC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,gBAAgB,GAAwC;IAC5D,wBAAwB,EAAE,OAAO;IACjC,iBAAiB,EAAE,MAAM;CAC1B,CAAC;AAEF,wDAAwD;AACxD,MAAM,uBAAuB,GAAwC;IACnE,wBAAwB,EAAE,OAAO;IACjC,iBAAiB,EAAE,OAAO;CAC3B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,yBAAyB,GAAwC;IACrE,wBAAwB,EAAE,KAAK;IAC/B,iBAAiB,EAAE,KAAK;CACzB,CAAC;AAEF,yDAAyD;A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B,EAAE,yBAAyB,CAAC;QAC7F,oBAAoB,EAAE,YAAY,CAAC,iBAAiB,CAAC;QACrD,eAAe,EAAE,YAAY,CAAC,YAAY,CAAC;QAC3C,iCAAiC,EAAE,YAAY,CAAC,sBAAsB,CAAC;QACvE,4BAA4B,EAAE,YAAY,CAAC,iBAAiB,CAAC;QAC7D,6BAA6B,EAAE,YAAY,CAAC,yBAAyB,CAAC;KACvE,CAAC;AACJ,CAAC"}
|
package/dist/docs.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a rule's documentation lives.
|
|
3
|
+
*
|
|
4
|
+
* `meta.docs.url` is what an editor turns into the "learn more" link on a
|
|
5
|
+
* report, and ESLint requires an absolute URL for it. This project has no
|
|
6
|
+
* public repository yet, so there is no honest absolute URL to give: pointing
|
|
7
|
+
* the link at a guessed host would put a dead link in front of every developer
|
|
8
|
+
* who hovers a finding, which is worse than no link at all.
|
|
9
|
+
*
|
|
10
|
+
* The markdown under `docs/rules/` ships in the package either way, so the
|
|
11
|
+
* documentation is present in `node_modules` regardless. When the project gets
|
|
12
|
+
* a home, set {@link DOCS_BASE_URL} and every rule picks the link up.
|
|
13
|
+
*/
|
|
14
|
+
/** The published location of `docs/rules/`, with a trailing slash, or `undefined`. */
|
|
15
|
+
export declare const DOCS_BASE_URL: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The `docs` block for a rule, carrying a `url` only when there is one to give.
|
|
18
|
+
*
|
|
19
|
+
* `url` is omitted rather than set to `undefined` because `exactOptionalPropertyTypes`
|
|
20
|
+
* distinguishes the two, and because ESLint's own config-inspector renders an
|
|
21
|
+
* explicit `undefined` as a broken link.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ruleDocs(ruleName: string, description: string, recommended: boolean, base?: string | undefined): {
|
|
24
|
+
readonly description: string;
|
|
25
|
+
readonly recommended: boolean;
|
|
26
|
+
readonly url?: string;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,sFAAsF;AACtF,eAAO,MAAM,aAAa,EAAE,MAAM,GAAG,SAAqB,CAAC;AAE3D;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,OAAO,EACpB,IAAI,GAAE,MAAM,GAAG,SAAyB,GACvC;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAKxF"}
|