@platform-sec/eslint-plugin-sensitive-string 0.2.0 → 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/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/package.json +10 -10
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noPasswordFastHash = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `no-password-fast-hash`: a fast digest is not password storage.
|
|
6
|
+
*/
|
|
7
|
+
const ast_js_1 = require("../ast.js");
|
|
8
|
+
const docs_js_1 = require("../docs.js");
|
|
9
|
+
const options_js_1 = require("../options.js");
|
|
10
|
+
const RULE_NAME = 'no-password-fast-hash';
|
|
11
|
+
/**
|
|
12
|
+
* The library's fast digests.
|
|
13
|
+
*
|
|
14
|
+
* `hmac()` is here beside `hash()` because a key does not make a fast function
|
|
15
|
+
* slow. Peppering a password with an HMAC and storing the result is a real
|
|
16
|
+
* pattern, and a defensible one only *on top of* a KDF, never instead of it.
|
|
17
|
+
*/
|
|
18
|
+
const FAST_HASH_METHODS = new Set(['hash', 'hmac']);
|
|
19
|
+
/**
|
|
20
|
+
* What a password is called.
|
|
21
|
+
*
|
|
22
|
+
* Matched case-insensitively as a fragment, so `newPassword`, `user.passwd`
|
|
23
|
+
* and `plainPwd` all count. `secret`, `token` and `key` are deliberately
|
|
24
|
+
* absent: those are the values `hash()` is *for*, and a rule that reported
|
|
25
|
+
* them would be reporting the feature.
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_PASSWORD_NAMES = ['password', 'passwd', 'passphrase', 'pwd'];
|
|
28
|
+
/**
|
|
29
|
+
* The name of the value being hashed.
|
|
30
|
+
*
|
|
31
|
+
* The first name in the receiver's chain, which is the value itself rather
|
|
32
|
+
* than whatever holds it: `user.password.hash()` reports on `password`, and
|
|
33
|
+
* `passwordService.token.hash()` reports on `token`, which is to say not at
|
|
34
|
+
* all. A call is stepped through, so `getPassword().hash()` is reached.
|
|
35
|
+
*/
|
|
36
|
+
function hashedValueName(receiver) {
|
|
37
|
+
const [nearest] = (0, ast_js_1.calleeChainNames)(receiver);
|
|
38
|
+
return nearest;
|
|
39
|
+
}
|
|
40
|
+
function looksLikeAPassword(name, fragments) {
|
|
41
|
+
const lowered = name.toLowerCase();
|
|
42
|
+
for (const fragment of fragments) {
|
|
43
|
+
if (lowered.includes(fragment.toLowerCase())) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
exports.noPasswordFastHash = {
|
|
50
|
+
meta: {
|
|
51
|
+
type: 'problem',
|
|
52
|
+
docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow hashing a password with hash() or hmac(), which are fast by design', false),
|
|
53
|
+
messages: {
|
|
54
|
+
fastHash: '{{method}}() is a fast digest, not password storage: a wordlist runs through SHA-256 at billions of guesses a second, and a salt does not slow that down for whoever has the row it is stored in. Use hashForStorage() from @platform-sec/sensitive-string-kdf.',
|
|
55
|
+
},
|
|
56
|
+
schema: [
|
|
57
|
+
{
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
passwordNames: (0, options_js_1.nameListSchema)(),
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
create(context) {
|
|
67
|
+
const option = (0, options_js_1.optionObject)(context.options, 0);
|
|
68
|
+
const passwordNames = (0, options_js_1.readNameSet)(option, 'passwordNames', DEFAULT_PASSWORD_NAMES);
|
|
69
|
+
return {
|
|
70
|
+
CallExpression(node) {
|
|
71
|
+
const call = (0, ast_js_1.asMethodCall)(node);
|
|
72
|
+
if (call === undefined || !FAST_HASH_METHODS.has(call.method)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const name = hashedValueName(call.receiver);
|
|
76
|
+
if (name === undefined || !looksLikeAPassword(name, passwordNames)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
context.report({ node, messageId: 'fastHash', data: { method: call.method } });
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=no-password-fast-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-password-fast-hash.js","sourceRoot":"","sources":["../../src/rules/no-password-fast-hash.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAA2D;AAC3D,wCAAsC;AACtC,8CAA0E;AAG1E,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAsB,CAAC,U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GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC9D,OAAO;gBACT,CAAC;gBAED,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5C,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,CAAC;oBACnE,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACjF,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-stringify-sensitive.d.ts","sourceRoot":"","sources":["../../src/rules/no-stringify-sensitive.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AA0BlF,eAAO,MAAM,oBAAoB,EAAE,UA4ElC,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noStringifySensitive = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `no-stringify-sensitive`: `JSON.stringify` is the wrong tool for a structure
|
|
6
|
+
* holding a sensitive value, in both directions.
|
|
7
|
+
*/
|
|
8
|
+
const ast_js_1 = require("../ast.js");
|
|
9
|
+
const docs_js_1 = require("../docs.js");
|
|
10
|
+
const options_js_1 = require("../options.js");
|
|
11
|
+
const type_info_js_1 = require("../type-info.js");
|
|
12
|
+
const RULE_NAME = 'no-stringify-sensitive';
|
|
13
|
+
/**
|
|
14
|
+
* Whether a call is `JSON.stringify(...)`.
|
|
15
|
+
*
|
|
16
|
+
* Keyed on the method name with `JSON` somewhere along the chain, the same way
|
|
17
|
+
* the other call-matching rules work, so `globalThis.JSON.stringify` and a
|
|
18
|
+
* `JSON` reached through an alias both count. No option widens this: `JSON` is
|
|
19
|
+
* a global with one spelling, and a project's own serializer is a different
|
|
20
|
+
* rule's subject.
|
|
21
|
+
*/
|
|
22
|
+
function isJsonStringify(node) {
|
|
23
|
+
const callee = (0, ast_js_1.calleeOf)(node);
|
|
24
|
+
if (callee === undefined || callee.type !== 'MemberExpression') {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if ((0, ast_js_1.staticPropertyName)(callee) !== 'stringify') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return (0, ast_js_1.calleeChainNames)(callee).slice(1).includes('JSON');
|
|
31
|
+
}
|
|
32
|
+
exports.noStringifySensitive = {
|
|
33
|
+
meta: {
|
|
34
|
+
type: 'problem',
|
|
35
|
+
docs: {
|
|
36
|
+
...(0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow JSON.stringify on a structure whose type carries a sensitive value', true),
|
|
37
|
+
requiresTypeChecking: true,
|
|
38
|
+
},
|
|
39
|
+
messages: {
|
|
40
|
+
stringifySensitive: 'JSON.stringify writes the redaction of this {{name}}, not its value, and nothing at the call site says so. Use safeStringify() when redacted JSON is what you want, or serialize() on the field when the value has to reach the other side.',
|
|
41
|
+
stringifySerialized: 'A serialize() result reaches JSON.stringify here: a plain object holding the raw value, which it writes out in the clear. Send that only over the transport it was serialized for, and use safeStringify() for anything going to a log or a store.',
|
|
42
|
+
missingTypeInformation: 'This rule needs type information and has none, so it is reporting nothing at all. Configure typescript-eslint type-aware linting for this file, or apply the disable-type-checked preset to files that have no TypeScript program.',
|
|
43
|
+
},
|
|
44
|
+
schema: [
|
|
45
|
+
{
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
sensitiveTypes: (0, options_js_1.nameListSchema)(),
|
|
49
|
+
serializedTypes: (0, options_js_1.nameListSchema)(),
|
|
50
|
+
},
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
create(context) {
|
|
56
|
+
const option = (0, options_js_1.optionObject)(context.options, 0);
|
|
57
|
+
const names = {
|
|
58
|
+
sensitive: (0, options_js_1.readNameSet)(option, 'sensitiveTypes', type_info_js_1.DEFAULT_SENSITIVE_TYPES),
|
|
59
|
+
serialized: (0, options_js_1.readNameSet)(option, 'serializedTypes', type_info_js_1.DEFAULT_SERIALIZED_TYPES),
|
|
60
|
+
};
|
|
61
|
+
const services = (0, type_info_js_1.getTypeServices)(context);
|
|
62
|
+
if (services === undefined) {
|
|
63
|
+
// Silence would be the worse failure. A rule that reports nothing looks
|
|
64
|
+
// exactly like a rule that found nothing, and this one is read as
|
|
65
|
+
// "no sensitive value reaches JSON.stringify in this file".
|
|
66
|
+
return {
|
|
67
|
+
Program(node) {
|
|
68
|
+
context.report({ node, messageId: 'missingTypeInformation' });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
CallExpression(node) {
|
|
74
|
+
if (!isJsonStringify(node)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Only the first argument. The second is a replacer and the third is
|
|
78
|
+
// an indent, and neither is written into the output as a value.
|
|
79
|
+
const [value] = (0, ast_js_1.callArguments)(node);
|
|
80
|
+
if (value === undefined) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const match = (0, type_info_js_1.findSensitiveType)(value, services, names);
|
|
84
|
+
if (match === undefined) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
context.report({
|
|
88
|
+
node: value,
|
|
89
|
+
messageId: match.serialized ? 'stringifySerialized' : 'stringifySensitive',
|
|
90
|
+
data: { name: match.name },
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=no-stringify-sensitive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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J,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-safe-log.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-safe-log.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AAIlF,eAAO,MAAM,aAAa,EAAE,UAoF3B,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preferSafeLog = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `prefer-safe-log`: redact before the logger, not inside it.
|
|
6
|
+
*/
|
|
7
|
+
const ast_js_1 = require("../ast.js");
|
|
8
|
+
const docs_js_1 = require("../docs.js");
|
|
9
|
+
const log_calls_js_1 = require("../log-calls.js");
|
|
10
|
+
const options_js_1 = require("../options.js");
|
|
11
|
+
const type_info_js_1 = require("../type-info.js");
|
|
12
|
+
const RULE_NAME = 'prefer-safe-log';
|
|
13
|
+
exports.preferSafeLog = {
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'suggestion',
|
|
16
|
+
docs: {
|
|
17
|
+
...(0, docs_js_1.ruleDocs)(RULE_NAME, 'Prefer safeLog() when logging a structure whose type carries a sensitive value', false),
|
|
18
|
+
requiresTypeChecking: true,
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
preferSafeLog: 'This structure holds a {{name}}, so what gets written depends on which serializer the transport happens to call. safeLog() redacts the copy before the logger sees it, which does not.',
|
|
22
|
+
logsSerialized: 'A serialize() result reaches this logger: a plain object carrying the raw value, which nothing redacts, because it is the one shape toString() and toJSON() cannot reach. Pass it through safeLog(), which replaces it with the redaction its class would produce.',
|
|
23
|
+
missingTypeInformation: 'This rule needs type information and has none, so it is reporting nothing at all. Configure typescript-eslint type-aware linting for this file, or apply the disable-type-checked preset to files that have no TypeScript program.',
|
|
24
|
+
},
|
|
25
|
+
schema: [
|
|
26
|
+
{
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
logFunctions: (0, options_js_1.nameListSchema)(),
|
|
30
|
+
logObjects: (0, options_js_1.nameListSchema)(),
|
|
31
|
+
sensitiveTypes: (0, options_js_1.nameListSchema)(),
|
|
32
|
+
serializedTypes: (0, options_js_1.nameListSchema)(),
|
|
33
|
+
},
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
create(context) {
|
|
39
|
+
const option = (0, options_js_1.optionObject)(context.options, 0);
|
|
40
|
+
const logFunctions = (0, options_js_1.readNameSet)(option, 'logFunctions', log_calls_js_1.DEFAULT_LOG_FUNCTIONS);
|
|
41
|
+
const logObjects = (0, options_js_1.readNameSet)(option, 'logObjects', log_calls_js_1.DEFAULT_LOG_OBJECTS);
|
|
42
|
+
const names = {
|
|
43
|
+
sensitive: (0, options_js_1.readNameSet)(option, 'sensitiveTypes', type_info_js_1.DEFAULT_SENSITIVE_TYPES),
|
|
44
|
+
serialized: (0, options_js_1.readNameSet)(option, 'serializedTypes', type_info_js_1.DEFAULT_SERIALIZED_TYPES),
|
|
45
|
+
};
|
|
46
|
+
const services = (0, type_info_js_1.getTypeServices)(context);
|
|
47
|
+
if (services === undefined) {
|
|
48
|
+
return {
|
|
49
|
+
Program(node) {
|
|
50
|
+
context.report({ node, messageId: 'missingTypeInformation' });
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
CallExpression(node) {
|
|
56
|
+
if (!(0, log_calls_js_1.isLogCall)(node, logFunctions, logObjects)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const argument of (0, ast_js_1.callArguments)(node)) {
|
|
60
|
+
// Every argument, not just the first: `logger.info('sending', payload)`
|
|
61
|
+
// puts the message in one and the structure in the next.
|
|
62
|
+
const match = (0, type_info_js_1.findSensitiveType)(argument, services, names);
|
|
63
|
+
if (match === undefined) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Logging the value itself, or a plain list of them, is the
|
|
67
|
+
// documented way to do it: the class redacts itself through
|
|
68
|
+
// `util.inspect` and through `toJSON`, and an array delegates to each
|
|
69
|
+
// element. What this rule is about is a record that holds one, where
|
|
70
|
+
// the redaction becomes the transport's business. A serialize()
|
|
71
|
+
// result is reported wherever it sits, because nothing redacts it.
|
|
72
|
+
if (!match.serialized && !match.throughProperty) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
context.report({
|
|
76
|
+
node: argument,
|
|
77
|
+
messageId: match.serialized ? 'logsSerialized' : 'preferSafeLog',
|
|
78
|
+
data: { name: match.name },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=prefer-safe-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-safe-log.js","sourceRoot":"","sources":["../../src/rules/prefer-safe-log.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAA0C;AAC1C,wCAAsC;AACtC,kDAAwF;AACxF,8CAA0E;AAC1E,kDAKyB;AAGzB,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEvB,QAAA,aAAa,GAAe;IACvC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,GAAG,IAAA,kBAAQ,EACT,SAAS,EACT,gFAAgF,EAChF,KAAK,CACN;YACD,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,aAAa,EACX,wLAAwL;YAC1L,cAAc,EACZ,oQAAoQ;YACtQ,sBAAsB,EACpB,oOAAoO;SACvO;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,YAAY,EAAE,IAAA,2BAAc,GAAE;oBAC9B,UAAU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AK,CAAC,CAAC;oBAC3D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;wBACxB,SAAS;oBACX,CAAC;oBAED,4DAA4D;oBAC5D,4DAA4D;oBAC5D,sEAAsE;oBACtE,qEAAqE;oBACrE,gEAAgE;oBAChE,mEAAmE;oBACnE,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;wBAChD,SAAS;oBACX,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,QAAQ;wBACd,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe;wBAChE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE;qBAC3B,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-reveal-context.d.ts","sourceRoot":"","sources":["../../src/rules/require-reveal-context.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AAoGlF,eAAO,MAAM,oBAAoB,EAAE,UA0FlC,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireRevealContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `require-reveal-context`: a reveal should say who is reading and why.
|
|
6
|
+
*/
|
|
7
|
+
const ast_js_1 = require("../ast.js");
|
|
8
|
+
const docs_js_1 = require("../docs.js");
|
|
9
|
+
const options_js_1 = require("../options.js");
|
|
10
|
+
const type_info_js_1 = require("../type-info.js");
|
|
11
|
+
const RULE_NAME = 'require-reveal-context';
|
|
12
|
+
/**
|
|
13
|
+
* Functions that install a reveal context for everything they run.
|
|
14
|
+
*
|
|
15
|
+
* A reveal inside one of these needs no argument of its own: the context comes
|
|
16
|
+
* from `AsyncLocalStorage`, and the audit record is written either way.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_CONTEXT_FUNCTIONS = ['withRevealContext', 'withAuditedReveals'];
|
|
19
|
+
/**
|
|
20
|
+
* The reads that take a `RevealContext`.
|
|
21
|
+
*
|
|
22
|
+
* `hash()` and `hmac()` are here because the library audits them exactly as it
|
|
23
|
+
* audits a reveal: they read the raw value, charge the reveal budget, and write
|
|
24
|
+
* an audit record. A record saying a digest of a credential was taken, with
|
|
25
|
+
* nothing about who took it or why, is the gap this rule exists to close.
|
|
26
|
+
*
|
|
27
|
+
* `mask()` is a partial reveal that returns a plain string, and `serialize()`
|
|
28
|
+
* returns the raw value in a wire object, so both belong here for a plainer
|
|
29
|
+
* reason than the digests do.
|
|
30
|
+
*
|
|
31
|
+
* One table rather than a list of names and a second list of the typed ones,
|
|
32
|
+
* so the two cannot come to disagree about a method that is in one and not the
|
|
33
|
+
* other. What is not here is the transforms, `substring` and `map` and the
|
|
34
|
+
* rest: they audit too, and requiring a context on `token.trim()` would make
|
|
35
|
+
* the rule unusable long before it made an audit log better.
|
|
36
|
+
*/
|
|
37
|
+
const CONTEXT_METHODS = new Map([
|
|
38
|
+
[ast_js_1.REVEAL_METHOD, { index: 0, typedOnly: false }],
|
|
39
|
+
['mask', { index: 1, typedOnly: true }],
|
|
40
|
+
['hash', { index: 2, typedOnly: true }],
|
|
41
|
+
['hmac', { index: 3, typedOnly: true }],
|
|
42
|
+
['serialize', { index: 0, typedOnly: true }],
|
|
43
|
+
]);
|
|
44
|
+
/**
|
|
45
|
+
* Whether the reveal sits inside a call that installs a context.
|
|
46
|
+
*
|
|
47
|
+
* The check is lexical, so it sees the ordinary shape,
|
|
48
|
+
* `withRevealContext(ctx, async () => { secret.reveal(); })`, and misses a
|
|
49
|
+
* reveal in a function that is merely *called* from inside one. That miss is
|
|
50
|
+
* the reason this rule ships as a warning: it costs a needless warning on
|
|
51
|
+
* correct code, never a missed one on incorrect code.
|
|
52
|
+
*/
|
|
53
|
+
function insideContextCall(ancestors, contextFunctions) {
|
|
54
|
+
return ancestors.some((ancestor) => {
|
|
55
|
+
if (ancestor.type !== 'CallExpression') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const callee = (0, ast_js_1.calleeOf)(ancestor);
|
|
59
|
+
if (callee === undefined) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const [called] = (0, ast_js_1.calleeChainNames)(callee);
|
|
63
|
+
return called !== undefined && contextFunctions.has(called);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether an object literal spells out a `reason` property.
|
|
68
|
+
*
|
|
69
|
+
* A spread counts as satisfied. Reading what `{ ...base }` contributes needs
|
|
70
|
+
* types this rule does not have, and warning on a context that is very likely
|
|
71
|
+
* complete would train people to disable the rule.
|
|
72
|
+
*/
|
|
73
|
+
function hasReason(objectExpression) {
|
|
74
|
+
return (0, ast_js_1.objectProperties)(objectExpression).some((property) => (0, ast_js_1.isSpread)(property) || (0, ast_js_1.staticKeyName)(property) === 'reason');
|
|
75
|
+
}
|
|
76
|
+
exports.requireRevealContext = {
|
|
77
|
+
meta: {
|
|
78
|
+
type: 'suggestion',
|
|
79
|
+
docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Require an audit context on reveal(), and on mask(), hash(), hmac() and serialize() where types are available, from an argument or an enclosing withRevealContext()', false),
|
|
80
|
+
messages: {
|
|
81
|
+
missingContext: '{{method}}() has no audit context. Pass { name: "..." } or run the call inside {{contextFunction}}() so the access is attributable.',
|
|
82
|
+
missingReason: '{{method}}() context has no "reason". Add one so the audit record says why the value was read, not just who read it.',
|
|
83
|
+
},
|
|
84
|
+
schema: [
|
|
85
|
+
{
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
requireReason: { type: 'boolean' },
|
|
89
|
+
contextFunctions: (0, options_js_1.nameListSchema)(),
|
|
90
|
+
sensitiveTypes: (0, options_js_1.nameListSchema)(),
|
|
91
|
+
},
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
create(context) {
|
|
97
|
+
const option = (0, options_js_1.optionObject)(context.options, 0);
|
|
98
|
+
const requireReason = (0, options_js_1.readBoolean)(option, 'requireReason', false);
|
|
99
|
+
const contextFunctions = (0, options_js_1.readNameSet)(option, 'contextFunctions', DEFAULT_CONTEXT_FUNCTIONS);
|
|
100
|
+
const sensitiveTypes = (0, options_js_1.readNameSet)(option, 'sensitiveTypes', type_info_js_1.DEFAULT_SENSITIVE_TYPES);
|
|
101
|
+
const [suggestedFunction] = contextFunctions;
|
|
102
|
+
const services = (0, type_info_js_1.getTypeServices)(context);
|
|
103
|
+
return {
|
|
104
|
+
CallExpression(node) {
|
|
105
|
+
const call = (0, ast_js_1.asMethodCall)(node);
|
|
106
|
+
if (call === undefined) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const method = CONTEXT_METHODS.get(call.method);
|
|
110
|
+
if (method === undefined) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// The lexical check first: it is a walk up the ancestors, where the
|
|
114
|
+
// receiver check builds and searches a type.
|
|
115
|
+
if (insideContextCall((0, ast_js_1.getAncestors)(context, node), contextFunctions)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (method.typedOnly &&
|
|
119
|
+
(services === undefined || !(0, type_info_js_1.isSensitiveWrapper)(call.receiver, services, sensitiveTypes))) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const index = method.index;
|
|
123
|
+
const args = (0, ast_js_1.callArguments)(node);
|
|
124
|
+
// A spread ahead of the context moves everything after it, so which
|
|
125
|
+
// argument is the context stops being a question syntax can answer.
|
|
126
|
+
if (args.slice(0, index + 1).some((argument) => (0, ast_js_1.isSpread)(argument))) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const given = args[index];
|
|
130
|
+
if (given === undefined || (0, ast_js_1.isExplicitUndefined)(given)) {
|
|
131
|
+
context.report({
|
|
132
|
+
node,
|
|
133
|
+
messageId: 'missingContext',
|
|
134
|
+
data: {
|
|
135
|
+
method: call.method,
|
|
136
|
+
contextFunction: suggestedFunction ?? 'withRevealContext',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const givenContext = (0, ast_js_1.unwrap)(given);
|
|
142
|
+
if (requireReason && givenContext.type === 'ObjectExpression' && !hasReason(givenContext)) {
|
|
143
|
+
context.report({ node, messageId: 'missingReason', data: { method: call.method } });
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=require-reveal-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require-reveal-context.js","sourceRoot":"","sources":["../../src/rules/require-reveal-context.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAYmB;AACnB,wCAAsC;AACtC,8CAAuF;AACvF,kDAA+F;AAG/F,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,yBAAyB,GAAsB,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC;AAuBjG;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,eAAe,GAAyC,IAAI,GAAG,CAAC;IACpE,CAAC,sBAAa,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC/C,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,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Context } from './types.js';
|
|
2
|
+
/** A `ts.Symbol`, as far as this module reads one. */
|
|
3
|
+
interface SymbolLike {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
}
|
|
6
|
+
/** A `ts.Node`. Opaque here: it is only ever handed back to the checker. */
|
|
7
|
+
interface TsNodeLike {
|
|
8
|
+
readonly kind: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A `ts.Type`, as far as this module reads one.
|
|
12
|
+
*
|
|
13
|
+
* `types` is the field a union and an intersection both carry, which is why
|
|
14
|
+
* this module never needs `isUnion()` or the `TypeFlags` enum behind it, and
|
|
15
|
+
* so never needs `typescript` itself at runtime.
|
|
16
|
+
*/
|
|
17
|
+
interface TypeLike {
|
|
18
|
+
readonly symbol?: SymbolLike | undefined;
|
|
19
|
+
readonly aliasSymbol?: SymbolLike | undefined;
|
|
20
|
+
/** The constituents of a union or an intersection. Absent on anything else. */
|
|
21
|
+
readonly types?: readonly TypeLike[] | undefined;
|
|
22
|
+
getProperties(): readonly SymbolLike[];
|
|
23
|
+
/** The classes and interfaces extended. `undefined` for anything else. */
|
|
24
|
+
getBaseTypes?(): readonly TypeLike[] | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** One index signature of a type, as `{ [k: string]: T }` declares. */
|
|
27
|
+
interface IndexInfoLike {
|
|
28
|
+
readonly type: TypeLike;
|
|
29
|
+
}
|
|
30
|
+
/** A `ts.TypeChecker`, as far as this module calls one. */
|
|
31
|
+
interface TypeCheckerLike {
|
|
32
|
+
getTypeAtLocation(node: TsNodeLike): TypeLike;
|
|
33
|
+
getTypeOfSymbolAtLocation(symbol: SymbolLike, node: TsNodeLike): TypeLike;
|
|
34
|
+
isArrayType(type: TypeLike): boolean;
|
|
35
|
+
isTupleType(type: TypeLike): boolean;
|
|
36
|
+
/** Public since TypeScript 4.2. Guarded anyway, being duck-typed. */
|
|
37
|
+
getTypeArguments?(type: TypeLike): readonly TypeLike[];
|
|
38
|
+
/** Public since TypeScript 4.7. Guarded anyway, being duck-typed. */
|
|
39
|
+
getIndexInfosOfType?(type: TypeLike): readonly IndexInfoLike[];
|
|
40
|
+
}
|
|
41
|
+
/** The checker, plus the one lookup a rule needs to reach it from an ESLint node. */
|
|
42
|
+
export interface TypeServices {
|
|
43
|
+
readonly checker: TypeCheckerLike;
|
|
44
|
+
/**
|
|
45
|
+
* The TypeScript node an ESLint node came from.
|
|
46
|
+
*
|
|
47
|
+
* It is both what a type is read from and the location the read happens at,
|
|
48
|
+
* which is why the walk carries it rather than resolving a type once: every
|
|
49
|
+
* `getTypeOfSymbolAtLocation` below needs somewhere to stand.
|
|
50
|
+
*/
|
|
51
|
+
tsNodeOf(node: AstNode): TsNodeLike | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Type names whose presence in a structure is what the rules report. */
|
|
54
|
+
export interface SensitiveTypeNames {
|
|
55
|
+
/** A live wrapper, which redacts itself in every path the library controls. */
|
|
56
|
+
readonly sensitive: ReadonlySet<string>;
|
|
57
|
+
/** A `serialize()` result: a plain object holding the raw value. */
|
|
58
|
+
readonly serialized: ReadonlySet<string>;
|
|
59
|
+
}
|
|
60
|
+
/** Where a sensitive type was found, and what kind it was. */
|
|
61
|
+
export interface SensitiveTypeMatch {
|
|
62
|
+
/** The type name that matched, for the finding's message. */
|
|
63
|
+
readonly name: string;
|
|
64
|
+
/** Whether it was a wire-format type rather than a live wrapper. */
|
|
65
|
+
readonly serialized: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Whether it was reached through a property or an index signature, rather
|
|
68
|
+
* than being the value itself or an element of a plain list of them.
|
|
69
|
+
*
|
|
70
|
+
* `console.log(token)` and `console.log(tokens)` are the documented way to
|
|
71
|
+
* log a sensitive value: the class redacts itself, and a list delegates to
|
|
72
|
+
* each element. `console.log(user)` is a different thing, because whatever
|
|
73
|
+
* redacts now is whichever serializer the transport happens to install.
|
|
74
|
+
* `prefer-safe-log` keys on this; `no-stringify-sensitive` does not, because
|
|
75
|
+
* `JSON.stringify(token)` writes the placeholder either way.
|
|
76
|
+
*/
|
|
77
|
+
readonly throughProperty: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** The library's own names, which every project gets without configuring any. */
|
|
80
|
+
export declare const DEFAULT_SENSITIVE_TYPES: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* The wire format's name.
|
|
83
|
+
*
|
|
84
|
+
* Matched exactly, never by prefix: `SerializedSensitiveString` is the shape
|
|
85
|
+
* `serialize()` produces and `deserialize()` consumes, so a rule that reported
|
|
86
|
+
* every name containing "Sensitive" would report the recommended transmission
|
|
87
|
+
* path at the point where it is correct.
|
|
88
|
+
*/
|
|
89
|
+
export declare const DEFAULT_SERIALIZED_TYPES: readonly string[];
|
|
90
|
+
/**
|
|
91
|
+
* The type checker for the file being linted, or `undefined` when the consumer
|
|
92
|
+
* has not configured type-aware linting.
|
|
93
|
+
*
|
|
94
|
+
* Both spellings are tried because they belong to different ESLint majors: 9
|
|
95
|
+
* hangs `parserServices` off `SourceCode`, 8 hangs it off the rule context.
|
|
96
|
+
* `program` is `null` rather than absent under `@typescript-eslint/parser`
|
|
97
|
+
* without a `project`, which is the ordinary "TypeScript parser, no types"
|
|
98
|
+
* configuration and has to read as "no type information" rather than as a
|
|
99
|
+
* malformed services object.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getTypeServices(context: RuleContext): TypeServices | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Whether an expression *is* a sensitive wrapper, rather than carrying one.
|
|
104
|
+
*
|
|
105
|
+
* The question `findSensitiveType` answers is "does this structure hold a
|
|
106
|
+
* value", which is what a serializer walks. This one asks whether the
|
|
107
|
+
* expression in hand is the wrapper itself, which is what a method call needs:
|
|
108
|
+
* `bcrypt.hash(...)` and `token.hash(...)` are the same syntax, and only the
|
|
109
|
+
* receiver's type separates them.
|
|
110
|
+
*
|
|
111
|
+
* Properties are therefore not followed. A `{ token: SensitiveString }` holds
|
|
112
|
+
* one and has no `hash` method of its own, so following its properties would
|
|
113
|
+
* report `user.hash()` on a `user` that has an unrelated one. Unions,
|
|
114
|
+
* intersections and base classes are followed: `SensitiveString | undefined`
|
|
115
|
+
* is what an optional chain produces, and `class ApiKey extends
|
|
116
|
+
* SensitiveString` is still a wrapper.
|
|
117
|
+
*/
|
|
118
|
+
export declare function isSensitiveWrapper(node: AstNode, services: TypeServices, names: ReadonlySet<string>): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The sensitive type an expression's type carries, or `undefined`.
|
|
121
|
+
*
|
|
122
|
+
* The search stops as soon as it finds one reached through a property, which
|
|
123
|
+
* is the finding both rules most want to report. A match on the value itself,
|
|
124
|
+
* or on an element of a list of them, is kept but does not end the walk: a
|
|
125
|
+
* `SensitiveString` in hand says nothing about whether the same expression
|
|
126
|
+
* also holds one inside a record, and the two produce different findings.
|
|
127
|
+
*
|
|
128
|
+
* Visited types are tracked separately per arrival, because the same type
|
|
129
|
+
* reached directly and reached through a property is two different answers,
|
|
130
|
+
* and the first must not suppress the second.
|
|
131
|
+
*/
|
|
132
|
+
export declare function findSensitiveType(node: AstNode, services: TypeServices, names: SensitiveTypeNames): SensitiveTypeMatch | undefined;
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=type-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-info.d.ts","sourceRoot":"","sources":["../src/type-info.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvD,sDAAsD;AACtD,UAAU,UAAU;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,4EAA4E;AAC5E,UAAU,UAAU;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,UAAU,QAAQ;IAChB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,UAAU,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