@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.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +193 -2
  3. package/dist/ast.d.ts +172 -0
  4. package/dist/ast.d.ts.map +1 -0
  5. package/dist/ast.js +418 -0
  6. package/dist/ast.js.map +1 -0
  7. package/dist/configs.d.ts +38 -0
  8. package/dist/configs.d.ts.map +1 -0
  9. package/dist/configs.js +131 -0
  10. package/dist/configs.js.map +1 -0
  11. package/dist/docs.d.ts +28 -0
  12. package/dist/docs.d.ts.map +1 -0
  13. package/dist/docs.js +33 -0
  14. package/dist/docs.js.map +1 -0
  15. package/dist/index.d.ts +44 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +117 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/log-calls.d.ts +28 -0
  20. package/dist/log-calls.d.ts.map +1 -0
  21. package/dist/log-calls.js +80 -0
  22. package/dist/log-calls.js.map +1 -0
  23. package/dist/options.d.ts +32 -0
  24. package/dist/options.d.ts.map +1 -0
  25. package/dist/options.js +56 -0
  26. package/dist/options.js.map +1 -0
  27. package/dist/rules/explicit-class.d.ts +3 -0
  28. package/dist/rules/explicit-class.d.ts.map +1 -0
  29. package/dist/rules/explicit-class.js +93 -0
  30. package/dist/rules/explicit-class.js.map +1 -0
  31. package/dist/rules/no-allow-unaudited.d.ts +3 -0
  32. package/dist/rules/no-allow-unaudited.d.ts.map +1 -0
  33. package/dist/rules/no-allow-unaudited.js +92 -0
  34. package/dist/rules/no-allow-unaudited.js.map +1 -0
  35. package/dist/rules/no-credential-equality.d.ts +3 -0
  36. package/dist/rules/no-credential-equality.d.ts.map +1 -0
  37. package/dist/rules/no-credential-equality.js +146 -0
  38. package/dist/rules/no-credential-equality.js.map +1 -0
  39. package/dist/rules/no-log-reveal.d.ts +3 -0
  40. package/dist/rules/no-log-reveal.d.ts.map +1 -0
  41. package/dist/rules/no-log-reveal.js +67 -0
  42. package/dist/rules/no-log-reveal.js.map +1 -0
  43. package/dist/rules/no-network-sensitive.d.ts +3 -0
  44. package/dist/rules/no-network-sensitive.d.ts.map +1 -0
  45. package/dist/rules/no-network-sensitive.js +106 -0
  46. package/dist/rules/no-network-sensitive.js.map +1 -0
  47. package/dist/rules/no-password-fast-hash.d.ts +3 -0
  48. package/dist/rules/no-password-fast-hash.d.ts.map +1 -0
  49. package/dist/rules/no-password-fast-hash.js +84 -0
  50. package/dist/rules/no-password-fast-hash.js.map +1 -0
  51. package/dist/rules/no-stringify-sensitive.d.ts +3 -0
  52. package/dist/rules/no-stringify-sensitive.d.ts.map +1 -0
  53. package/dist/rules/no-stringify-sensitive.js +96 -0
  54. package/dist/rules/no-stringify-sensitive.js.map +1 -0
  55. package/dist/rules/prefer-safe-log.d.ts +3 -0
  56. package/dist/rules/prefer-safe-log.d.ts.map +1 -0
  57. package/dist/rules/prefer-safe-log.js +85 -0
  58. package/dist/rules/prefer-safe-log.js.map +1 -0
  59. package/dist/rules/require-reveal-context.d.ts +3 -0
  60. package/dist/rules/require-reveal-context.d.ts.map +1 -0
  61. package/dist/rules/require-reveal-context.js +149 -0
  62. package/dist/rules/require-reveal-context.js.map +1 -0
  63. package/dist/type-info.d.ts +134 -0
  64. package/dist/type-info.d.ts.map +1 -0
  65. package/dist/type-info.js +282 -0
  66. package/dist/type-info.js.map +1 -0
  67. package/dist/types.d.ts +137 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +23 -0
  70. package/dist/types.js.map +1 -0
  71. package/docs/rules/explicit-class.md +62 -0
  72. package/docs/rules/no-allow-unaudited.md +93 -0
  73. package/docs/rules/no-credential-equality.md +69 -0
  74. package/docs/rules/no-log-reveal.md +104 -0
  75. package/docs/rules/no-network-sensitive.md +74 -0
  76. package/docs/rules/no-password-fast-hash.md +95 -0
  77. package/docs/rules/no-stringify-sensitive.md +144 -0
  78. package/docs/rules/prefer-safe-log.md +131 -0
  79. package/docs/rules/require-reveal-context.md +128 -0
  80. package/package.json +49 -3
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noCredentialEquality: RuleModule;
3
+ //# sourceMappingURL=no-credential-equality.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-credential-equality.d.ts","sourceRoot":"","sources":["../../src/rules/no-credential-equality.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAIV,UAAU,EAGX,MAAM,aAAa,CAAC;AAuGrB,eAAO,MAAM,oBAAoB,EAAE,UAmElC,CAAC"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noCredentialEquality = void 0;
4
+ /**
5
+ * `no-credential-equality`: comparing a revealed value with `===` leaks timing.
6
+ */
7
+ const ast_js_1 = require("../ast.js");
8
+ const docs_js_1 = require("../docs.js");
9
+ const RULE_NAME = 'no-credential-equality';
10
+ /** The operators that compare two values and return early on the first difference. */
11
+ const EQUALITY_OPERATORS = new Set(['===', '==', '!==', '!=']);
12
+ /** Operators whose result the `.equals()` form has to negate. */
13
+ const NEGATED_OPERATORS = new Set(['!==', '!=']);
14
+ /** A reveal call, if that is what the operand is. */
15
+ function asRevealCall(node) {
16
+ const call = (0, ast_js_1.asMethodCall)(node);
17
+ return call !== undefined && call.method === ast_js_1.REVEAL_METHOD ? call : undefined;
18
+ }
19
+ /**
20
+ * The audit context a reveal carries, or `undefined` if it carries none.
21
+ *
22
+ * A placeholder `undefined` counts as none, so the rewrite does not copy
23
+ * `equals(other, undefined)` into the file and does not treat two reveals as
24
+ * having a context each when only one really does.
25
+ */
26
+ function revealContext(reveal) {
27
+ if (reveal === undefined) {
28
+ return undefined;
29
+ }
30
+ const [context] = (0, ast_js_1.callArguments)(reveal.call);
31
+ return context === undefined || (0, ast_js_1.isExplicitUndefined)(context) ? undefined : context;
32
+ }
33
+ /**
34
+ * The `.equals()` rewrite for one comparison, or `undefined` when it cannot be
35
+ * written safely.
36
+ *
37
+ * The result is offered as a suggestion and never as an auto-fix. `--fix`
38
+ * rewrites a file without anyone reading the diff, and the two forms are not
39
+ * interchangeable: `equals()` on a `credential` compares in constant time, and
40
+ * it can throw where `reveal()` did not, on an expired value or under a policy
41
+ * that demands a context. That difference is the point of the rule and exactly
42
+ * the reason a person, not a batch job, should accept it.
43
+ *
44
+ * Three cases are declined outright:
45
+ *
46
+ * - An optional call. `x?.reveal() === y` yields `false` when `x` is nullish
47
+ * while `x?.equals(y)` yields `undefined`, and a suggestion must not change
48
+ * which branch runs.
49
+ * - A comment inside the comparison, which a text replacement would delete.
50
+ * - A reveal on both sides carrying different contexts, where the rewrite would
51
+ * have to drop one of the two audit records.
52
+ * - A comma expression on the other side. Its text carries a top-level comma,
53
+ * which inside an argument list would split into two arguments and quietly
54
+ * promote its second half to the audit context.
55
+ */
56
+ function buildSuggestion(sourceCode, node, operator, reveal, other) {
57
+ if (reveal.optional) {
58
+ return undefined;
59
+ }
60
+ if (sourceCode.getCommentsInside(node).length > 0) {
61
+ return undefined;
62
+ }
63
+ if (other.type === 'SequenceExpression') {
64
+ return undefined;
65
+ }
66
+ const otherReveal = asRevealCall(other);
67
+ if (otherReveal !== undefined) {
68
+ if (otherReveal.optional) {
69
+ return undefined;
70
+ }
71
+ if (revealContext(reveal) !== undefined && revealContext(otherReveal) !== undefined) {
72
+ return undefined;
73
+ }
74
+ }
75
+ const receiver = sourceCode.getText(reveal.receiver);
76
+ const comparand = sourceCode.getText(otherReveal === undefined ? other : otherReveal.receiver);
77
+ // `equals(other, ctx?)` takes the context in second position, so a context
78
+ // written on either reveal survives the rewrite. Only one can, which is why
79
+ // a pair that both carry one is declined above.
80
+ const contextArgument = revealContext(reveal) ?? revealContext(otherReveal);
81
+ const context = contextArgument === undefined ? '' : `, ${sourceCode.getText(contextArgument)}`;
82
+ const call = `${receiver}.equals(${comparand}${context})`;
83
+ // `!` and a call both bind tighter than any equality operator, so replacing
84
+ // the comparison never needs parentheses added around it.
85
+ const replacement = NEGATED_OPERATORS.has(operator) ? `!${call}` : call;
86
+ return {
87
+ messageId: 'useEqualsSuggestion',
88
+ data: { replacement },
89
+ fix: (fixer) => fixer.replaceText(node, replacement),
90
+ };
91
+ }
92
+ exports.noCredentialEquality = {
93
+ meta: {
94
+ type: 'problem',
95
+ docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow comparing a revealed sensitive value with an equality operator', true),
96
+ messages: {
97
+ useEquals: 'Comparing a revealed value with {{operator}} returns on the first differing byte, which leaks its contents to a timing attack. Use .equals(), which compares in constant time for the credential class.',
98
+ noSwitchOnReveal: 'switch on a revealed value compares each case in turn and stops at the first match, which leaks its contents to a timing attack. Use .equals() for each candidate instead.',
99
+ useEqualsSuggestion: 'Replace with {{replacement}}',
100
+ },
101
+ hasSuggestions: true,
102
+ schema: [],
103
+ },
104
+ create(context) {
105
+ const sourceCode = (0, ast_js_1.getSourceCode)(context);
106
+ return {
107
+ BinaryExpression(node) {
108
+ const operator = (0, ast_js_1.operatorOf)(node);
109
+ if (operator === undefined || !EQUALITY_OPERATORS.has(operator)) {
110
+ return;
111
+ }
112
+ const operands = (0, ast_js_1.operandsOf)(node);
113
+ if (operands === undefined) {
114
+ return;
115
+ }
116
+ // Operands arrive exactly as written. `asRevealCall` unwraps for itself,
117
+ // and quoting an operand into a suggestion needs the author's text.
118
+ // Whichever side reveals drives the rewrite. When both do, the left one
119
+ // becomes the receiver, which reads the way the original did.
120
+ const left = asRevealCall(operands.left);
121
+ const reveal = left ?? asRevealCall(operands.right);
122
+ if (reveal === undefined) {
123
+ return;
124
+ }
125
+ const other = left === undefined ? operands.left : operands.right;
126
+ const suggestion = sourceCode === undefined
127
+ ? undefined
128
+ : buildSuggestion(sourceCode, node, operator, reveal, other);
129
+ context.report({
130
+ node,
131
+ messageId: 'useEquals',
132
+ data: { operator },
133
+ ...(suggestion === undefined ? {} : { suggest: [suggestion] }),
134
+ });
135
+ },
136
+ SwitchStatement(node) {
137
+ const discriminant = (0, ast_js_1.discriminantOf)(node);
138
+ if (discriminant === undefined || asRevealCall(discriminant) === undefined) {
139
+ return;
140
+ }
141
+ context.report({ node: discriminant, messageId: 'noSwitchOnReveal' });
142
+ },
143
+ };
144
+ },
145
+ };
146
+ //# sourceMappingURL=no-credential-equality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-credential-equality.js","sourceRoot":"","sources":["../../src/rules/no-credential-equality.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCASmB;AAEnB,wCAAsC;AAUtC,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAE3C,sFAAsF;AACtF,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAEpF,iEAAiE;AACjE,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAEtE,qDAAqD;AACrD,SAAS,YAAY,CAAC,IAAa;IACjC,MAAM,IAAI,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,sBAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAA8B;IACnD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,GAAG,IAAA,sBAAa,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,OAAO,KAAK,SAAS,IAAI,IAAA,4BAAmB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACrF,CAAC;AAED;;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@
1
+ {"version":3,"file":"no-log-reveal.d.ts","sourceRoot":"","sources":["../../src/rules/no-log-reveal.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AAgBlF,eAAO,MAAM,WAAW,EAAE,UAgDzB,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noLogReveal = void 0;
4
+ /**
5
+ * `no-log-reveal`: a revealed value must not reach a logger.
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 RULE_NAME = 'no-log-reveal';
12
+ /**
13
+ * Methods whose result is the raw value.
14
+ *
15
+ * `serialize` is here alongside `reveal` because the wire format carries the
16
+ * value in the clear: the README's first security note says so, and
17
+ * `console.log(token.serialize())` is the more dangerous of the two precisely
18
+ * because it reads like the safe option. Nothing else on `SensitiveString`
19
+ * returns an unprotected value; `toString`, `toJSON` and `mask` all redact, and
20
+ * logging them is the fix this rule points at.
21
+ */
22
+ const DEFAULT_REVEAL_METHODS = [ast_js_1.REVEAL_METHOD, 'serialize'];
23
+ exports.noLogReveal = {
24
+ meta: {
25
+ type: 'problem',
26
+ docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow passing a revealed sensitive value to a logger', true),
27
+ messages: {
28
+ noLogReveal: 'Do not log the result of .{{method}}(). Log the value itself, which redacts, or pass it through safeLog().',
29
+ noLogRevealNested: 'This argument contains a .{{method}}() call, so the logged output carries the raw value. Log the value itself, which redacts, or pass it through safeLog().',
30
+ },
31
+ schema: [
32
+ {
33
+ type: 'object',
34
+ properties: {
35
+ logFunctions: (0, options_js_1.nameListSchema)(),
36
+ logObjects: (0, options_js_1.nameListSchema)(),
37
+ revealMethods: (0, options_js_1.nameListSchema)(),
38
+ },
39
+ additionalProperties: false,
40
+ },
41
+ ],
42
+ },
43
+ create(context) {
44
+ const option = (0, options_js_1.optionObject)(context.options, 0);
45
+ const logFunctions = (0, options_js_1.readNameSet)(option, 'logFunctions', log_calls_js_1.DEFAULT_LOG_FUNCTIONS);
46
+ const logObjects = (0, options_js_1.readNameSet)(option, 'logObjects', log_calls_js_1.DEFAULT_LOG_OBJECTS);
47
+ const revealMethods = (0, options_js_1.readNameSet)(option, 'revealMethods', DEFAULT_REVEAL_METHODS);
48
+ const visitorKeys = (0, ast_js_1.getSourceCode)(context)?.visitorKeys;
49
+ return {
50
+ CallExpression(node) {
51
+ if (!(0, log_calls_js_1.isLogCall)(node, logFunctions, logObjects)) {
52
+ return;
53
+ }
54
+ for (const argument of (0, ast_js_1.callArguments)(node)) {
55
+ for (const reveal of (0, ast_js_1.findMethodCalls)(argument, revealMethods, visitorKeys)) {
56
+ context.report({
57
+ node: reveal,
58
+ messageId: (0, ast_js_1.unwrap)(argument) === reveal ? 'noLogReveal' : 'noLogRevealNested',
59
+ data: { method: (0, ast_js_1.asMethodCall)(reveal)?.method ?? ast_js_1.REVEAL_METHOD },
60
+ });
61
+ }
62
+ }
63
+ },
64
+ };
65
+ },
66
+ };
67
+ //# sourceMappingURL=no-log-reveal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-log-reveal.js","sourceRoot":"","sources":["../../src/rules/no-log-reveal.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAOmB;AACnB,wCAAsC;AACtC,kDAAwF;AACxF,8CAA0E;AAG1E,MAAM,SAAS,GAAG,eAAe,CAAC;AAElC;;;;;;;;;GASG;AACH,MAAM,sBAAsB,GAAsB,CAAC,sBAAa,EAAE,WAAW,CAAC,CAAC;AAElE,QAAA,WAAW,GAAe;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAA,kBAAQ,EAAC,SAAS,EAAE,yDAAyD,EAAE,IAAI,CAAC;QAC1F,QAAQ,EAAE;YACR,WAAW,EACT,4GAA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,EAAE,MAAM,EAAE,IAAA,qBAAY,EAAC,MAAM,CAAC,EAAE,MAAM,IAAI,sBAAa,EAAE;yBAChE,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noNetworkSensitive: RuleModule;
3
+ //# sourceMappingURL=no-network-sensitive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-network-sensitive.d.ts","sourceRoot":"","sources":["../../src/rules/no-network-sensitive.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AAuClF,eAAO,MAAM,kBAAkB,EAAE,UAwEhC,CAAC"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noNetworkSensitive = void 0;
4
+ /**
5
+ * `no-network-sensitive`: a secret leaves the process only on purpose.
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-network-sensitive';
11
+ /**
12
+ * Names an HTTP client is reached by, anywhere along the callee chain.
13
+ *
14
+ * The list is of clients, not of methods, because `post` and `get` are far too
15
+ * common to key on: matching `superagent.post(url).send(x)` has to recognise
16
+ * `superagent`, and matching a bare `client.post(...)` would report every
17
+ * mailbox and cache wrapper in a codebase.
18
+ *
19
+ * `request` is deliberately absent even though the library of that name exists.
20
+ * Fastify calls its request object `request`, so the name appears in ordinary
21
+ * handler code that sends nothing anywhere. A project using that library adds
22
+ * it back through `networkFunctions`.
23
+ */
24
+ const DEFAULT_NETWORK_FUNCTIONS = [
25
+ 'fetch',
26
+ '$fetch',
27
+ 'axios',
28
+ 'got',
29
+ 'ky',
30
+ 'superagent',
31
+ 'undici',
32
+ 'http',
33
+ 'https',
34
+ 'XMLHttpRequest',
35
+ ];
36
+ /** Whether a call reaches an HTTP client. */
37
+ function isNetworkCall(node, networkFunctions) {
38
+ const callee = (0, ast_js_1.calleeOf)(node);
39
+ if (callee === undefined) {
40
+ return false;
41
+ }
42
+ return (0, ast_js_1.calleeChainNames)(callee).some((name) => networkFunctions.has(name));
43
+ }
44
+ exports.noNetworkSensitive = {
45
+ meta: {
46
+ type: 'problem',
47
+ docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow sending an unaudited revealed value in a network request', true),
48
+ messages: {
49
+ noNetworkReveal: 'This request sends the result of an unaudited reveal(). Give the reveal a context, as in reveal({ name: "auth-header" }), so the transmission is recorded, or send token.serialize() instead.',
50
+ noNetworkRevealStrict: "This request sends a revealed value. Send token.serialize() instead, which keeps the wire format under the library's control.",
51
+ },
52
+ schema: [
53
+ {
54
+ type: 'object',
55
+ properties: {
56
+ networkFunctions: (0, options_js_1.nameListSchema)(),
57
+ allowWithContext: { type: 'boolean' },
58
+ },
59
+ additionalProperties: false,
60
+ },
61
+ ],
62
+ },
63
+ create(context) {
64
+ const option = (0, options_js_1.optionObject)(context.options, 0);
65
+ const networkFunctions = (0, options_js_1.readNameSet)(option, 'networkFunctions', DEFAULT_NETWORK_FUNCTIONS);
66
+ /**
67
+ * Whether a reveal that names its purpose may cross the network.
68
+ *
69
+ * On by default, which resolves what the two source documents say
70
+ * differently. The roadmap's table describes the rule as catching any
71
+ * `reveal()` inside a `fetch`, while the design document lists
72
+ * `fetch(url, { headers: { Authorization: token.reveal({ name: 'auth-header' }) } })`
73
+ * among its correct examples. They cannot both hold, and the design
74
+ * document has the better of it: sending a credential is what an
75
+ * `Authorization` header is for, so the rule that helps is one separating a
76
+ * deliberate, audited send from an incidental one. Turn this off to forbid
77
+ * both, for a service that must transmit only the serialized wire format.
78
+ */
79
+ const allowWithContext = (0, options_js_1.readBoolean)(option, 'allowWithContext', true);
80
+ const revealMethods = new Set([ast_js_1.REVEAL_METHOD]);
81
+ const visitorKeys = (0, ast_js_1.getSourceCode)(context)?.visitorKeys;
82
+ return {
83
+ CallExpression(node) {
84
+ if (!isNetworkCall(node, networkFunctions)) {
85
+ return;
86
+ }
87
+ for (const argument of (0, ast_js_1.callArguments)(node)) {
88
+ for (const reveal of (0, ast_js_1.findMethodCalls)(argument, revealMethods, visitorKeys)) {
89
+ // An explicit `undefined` satisfies the signature and decides
90
+ // nothing, so it must not be what lets a secret onto the wire.
91
+ const [given] = (0, ast_js_1.callArguments)(reveal);
92
+ const audited = given !== undefined && !(0, ast_js_1.isExplicitUndefined)(given);
93
+ if (allowWithContext && audited) {
94
+ continue;
95
+ }
96
+ context.report({
97
+ node: reveal,
98
+ messageId: allowWithContext ? 'noNetworkReveal' : 'noNetworkRevealStrict',
99
+ });
100
+ }
101
+ }
102
+ },
103
+ };
104
+ },
105
+ };
106
+ //# sourceMappingURL=no-network-sensitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-network-sensitive.js","sourceRoot":"","sources":["../../src/rules/no-network-sensitive.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAQmB;AACnB,wCAAsC;AACtC,8CAAuF;AAGvF,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,MAAM,yBAAyB,GAAsB;IACnD,OAAO;IACP,QAAQ;IACR,OAAO;IACP,KAAK;IACL,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,MAAM;IACN,OAAO;IACP,gBAAgB;CACjB,CAAC;AAEF,6CAA6C;AAC7C,SAAS,aAAa,CAAC,IAAa,EAAE,gBAAqC;IACzE,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAA,yBAAgB,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,C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AAE,CAAC;wBAC3E,8DAA8D;wBAC9D,+DAA+D;wBAC/D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAa,EAAC,MAAM,CAAC,CAAC;wBACtC,MAAM,OAAO,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC,IAAA,4BAAmB,EAAC,KAAK,CAAC,CAAC;wBAEnE,IAAI,gBAAgB,IAAI,OAAO,EAAE,CAAC;4BAChC,SAAS;wBACX,CAAC;wBACD,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,MAAM;4BACZ,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,uBAAuB;yBAC1E,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noPasswordFastHash: RuleModule;
3
+ //# sourceMappingURL=no-password-fast-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-password-fast-hash.d.ts","sourceRoot":"","sources":["../../src/rules/no-password-fast-hash.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AAgDlF,eAAO,MAAM,kBAAkB,EAAE,UA2ChC,CAAC"}
@@ -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,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,QAAiB;IACxC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAA,yBAAgB,EAAC,QAAQ,CAAC,CAAC;IAC7C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,SAA8B;IACtE,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAEnC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YAC7C,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,kBAAkB,GAAe;IAC5C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAA,kBAAQ,EACZ,SAAS,EACT,6EAA6E,EAC7E,KAAK,CACN;QACD,QAAQ,EAAE;YACR,QAAQ,EACN,iQAAiQ;SACpQ;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,aAAa,EAAE,IAAA,2BAAc,GAAE;iBAChC;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF;IAED,MAAM,CAAC,OAAoB;QACzB,MAAM,MAAM,GAAG,IAAA,yBAAY,EAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAChD,MAAM,aAAa,GAAG,IAAA,wBAAW,EAAC,MAAM,EAAE,eAAe,EAAE,sBAAsB,CAAC,CAAC;QAEnF,OAAO;YACL,cAAc,CAAC,IAAa;gBAC1B,MAAM,IAAI,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,iBAAiB,CAAC,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,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noStringifySensitive: RuleModule;
3
+ //# sourceMappingURL=no-stringify-sensitive.d.ts.map
@@ -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
+ {"version":3,"file":"no-stringify-sensitive.js","sourceRoot":"","sources":["../../src/rules/no-stringify-sensitive.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,sCAA0F;AAC1F,wCAAsC;AACtC,8CAA0E;AAC1E,kDAKyB;AAGzB,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAE3C;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAA,2BAAkB,EAAC,MAAM,CAAC,KAAK,WAAW,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAA,yBAAgB,EAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAEY,QAAA,oBAAoB,GAAe;IAC9C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,GAAG,IAAA,kBAAQ,EACT,SAAS,EACT,6EAA6E,EAC7E,IAAI,CACL;YACD,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,kBAAkB,EAChB,6OAA6O;YAC/O,mBAAmB,EACjB,oPAAoP;YACtP,sBAAsB,EACpB,oOAAoO;SACvO;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,cAAc,EAAE,IAAA,2BAAc,GAAE;oBAChC,eAAe,EAAE,IAAA,2BAAc,GAAE;iBAClC;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF;IAED,MAAM,CAAC,OAAoB;QACzB,MAAM,MAAM,GAAG,IAAA,yB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ACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const preferSafeLog: RuleModule;
3
+ //# sourceMappingURL=prefer-safe-log.d.ts.map
@@ -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"}