@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
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SERIALIZED_TYPES = exports.DEFAULT_SENSITIVE_TYPES = void 0;
|
|
4
|
+
exports.getTypeServices = getTypeServices;
|
|
5
|
+
exports.isSensitiveWrapper = isSensitiveWrapper;
|
|
6
|
+
exports.findSensitiveType = findSensitiveType;
|
|
7
|
+
/**
|
|
8
|
+
* Type-aware access, for the two rules that cannot work without it.
|
|
9
|
+
*
|
|
10
|
+
* The other five rules read the shape of a call. These two have to answer a
|
|
11
|
+
* different question: does this *value* carry a sensitive one anywhere inside
|
|
12
|
+
* it? No amount of syntax answers that. Guessing from a variable's name is the
|
|
13
|
+
* substitute usually proposed, and it is worse than nothing here: it reports
|
|
14
|
+
* `JSON.stringify(token)` and stays quiet on `JSON.stringify(user)`, which is
|
|
15
|
+
* the call that actually holds the secret.
|
|
16
|
+
*
|
|
17
|
+
* ## What is declared here, and why
|
|
18
|
+
*
|
|
19
|
+
* The TypeScript API is reached structurally, the same way `./types.js`
|
|
20
|
+
* reaches ESLint's. This package has no dependencies and adding `typescript`
|
|
21
|
+
* as one would put it in the install of every consumer who lints plain
|
|
22
|
+
* JavaScript, for a pair of rules they cannot run. Nothing here is imported at
|
|
23
|
+
* runtime either: the checker arrives through `parserServices`, already
|
|
24
|
+
* constructed by whoever configured type-aware linting.
|
|
25
|
+
*
|
|
26
|
+
* The declarations are deliberately small. Every method below is public API
|
|
27
|
+
* that has been stable since TypeScript 4.7, and the set is bounded by the
|
|
28
|
+
* traversal in {@link findSensitiveType}, which mirrors what `JSON.stringify`
|
|
29
|
+
* and `util.inspect` themselves walk: union members, array and tuple elements,
|
|
30
|
+
* base classes, object properties, index signatures. Nothing else can carry a
|
|
31
|
+
* value into a log line or a request body.
|
|
32
|
+
*/
|
|
33
|
+
const ast_js_1 = require("./ast.js");
|
|
34
|
+
/** The library's own names, which every project gets without configuring any. */
|
|
35
|
+
exports.DEFAULT_SENSITIVE_TYPES = ['SensitiveString'];
|
|
36
|
+
/**
|
|
37
|
+
* The wire format's name.
|
|
38
|
+
*
|
|
39
|
+
* Matched exactly, never by prefix: `SerializedSensitiveString` is the shape
|
|
40
|
+
* `serialize()` produces and `deserialize()` consumes, so a rule that reported
|
|
41
|
+
* every name containing "Sensitive" would report the recommended transmission
|
|
42
|
+
* path at the point where it is correct.
|
|
43
|
+
*/
|
|
44
|
+
exports.DEFAULT_SERIALIZED_TYPES = ['SerializedSensitiveString'];
|
|
45
|
+
/**
|
|
46
|
+
* How many distinct types one search may examine.
|
|
47
|
+
*
|
|
48
|
+
* A safety valve, not a design limit. The visited set already makes the walk
|
|
49
|
+
* terminate on a recursive type; this bounds the pathological case where a
|
|
50
|
+
* single argument is typed as a framework object reaching thousands of others,
|
|
51
|
+
* so that one unlucky call cannot make a lint run look hung. A payload type
|
|
52
|
+
* that reaches this figure without a sensitive value in it does not exist in
|
|
53
|
+
* practice, and the rule's documentation says what happens if one does.
|
|
54
|
+
*/
|
|
55
|
+
const TYPE_BUDGET = 1000;
|
|
56
|
+
/** Whether a value is an object, for narrowing what a parser handed back. */
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === 'object' && value !== null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The type checker for the file being linted, or `undefined` when the consumer
|
|
62
|
+
* has not configured type-aware linting.
|
|
63
|
+
*
|
|
64
|
+
* Both spellings are tried because they belong to different ESLint majors: 9
|
|
65
|
+
* hangs `parserServices` off `SourceCode`, 8 hangs it off the rule context.
|
|
66
|
+
* `program` is `null` rather than absent under `@typescript-eslint/parser`
|
|
67
|
+
* without a `project`, which is the ordinary "TypeScript parser, no types"
|
|
68
|
+
* configuration and has to read as "no type information" rather than as a
|
|
69
|
+
* malformed services object.
|
|
70
|
+
*/
|
|
71
|
+
function getTypeServices(context) {
|
|
72
|
+
const raw = (0, ast_js_1.getSourceCode)(context)?.parserServices ?? context.parserServices;
|
|
73
|
+
if (!isRecord(raw)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const services = raw;
|
|
77
|
+
const program = services.program;
|
|
78
|
+
const nodeMap = services.esTreeNodeToTSNodeMap;
|
|
79
|
+
if (!isRecord(program) ||
|
|
80
|
+
typeof program.getTypeChecker !== 'function' ||
|
|
81
|
+
!isRecord(nodeMap) ||
|
|
82
|
+
typeof nodeMap.get !== 'function') {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
checker: program.getTypeChecker(),
|
|
87
|
+
tsNodeOf: (node) => nodeMap.get(node),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** The names a type answers to: its own, and the alias it was written as. */
|
|
91
|
+
function namesOf(type) {
|
|
92
|
+
const names = [];
|
|
93
|
+
// Both, not the first of the two. `type Token = SensitiveString<'credential'>`
|
|
94
|
+
// has `Token` as its alias and `SensitiveString` as its own symbol, and a
|
|
95
|
+
// project may well have configured either one.
|
|
96
|
+
const alias = type.aliasSymbol?.name;
|
|
97
|
+
if (typeof alias === 'string') {
|
|
98
|
+
names.push(alias);
|
|
99
|
+
}
|
|
100
|
+
const own = type.symbol?.name;
|
|
101
|
+
if (typeof own === 'string') {
|
|
102
|
+
names.push(own);
|
|
103
|
+
}
|
|
104
|
+
return names;
|
|
105
|
+
}
|
|
106
|
+
/** The match a type's own names produce, or `undefined` if none do. */
|
|
107
|
+
function matchNames(type, names, throughProperty) {
|
|
108
|
+
for (const name of namesOf(type)) {
|
|
109
|
+
if (names.serialized.has(name)) {
|
|
110
|
+
return { name, serialized: true, throughProperty };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const name of namesOf(type)) {
|
|
114
|
+
if (names.sensitive.has(name)) {
|
|
115
|
+
return { name, serialized: false, throughProperty };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Everything a type can carry a value through, mirroring what a serializer
|
|
122
|
+
* walks.
|
|
123
|
+
*
|
|
124
|
+
* Union and intersection members, array and tuple elements, and base classes
|
|
125
|
+
* preserve how the type was reached: a `SensitiveString[]` is still the value
|
|
126
|
+
* itself, logged as a list. Properties and index signatures do not, because
|
|
127
|
+
* something else is holding the value now.
|
|
128
|
+
*
|
|
129
|
+
* A union and an array each answer for the whole of themselves, so neither
|
|
130
|
+
* goes on to its properties. For an array that is not a nicety: `Array<T>`
|
|
131
|
+
* declares a numeric index signature, so following its members would reach
|
|
132
|
+
* every element back through a property edge and turn `console.log(tokens)`
|
|
133
|
+
* into a finding. Its other properties are `Array.prototype`, which is not
|
|
134
|
+
* payload either.
|
|
135
|
+
*/
|
|
136
|
+
function childrenOf(type, location, checker, throughProperty) {
|
|
137
|
+
const children = [];
|
|
138
|
+
const push = (child, through) => {
|
|
139
|
+
if (isRecord(child)) {
|
|
140
|
+
children.push({ type: child, throughProperty: through });
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const members = type.types ?? [];
|
|
144
|
+
if (members.length > 0) {
|
|
145
|
+
for (const member of members) {
|
|
146
|
+
push(member, throughProperty);
|
|
147
|
+
}
|
|
148
|
+
return children;
|
|
149
|
+
}
|
|
150
|
+
if (checker.isArrayType(type) || checker.isTupleType(type)) {
|
|
151
|
+
for (const element of checker.getTypeArguments?.(type) ?? []) {
|
|
152
|
+
push(element, throughProperty);
|
|
153
|
+
}
|
|
154
|
+
return children;
|
|
155
|
+
}
|
|
156
|
+
// A subclass is reached by name through here and nowhere else: inherited
|
|
157
|
+
// members arrive through `getProperties` already, but the base type's own
|
|
158
|
+
// name does not, and a `class ApiKey extends SensitiveString` is still a
|
|
159
|
+
// sensitive value.
|
|
160
|
+
for (const base of type.getBaseTypes?.() ?? []) {
|
|
161
|
+
push(base, throughProperty);
|
|
162
|
+
}
|
|
163
|
+
for (const property of type.getProperties()) {
|
|
164
|
+
push(checker.getTypeOfSymbolAtLocation(property, location), true);
|
|
165
|
+
}
|
|
166
|
+
for (const info of checker.getIndexInfosOfType?.(type) ?? []) {
|
|
167
|
+
push(info.type, true);
|
|
168
|
+
}
|
|
169
|
+
return children;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* How many types one receiver check may examine.
|
|
173
|
+
*
|
|
174
|
+
* Far below {@link TYPE_BUDGET}, because this walk is a different shape: it
|
|
175
|
+
* follows unions and base classes only, never properties, so the count is the
|
|
176
|
+
* depth of an inheritance chain and the width of a union rather than the size
|
|
177
|
+
* of a payload. A receiver that reaches this figure is not a wrapper.
|
|
178
|
+
*/
|
|
179
|
+
const RECEIVER_BUDGET = 64;
|
|
180
|
+
/**
|
|
181
|
+
* Whether an expression *is* a sensitive wrapper, rather than carrying one.
|
|
182
|
+
*
|
|
183
|
+
* The question `findSensitiveType` answers is "does this structure hold a
|
|
184
|
+
* value", which is what a serializer walks. This one asks whether the
|
|
185
|
+
* expression in hand is the wrapper itself, which is what a method call needs:
|
|
186
|
+
* `bcrypt.hash(...)` and `token.hash(...)` are the same syntax, and only the
|
|
187
|
+
* receiver's type separates them.
|
|
188
|
+
*
|
|
189
|
+
* Properties are therefore not followed. A `{ token: SensitiveString }` holds
|
|
190
|
+
* one and has no `hash` method of its own, so following its properties would
|
|
191
|
+
* report `user.hash()` on a `user` that has an unrelated one. Unions,
|
|
192
|
+
* intersections and base classes are followed: `SensitiveString | undefined`
|
|
193
|
+
* is what an optional chain produces, and `class ApiKey extends
|
|
194
|
+
* SensitiveString` is still a wrapper.
|
|
195
|
+
*/
|
|
196
|
+
function isSensitiveWrapper(node, services, names) {
|
|
197
|
+
const location = services.tsNodeOf(node);
|
|
198
|
+
if (location === undefined) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const root = services.checker.getTypeAtLocation(location);
|
|
202
|
+
if (!isRecord(root)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const pending = [root];
|
|
206
|
+
const seen = new Set();
|
|
207
|
+
let budget = RECEIVER_BUDGET;
|
|
208
|
+
while (pending.length > 0 && budget > 0) {
|
|
209
|
+
const type = pending.pop();
|
|
210
|
+
if (seen.has(type)) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
seen.add(type);
|
|
214
|
+
budget -= 1;
|
|
215
|
+
if (namesOf(type).some((name) => names.has(name))) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
for (const member of type.types ?? []) {
|
|
219
|
+
if (isRecord(member)) {
|
|
220
|
+
pending.push(member);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const base of type.getBaseTypes?.() ?? []) {
|
|
224
|
+
if (isRecord(base)) {
|
|
225
|
+
pending.push(base);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The sensitive type an expression's type carries, or `undefined`.
|
|
233
|
+
*
|
|
234
|
+
* The search stops as soon as it finds one reached through a property, which
|
|
235
|
+
* is the finding both rules most want to report. A match on the value itself,
|
|
236
|
+
* or on an element of a list of them, is kept but does not end the walk: a
|
|
237
|
+
* `SensitiveString` in hand says nothing about whether the same expression
|
|
238
|
+
* also holds one inside a record, and the two produce different findings.
|
|
239
|
+
*
|
|
240
|
+
* Visited types are tracked separately per arrival, because the same type
|
|
241
|
+
* reached directly and reached through a property is two different answers,
|
|
242
|
+
* and the first must not suppress the second.
|
|
243
|
+
*/
|
|
244
|
+
function findSensitiveType(node, services, names) {
|
|
245
|
+
const location = services.tsNodeOf(node);
|
|
246
|
+
if (location === undefined) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
const root = services.checker.getTypeAtLocation(location);
|
|
250
|
+
if (!isRecord(root)) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const pending = [{ type: root, throughProperty: false }];
|
|
254
|
+
const seenDirectly = new Set();
|
|
255
|
+
const seenThroughProperty = new Set();
|
|
256
|
+
let budget = TYPE_BUDGET;
|
|
257
|
+
let direct;
|
|
258
|
+
while (pending.length > 0 && budget > 0) {
|
|
259
|
+
const entry = pending.pop();
|
|
260
|
+
const seen = entry.throughProperty ? seenThroughProperty : seenDirectly;
|
|
261
|
+
if (seen.has(entry.type)) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
seen.add(entry.type);
|
|
265
|
+
budget -= 1;
|
|
266
|
+
const match = matchNames(entry.type, names, entry.throughProperty);
|
|
267
|
+
if (match !== undefined) {
|
|
268
|
+
if (match.throughProperty) {
|
|
269
|
+
return match;
|
|
270
|
+
}
|
|
271
|
+
// A wire-format object found in hand outranks a wrapper found in hand:
|
|
272
|
+
// one is a leak, the other is the documented way to pass a value around.
|
|
273
|
+
if (direct === undefined || (match.serialized && !direct.serialized)) {
|
|
274
|
+
direct = match;
|
|
275
|
+
}
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
pending.push(...childrenOf(entry.type, location, services.checker, entry.throughProperty));
|
|
279
|
+
}
|
|
280
|
+
return direct;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=type-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-info.js","sourceRoot":"","sources":["../src/type-info.ts"],"names":[],"mappings":";;;AAsKA,0CAuBC;AA0ID,gDA6CC;AAeD,8CA+CC;AAlbD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qCAAyC;AAmGzC,iFAAiF;AACpE,QAAA,uBAAuB,GAAsB,CAAC,iBAAiB,CAAC,CAAC;AAE9E;;;;;;;GAOG;AACU,QAAA,wBAAwB,GAAsB,CAAC,2BAA2B,CAAC,CAAC;AAEzF;;;;;;;;;GASG;AACH,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,6EAA6E;AAC7E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAAC,OAAoB;IAClD,MAAM,GAAG,GAAG,IAAA,sBAAa,EAA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AAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;gBACrE,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;YACD,SAAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of ESLint's rule API this plugin uses, declared structurally.
|
|
3
|
+
*
|
|
4
|
+
* Where ESLint's own types come from depends on the major: ESLint 9 ships them
|
|
5
|
+
* in the package, while an ESLint 8 consumer installs `@types/eslint`. This
|
|
6
|
+
* plugin's peer range spans both, so importing either would put one major's
|
|
7
|
+
* declarations into the emitted `.d.ts` and make the other half of the range
|
|
8
|
+
* type-check against rule types it does not have. Declaring the shapes instead
|
|
9
|
+
* keeps the published types self-contained, the same way the testing package
|
|
10
|
+
* declares `pretty-format`'s plugin shape rather than depending on it.
|
|
11
|
+
*
|
|
12
|
+
* The types are also deliberately looser than ESLint's in one place: {@link
|
|
13
|
+
* AstNode} carries nothing but `type`. A rule in this plugin has to run under
|
|
14
|
+
* `espree` and under `@typescript-eslint/parser`, and the second produces nodes
|
|
15
|
+
* (`TSAsExpression`, `TSNonNullExpression`) that no ESTree union contains. A
|
|
16
|
+
* narrow union would make handling them a type error, which is backwards: the
|
|
17
|
+
* TypeScript nodes are exactly the ones a security rule must not miss. Access
|
|
18
|
+
* to a node's fields goes through the guards in `./ast.js`, which check at
|
|
19
|
+
* runtime what the type system is not being asked to promise.
|
|
20
|
+
*/
|
|
21
|
+
/** Any node any parser produces. Narrow it with the guards in `./ast.js`. */
|
|
22
|
+
export interface AstNode {
|
|
23
|
+
readonly type: string;
|
|
24
|
+
}
|
|
25
|
+
/** A single text edit. Produced by {@link RuleFixer}, applied by ESLint. */
|
|
26
|
+
export interface RuleFix {
|
|
27
|
+
readonly range: readonly [number, number];
|
|
28
|
+
readonly text: string;
|
|
29
|
+
}
|
|
30
|
+
/** The subset of ESLint's fixer used to build suggestions. */
|
|
31
|
+
export interface RuleFixer {
|
|
32
|
+
replaceText(node: AstNode, text: string): RuleFix;
|
|
33
|
+
insertTextAfter(node: AstNode, text: string): RuleFix;
|
|
34
|
+
}
|
|
35
|
+
/** One entry in a report's `suggest` list: a named, opt-in edit. */
|
|
36
|
+
export interface SuggestionDescriptor {
|
|
37
|
+
readonly messageId: string;
|
|
38
|
+
readonly data?: Readonly<Record<string, string>>;
|
|
39
|
+
fix(fixer: RuleFixer): RuleFix | null;
|
|
40
|
+
}
|
|
41
|
+
/** What a rule hands to `context.report`. */
|
|
42
|
+
export interface ReportDescriptor {
|
|
43
|
+
readonly node: AstNode;
|
|
44
|
+
readonly messageId: string;
|
|
45
|
+
readonly data?: Readonly<Record<string, string>>;
|
|
46
|
+
readonly suggest?: readonly SuggestionDescriptor[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The subset of `SourceCode` the rules read.
|
|
50
|
+
*
|
|
51
|
+
* `visitorKeys` is the parser's own map of which fields of each node type hold
|
|
52
|
+
* child nodes. Walking by that map rather than by a hand-written list of node
|
|
53
|
+
* types is what lets one traversal cover JSX, decorators, and every TypeScript
|
|
54
|
+
* node without this package knowing they exist.
|
|
55
|
+
*/
|
|
56
|
+
export interface SourceCode {
|
|
57
|
+
readonly visitorKeys?: Readonly<Record<string, readonly string[]>> | undefined;
|
|
58
|
+
getText(node?: AstNode): string;
|
|
59
|
+
getCommentsInside(node: AstNode): readonly unknown[];
|
|
60
|
+
/** ESLint 9. On ESLint 8 the equivalent lives on the context. */
|
|
61
|
+
getAncestors?(node: AstNode): readonly AstNode[];
|
|
62
|
+
/**
|
|
63
|
+
* Whatever the parser handed back alongside the tree, typed as `unknown`
|
|
64
|
+
* because every parser puts something different there and most put nothing.
|
|
65
|
+
* `./type-info.js` narrows the one shape this plugin can use.
|
|
66
|
+
*/
|
|
67
|
+
readonly parserServices?: unknown;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The subset of `RuleContext` the rules read.
|
|
71
|
+
*
|
|
72
|
+
* `sourceCode` and `getSourceCode()` are both optional because they belong to
|
|
73
|
+
* different ESLint majors: 9 has the property, 8 has the method, and 8.40
|
|
74
|
+
* onward has both. Same story for ancestors. `./ast.js` resolves each one once
|
|
75
|
+
* so no rule has to.
|
|
76
|
+
*/
|
|
77
|
+
export interface RuleContext {
|
|
78
|
+
readonly options: readonly unknown[];
|
|
79
|
+
readonly sourceCode?: SourceCode | undefined;
|
|
80
|
+
getSourceCode?(): SourceCode;
|
|
81
|
+
/** ESLint 8. Returns the ancestors of the node currently being visited. */
|
|
82
|
+
getAncestors?(): readonly AstNode[];
|
|
83
|
+
/** ESLint 8. On ESLint 9 the same object hangs off `SourceCode`. */
|
|
84
|
+
readonly parserServices?: unknown;
|
|
85
|
+
report(descriptor: ReportDescriptor): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A rule's visitor, keyed by node type or by ESLint selector.
|
|
89
|
+
*
|
|
90
|
+
* The index signature is what keeps this general: a rule returns an object
|
|
91
|
+
* literal with the handlers it needs and gets `AstNode` for the parameter by
|
|
92
|
+
* contextual typing, with no union of node types to keep in step with a parser.
|
|
93
|
+
*/
|
|
94
|
+
export interface RuleListener {
|
|
95
|
+
readonly [selector: string]: ((node: AstNode) => void) | undefined;
|
|
96
|
+
}
|
|
97
|
+
/** The documentation block of a rule's metadata. */
|
|
98
|
+
export interface RuleMetaDocs {
|
|
99
|
+
readonly description: string;
|
|
100
|
+
readonly recommended: boolean;
|
|
101
|
+
readonly url?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the rule needs a TypeScript program to say anything.
|
|
104
|
+
*
|
|
105
|
+
* The name is typescript-eslint's, and so is the meaning: a rule marked here
|
|
106
|
+
* belongs only in a preset a consumer opted into by configuring type-aware
|
|
107
|
+
* linting. `./configs.js` splits the presets on this flag, and a test holds
|
|
108
|
+
* the split to it, so a new type-aware rule cannot quietly land in a preset
|
|
109
|
+
* that runs over plain JavaScript.
|
|
110
|
+
*/
|
|
111
|
+
readonly requiresTypeChecking?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** A rule's metadata, as ESLint reads it. */
|
|
114
|
+
export interface RuleMeta {
|
|
115
|
+
readonly type: 'problem' | 'suggestion' | 'layout';
|
|
116
|
+
readonly docs: RuleMetaDocs;
|
|
117
|
+
readonly messages: Readonly<Record<string, string>>;
|
|
118
|
+
/** JSON Schema for the rule's options, one entry per positional option. */
|
|
119
|
+
readonly schema: readonly unknown[];
|
|
120
|
+
/** Whether reports may carry `suggest` entries. No rule here auto-fixes. */
|
|
121
|
+
readonly hasSuggestions?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/** A rule, in the object form both ESLint 8 and 9 accept. */
|
|
124
|
+
export interface RuleModule {
|
|
125
|
+
readonly meta: RuleMeta;
|
|
126
|
+
create(context: RuleContext): RuleListener;
|
|
127
|
+
}
|
|
128
|
+
/** The plugin object itself, as a flat or legacy config consumes it. */
|
|
129
|
+
export interface Plugin {
|
|
130
|
+
readonly meta: {
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly version: string;
|
|
133
|
+
};
|
|
134
|
+
readonly rules: Readonly<Record<string, RuleModule>>;
|
|
135
|
+
readonly configs: Readonly<Record<string, unknown>>;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,4EAA4E;AA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AAC;IACpC,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,YAAY,CAAC;CAC5C;AAED,wEAAwE;AACxE,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The slice of ESLint's rule API this plugin uses, declared structurally.
|
|
4
|
+
*
|
|
5
|
+
* Where ESLint's own types come from depends on the major: ESLint 9 ships them
|
|
6
|
+
* in the package, while an ESLint 8 consumer installs `@types/eslint`. This
|
|
7
|
+
* plugin's peer range spans both, so importing either would put one major's
|
|
8
|
+
* declarations into the emitted `.d.ts` and make the other half of the range
|
|
9
|
+
* type-check against rule types it does not have. Declaring the shapes instead
|
|
10
|
+
* keeps the published types self-contained, the same way the testing package
|
|
11
|
+
* declares `pretty-format`'s plugin shape rather than depending on it.
|
|
12
|
+
*
|
|
13
|
+
* The types are also deliberately looser than ESLint's in one place: {@link
|
|
14
|
+
* AstNode} carries nothing but `type`. A rule in this plugin has to run under
|
|
15
|
+
* `espree` and under `@typescript-eslint/parser`, and the second produces nodes
|
|
16
|
+
* (`TSAsExpression`, `TSNonNullExpression`) that no ESTree union contains. A
|
|
17
|
+
* narrow union would make handling them a type error, which is backwards: the
|
|
18
|
+
* TypeScript nodes are exactly the ones a security rule must not miss. Access
|
|
19
|
+
* to a node's fields goes through the guards in `./ast.js`, which check at
|
|
20
|
+
* runtime what the type system is not being asked to promise.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# explicit-class
|
|
2
|
+
|
|
3
|
+
Require an explicit sensitivity class when constructing a `SensitiveString`.
|
|
4
|
+
|
|
5
|
+
Severity in `recommended`: **warn**. Offers suggestions.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
The class decides how the value redacts and whether `equals()` compares in
|
|
10
|
+
constant time. A value constructed without one is not a weaker secret; it is a
|
|
11
|
+
broken object, since the constructor takes no default.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
Incorrect:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
new SensitiveString(value);
|
|
19
|
+
new core.SensitiveString(value);
|
|
20
|
+
|
|
21
|
+
// A placeholder names no class. The suggestion overwrites it rather than
|
|
22
|
+
// pushing it into the `label` position, where it is accepted and means nothing.
|
|
23
|
+
new SensitiveString(value, undefined);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Correct:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
new SensitiveString(value, 'credential');
|
|
30
|
+
new SensitiveString(value, 'sensitive', 'email');
|
|
31
|
+
new SensitiveString(value, klass);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
| Option | Default |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `constructorNames` | `SensitiveString` |
|
|
39
|
+
|
|
40
|
+
Set it to cover a re-exported or renamed constructor.
|
|
41
|
+
|
|
42
|
+
## Relationship to the type checker
|
|
43
|
+
|
|
44
|
+
The TypeScript signature already requires the class, so in a checked TypeScript
|
|
45
|
+
file this rule is a second line rather than the only one. It earns its place in
|
|
46
|
+
JavaScript sources, at `any`-typed call sites where the checker is silent, and
|
|
47
|
+
in a project whose build and lint run at different times.
|
|
48
|
+
|
|
49
|
+
## Suggestions
|
|
50
|
+
|
|
51
|
+
Two are offered, one per class, and neither is applied by `--fix`. The right
|
|
52
|
+
class is a security decision about the value being wrapped, and nothing in the
|
|
53
|
+
syntax reveals it. `credential` is the one to pick for anything compared against
|
|
54
|
+
user input.
|
|
55
|
+
|
|
56
|
+
A construction with no arguments at all is reported without suggestions: it is
|
|
57
|
+
broken in a way no sensitivity class fixes.
|
|
58
|
+
|
|
59
|
+
## Known limits
|
|
60
|
+
|
|
61
|
+
A spread argument makes the argument count unknowable, so
|
|
62
|
+
`new SensitiveString(...args)` is not reported.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# no-allow-unaudited
|
|
2
|
+
|
|
3
|
+
Disallow `allowUnaudited` on `fromWorkerPayload()` and `withWorkerPayload()`.
|
|
4
|
+
|
|
5
|
+
Severity in `recommended`: **error**.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
A `SensitiveString` crosses a worker thread or a child process through
|
|
10
|
+
`toWorkerPayload()`, which carries the sending context's `name`, `reason` and
|
|
11
|
+
`tags` along with the values. It cannot carry the context's `auditReveal`,
|
|
12
|
+
because a function does not survive structured clone or JSON, so a payload built
|
|
13
|
+
under an audited context arrives with `audited: true` and no hook.
|
|
14
|
+
|
|
15
|
+
`fromWorkerPayload()` refuses such a payload unless the receiving side supplies
|
|
16
|
+
a hook of its own, either through the `auditReveal` option or from an ambient
|
|
17
|
+
`withRevealContext()`. `allowUnaudited: true` is the way past that refusal, and
|
|
18
|
+
what it means is precise: the sender asked for every reveal of this value to be
|
|
19
|
+
recorded, and reveals in this thread will not be.
|
|
20
|
+
|
|
21
|
+
That is sometimes the right call, which is why the option exists. It is never a
|
|
22
|
+
call to make by accident, which is why this rule reports every use of it and
|
|
23
|
+
why the severity is error rather than warn: the flag is always deliberate, and
|
|
24
|
+
an inline disable comment is the right place for the reason it was deliberate.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
Incorrect:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
fromWorkerPayload(workerData, { allowUnaudited: true });
|
|
32
|
+
withWorkerPayload(workerData, { allowUnaudited: true }, ({ token }) => sign(token));
|
|
33
|
+
fromWorkerPayload(workerData, { auditReveal, allowUnaudited: true });
|
|
34
|
+
fromWorkerPayload(workerData, { allowUnaudited: skipAudit });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Correct:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
fromWorkerPayload(workerData, {
|
|
41
|
+
auditReveal: (value, details) => log.info('reveal', { klass: value.klass, ...details }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
withWorkerPayload(workerData, { auditReveal }, ({ token }) => sign(token));
|
|
45
|
+
|
|
46
|
+
// Inside a context that already carries a hook, which the reverse direction
|
|
47
|
+
// of the handoff relies on: a parent handler registered inside
|
|
48
|
+
// withRevealContext() consumes a worker's reply with no options at all.
|
|
49
|
+
fromWorkerPayload(message);
|
|
50
|
+
|
|
51
|
+
// The default spelled out.
|
|
52
|
+
fromWorkerPayload(workerData, { allowUnaudited: false });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
When the flag is the right answer:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
// eslint-disable-next-line @platform-sec/sensitive-string/no-allow-unaudited -- this worker only hashes the value and the digest is what gets recorded, downstream
|
|
59
|
+
fromWorkerPayload(workerData, { allowUnaudited: true });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Options
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"@platform-sec/sensitive-string/no-allow-unaudited": ["error", {
|
|
67
|
+
"payloadFunctions": ["fromWorkerPayload", "withWorkerPayload"]
|
|
68
|
+
}]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`payloadFunctions` names the functions the flag is read on. A configured list
|
|
73
|
+
replaces the default, for a project that wraps the two library functions in one
|
|
74
|
+
of its own.
|
|
75
|
+
|
|
76
|
+
## Known limits
|
|
77
|
+
|
|
78
|
+
- The flag is read from an object literal in the call. An options object built
|
|
79
|
+
elsewhere and passed by name is invisible to syntax, and so is a spread that
|
|
80
|
+
contributes it.
|
|
81
|
+
- A `false` literal and an explicit `undefined` are not reported. Any other
|
|
82
|
+
value is, a variable included, because `allowUnaudited: flag` is still a
|
|
83
|
+
deliberate decision to sometimes skip the audit.
|
|
84
|
+
- The functions are matched by name. A project that names something else
|
|
85
|
+
`fromWorkerPayload` is reported on that too, and `payloadFunctions` is the
|
|
86
|
+
fix.
|
|
87
|
+
- An aliased import is invisible for the same reason:
|
|
88
|
+
`import { fromWorkerPayload as fwp }` and then `fwp(workerData, { ... })` is
|
|
89
|
+
not reported, because resolving the alias needs types this rule does not
|
|
90
|
+
take. Add the local name to `payloadFunctions`.
|
|
91
|
+
- `allowUnaudited: 0`, `null` or `''` are reported although the runtime reads
|
|
92
|
+
anything but `true` as unset. That is deliberate: each is a confusing way to
|
|
93
|
+
write the default, and the rule would rather ask for `false`.
|