@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.
Files changed (69) hide show
  1. package/dist/ast.d.ts +172 -0
  2. package/dist/ast.d.ts.map +1 -0
  3. package/dist/ast.js +418 -0
  4. package/dist/ast.js.map +1 -0
  5. package/dist/configs.d.ts +38 -0
  6. package/dist/configs.d.ts.map +1 -0
  7. package/dist/configs.js +131 -0
  8. package/dist/configs.js.map +1 -0
  9. package/dist/docs.d.ts +28 -0
  10. package/dist/docs.d.ts.map +1 -0
  11. package/dist/docs.js +33 -0
  12. package/dist/docs.js.map +1 -0
  13. package/dist/index.d.ts +44 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +117 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/log-calls.d.ts +28 -0
  18. package/dist/log-calls.d.ts.map +1 -0
  19. package/dist/log-calls.js +80 -0
  20. package/dist/log-calls.js.map +1 -0
  21. package/dist/options.d.ts +32 -0
  22. package/dist/options.d.ts.map +1 -0
  23. package/dist/options.js +56 -0
  24. package/dist/options.js.map +1 -0
  25. package/dist/rules/explicit-class.d.ts +3 -0
  26. package/dist/rules/explicit-class.d.ts.map +1 -0
  27. package/dist/rules/explicit-class.js +93 -0
  28. package/dist/rules/explicit-class.js.map +1 -0
  29. package/dist/rules/no-allow-unaudited.d.ts +3 -0
  30. package/dist/rules/no-allow-unaudited.d.ts.map +1 -0
  31. package/dist/rules/no-allow-unaudited.js +92 -0
  32. package/dist/rules/no-allow-unaudited.js.map +1 -0
  33. package/dist/rules/no-credential-equality.d.ts +3 -0
  34. package/dist/rules/no-credential-equality.d.ts.map +1 -0
  35. package/dist/rules/no-credential-equality.js +146 -0
  36. package/dist/rules/no-credential-equality.js.map +1 -0
  37. package/dist/rules/no-log-reveal.d.ts +3 -0
  38. package/dist/rules/no-log-reveal.d.ts.map +1 -0
  39. package/dist/rules/no-log-reveal.js +67 -0
  40. package/dist/rules/no-log-reveal.js.map +1 -0
  41. package/dist/rules/no-network-sensitive.d.ts +3 -0
  42. package/dist/rules/no-network-sensitive.d.ts.map +1 -0
  43. package/dist/rules/no-network-sensitive.js +106 -0
  44. package/dist/rules/no-network-sensitive.js.map +1 -0
  45. package/dist/rules/no-password-fast-hash.d.ts +3 -0
  46. package/dist/rules/no-password-fast-hash.d.ts.map +1 -0
  47. package/dist/rules/no-password-fast-hash.js +84 -0
  48. package/dist/rules/no-password-fast-hash.js.map +1 -0
  49. package/dist/rules/no-stringify-sensitive.d.ts +3 -0
  50. package/dist/rules/no-stringify-sensitive.d.ts.map +1 -0
  51. package/dist/rules/no-stringify-sensitive.js +96 -0
  52. package/dist/rules/no-stringify-sensitive.js.map +1 -0
  53. package/dist/rules/prefer-safe-log.d.ts +3 -0
  54. package/dist/rules/prefer-safe-log.d.ts.map +1 -0
  55. package/dist/rules/prefer-safe-log.js +85 -0
  56. package/dist/rules/prefer-safe-log.js.map +1 -0
  57. package/dist/rules/require-reveal-context.d.ts +3 -0
  58. package/dist/rules/require-reveal-context.d.ts.map +1 -0
  59. package/dist/rules/require-reveal-context.js +149 -0
  60. package/dist/rules/require-reveal-context.js.map +1 -0
  61. package/dist/type-info.d.ts +134 -0
  62. package/dist/type-info.d.ts.map +1 -0
  63. package/dist/type-info.js +282 -0
  64. package/dist/type-info.js.map +1 -0
  65. package/dist/types.d.ts +137 -0
  66. package/dist/types.d.ts.map +1 -0
  67. package/dist/types.js +23 -0
  68. package/dist/types.js.map +1 -0
  69. package/package.json +10 -10
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.explicitClass = void 0;
4
+ /**
5
+ * `explicit-class`: a sensitive value must be constructed with its class.
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 = 'explicit-class';
11
+ /** Constructors whose second parameter is the sensitivity class. */
12
+ const DEFAULT_CONSTRUCTOR_NAMES = ['SensitiveString'];
13
+ /** The classes the core library defines, in the order the suggestions offer them. */
14
+ const SENSITIVITY_CLASSES = ['sensitive', 'credential'];
15
+ exports.explicitClass = {
16
+ meta: {
17
+ type: 'suggestion',
18
+ docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Require an explicit sensitivity class when constructing a SensitiveString', true),
19
+ messages: {
20
+ missingClass: "new {{name}}() has no sensitivity class. Pass 'credential' for anything compared against user input, or 'sensitive' otherwise; the class decides redaction and whether comparison is constant-time.",
21
+ addClass: "Pass '{{klass}}' as the sensitivity class",
22
+ },
23
+ hasSuggestions: true,
24
+ schema: [
25
+ {
26
+ type: 'object',
27
+ properties: {
28
+ constructorNames: (0, options_js_1.nameListSchema)(),
29
+ },
30
+ additionalProperties: false,
31
+ },
32
+ ],
33
+ },
34
+ create(context) {
35
+ const option = (0, options_js_1.optionObject)(context.options, 0);
36
+ const constructorNames = (0, options_js_1.readNameSet)(option, 'constructorNames', DEFAULT_CONSTRUCTOR_NAMES);
37
+ return {
38
+ NewExpression(node) {
39
+ const callee = (0, ast_js_1.calleeOf)(node);
40
+ if (callee === undefined) {
41
+ return;
42
+ }
43
+ // The chain covers both `new SensitiveString(v)` and the namespaced
44
+ // `new core.SensitiveString(v)`.
45
+ const [name] = (0, ast_js_1.calleeChainNames)(callee);
46
+ if (name === undefined || !constructorNames.has(name)) {
47
+ return;
48
+ }
49
+ // A spread makes the argument count unknowable, and guessing would
50
+ // report correct code. Precision matters more here than reach: the
51
+ // constructor's TypeScript signature already requires the class, so
52
+ // this rule is a second line for JavaScript callers and `any`-typed
53
+ // call sites, not the only one.
54
+ if ((0, ast_js_1.hasSpreadArgument)(node)) {
55
+ return;
56
+ }
57
+ // `new SensitiveString(v, undefined)` names no class either. Counting
58
+ // arguments alone would let the shortest way to silence this rule look
59
+ // like compliance with it.
60
+ const args = (0, ast_js_1.callArguments)(node);
61
+ const given = args[1];
62
+ const placeholder = given !== undefined && (0, ast_js_1.isExplicitUndefined)(given);
63
+ if (given !== undefined && !placeholder) {
64
+ return;
65
+ }
66
+ // Offered only when there is a value argument to anchor to. With no
67
+ // arguments at all the call is already broken in a way no sensitivity
68
+ // class fixes, and the report alone is the honest answer.
69
+ //
70
+ // A placeholder is overwritten rather than pushed along: inserting
71
+ // ahead of it would leave the `undefined` behind in the `label`
72
+ // position, where it is accepted and means nothing.
73
+ const value = args[0];
74
+ const suggestions = value === undefined
75
+ ? []
76
+ : SENSITIVITY_CLASSES.map((klass) => ({
77
+ messageId: 'addClass',
78
+ data: { klass },
79
+ fix: (fixer) => placeholder && given !== undefined
80
+ ? fixer.replaceText(given, `'${klass}'`)
81
+ : fixer.insertTextAfter(value, `, '${klass}'`),
82
+ }));
83
+ context.report({
84
+ node,
85
+ messageId: 'missingClass',
86
+ data: { name },
87
+ ...(suggestions.length === 0 ? {} : { suggest: suggestions }),
88
+ });
89
+ },
90
+ };
91
+ },
92
+ };
93
+ //# sourceMappingURL=explicit-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explicit-class.js","sourceRoot":"","sources":["../../src/rules/explicit-class.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAMmB;AACnB,wCAAsC;AACtC,8CAA0E;AAS1E,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC,oEAAoE;AACpE,MAAM,yBAAyB,GAAsB,CAAC,iBAAiB,CAAC,CAAC;AAEzE,qFAAqF;AACrF,MAAM,mBAAmB,GAAsB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAE9D,QAAA,aAAa,GAAe;IACvC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,IAAA,kBAAQ,EACZ,SAAS,EACT,2EAA2E,EAC3E,IAAI,CACL;QACD,QAAQ,EAAE;YACR,YAAY,EACV,qMAAqM;YACvM,QAAQ,EAAE,2CAA2C;SACtD;QACD,cAAc,EAAE,IAA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BACxC,OAAO;gBACT,CAAC;gBAED,oEAAoE;gBACpE,sEAAsE;gBACtE,0DAA0D;gBAC1D,EAAE;gBACF,mEAAmE;gBACnE,gEAAgE;gBAChE,oDAAoD;gBACpD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACtB,MAAM,WAAW,GACf,KAAK,KAAK,SAAS;oBACjB,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;wBAClC,SAAS,EAAE,UAAU;wBACrB,IAAI,EAAE,EAAE,KAAK,EAAE;wBACf,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CACb,WAAW,IAAI,KAAK,KAAK,SAAS;4BAChC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,KAAK,GAAG,CAAC;4BACxC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;qBACnD,CAAC,CAAC,CAAC;gBAEV,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,cAAc;oBACzB,IAAI,EAAE,EAAE,IAAI,EAAE;oBACd,GAAG,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;iBAC9D,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noAllowUnaudited: RuleModule;
3
+ //# sourceMappingURL=no-allow-unaudited.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-allow-unaudited.d.ts","sourceRoot":"","sources":["../../src/rules/no-allow-unaudited.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAsC,UAAU,EAAE,MAAM,aAAa,CAAC;AA6BlF,eAAO,MAAM,gBAAgB,EAAE,UAqE9B,CAAC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noAllowUnaudited = void 0;
4
+ /**
5
+ * `no-allow-unaudited`: accepting a worker payload without the audit hook its
6
+ * sender asked for.
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 RULE_NAME = 'no-allow-unaudited';
12
+ /** The option this rule is about. */
13
+ const FLAG = 'allowUnaudited';
14
+ /**
15
+ * The functions that consume a worker payload and take the flag.
16
+ *
17
+ * Both take it in an options object, and both drop the sender's audit hook
18
+ * when it is set: a payload built under an audited context arrives with
19
+ * `audited: true` and no hook, because a function cannot cross an isolate,
20
+ * and the flag says to go ahead without one.
21
+ */
22
+ const DEFAULT_PAYLOAD_FUNCTIONS = ['fromWorkerPayload', 'withWorkerPayload'];
23
+ /**
24
+ * Whether a property value is the literal `false`.
25
+ *
26
+ * `allowUnaudited: false` is the default spelled out, which is worth writing
27
+ * in a config object that is built up and passed around, and there is nothing
28
+ * to report about it.
29
+ */
30
+ function isLiteralFalse(node) {
31
+ const value = (0, ast_js_1.unwrap)(node);
32
+ return value.type === 'Literal' && value.value === false;
33
+ }
34
+ exports.noAllowUnaudited = {
35
+ meta: {
36
+ type: 'problem',
37
+ docs: (0, docs_js_1.ruleDocs)(RULE_NAME, 'Disallow allowUnaudited on fromWorkerPayload() and withWorkerPayload(), which drops an audit hook the sender asked for', true),
38
+ messages: {
39
+ allowUnaudited: '{{function}}() with allowUnaudited accepts a payload whose sender installed an audit hook and records none of the reveals it authorizes, because the hook could not cross the thread boundary. Pass auditReveal so this side records what the sender asked to have recorded. If reveals here genuinely need no record, say why in a disable comment on this line.',
40
+ },
41
+ schema: [
42
+ {
43
+ type: 'object',
44
+ properties: {
45
+ payloadFunctions: (0, options_js_1.nameListSchema)(),
46
+ },
47
+ additionalProperties: false,
48
+ },
49
+ ],
50
+ },
51
+ create(context) {
52
+ const option = (0, options_js_1.optionObject)(context.options, 0);
53
+ const payloadFunctions = (0, options_js_1.readNameSet)(option, 'payloadFunctions', DEFAULT_PAYLOAD_FUNCTIONS);
54
+ return {
55
+ CallExpression(node) {
56
+ const callee = (0, ast_js_1.calleeOf)(node);
57
+ if (callee === undefined) {
58
+ return;
59
+ }
60
+ // The nearest name in the chain, so `core.fromWorkerPayload(...)` and
61
+ // a bare import both match.
62
+ const [called] = (0, ast_js_1.calleeChainNames)(callee);
63
+ if (called === undefined || !payloadFunctions.has(called)) {
64
+ return;
65
+ }
66
+ // Every argument is read rather than only the second: the flag has
67
+ // exactly one meaning wherever it appears in one of these calls, and
68
+ // reading by position would miss it behind a leading spread.
69
+ for (const argument of (0, ast_js_1.callArguments)(node)) {
70
+ if ((0, ast_js_1.isSpread)(argument)) {
71
+ continue;
72
+ }
73
+ for (const property of (0, ast_js_1.objectProperties)((0, ast_js_1.unwrap)(argument))) {
74
+ if ((0, ast_js_1.isSpread)(property) || (0, ast_js_1.staticKeyName)(property) !== FLAG) {
75
+ continue;
76
+ }
77
+ const value = property.value;
78
+ if (value !== undefined && (isLiteralFalse(value) || (0, ast_js_1.isExplicitUndefined)(value))) {
79
+ continue;
80
+ }
81
+ context.report({
82
+ node: property,
83
+ messageId: 'allowUnaudited',
84
+ data: { function: called },
85
+ });
86
+ }
87
+ }
88
+ },
89
+ };
90
+ },
91
+ };
92
+ //# sourceMappingURL=no-allow-unaudited.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-allow-unaudited.js","sourceRoot":"","sources":["../../src/rules/no-allow-unaudited.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,sCASmB;AACnB,wCAAsC;AACtC,8CAA0E;AAG1E,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAEvC,qCAAqC;AACrC,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,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nE,qEAAqE;gBACrE,6DAA6D;gBAC7D,KAAK,MAAM,QAAQ,IAAI,IAAA,sBAAa,EAAC,IAAI,CAAC,EAAE,CAAC;oBAC3C,IAAI,IAAA,iBAAQ,EAAC,QAAQ,CAAC,EAAE,CAAC;wBACvB,SAAS;oBACX,CAAC;oBAED,KAAK,MAAM,QAAQ,IAAI,IAAA,yBAAgB,EAAC,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;wBAC1D,IAAI,IAAA,iBAAQ,EAAC,QAAQ,CAAC,IAAI,IAAA,sBAAa,EAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;4BAC3D,SAAS;wBACX,CAAC;wBAED,MAAM,KAAK,GAAI,QAA2C,CAAC,KAAK,CAAC;wBACjE,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,IAAA,4BAAmB,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC;4BACjF,SAAS;wBACX,CAAC;wBAED,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,QAAQ;4BACd,SAAS,EAAE,gBAAgB;4BAC3B,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE;yBAC3B,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 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,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,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBAEjE,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,EAAE,QAAQ,EAAE;oBAClB,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;iBAC/D,CAAC,CAAC;YACL,CAAC;YAED,eAAe,CAAC,IAAa;gBAC3B,MAAM,YAAY,GAAG,IAAA,uBAAc,EAAC,IAAI,CAAC,CAAC;gBAC1C,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE,CAAC;oBAC3E,OAAO;gBACT,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;YACxE,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const noLogReveal: RuleModule;
3
+ //# sourceMappingURL=no-log-reveal.d.ts.map
@@ -0,0 +1 @@
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,4GAA4G;YAC9G,iBAAiB,EACf,6JAA6J;SAChK;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,YAAY,EAAE,IAAA,2BAAc,GAAE;oBAC9B,UAAU,EAAE,IAAA,2BAAc,GAAE;oBAC5B,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,YAAY,GAAG,IAAA,wBAAW,EAAC,MAAM,EAAE,cAAc,EAAE,oCAAqB,CAAC,CAAC;QAChF,MAAM,UAAU,GAAG,IAAA,wBAAW,EAAC,MAAM,EAAE,YAAY,EAAE,kCAAmB,CAAC,CAAC;QAC1E,MAAM,aAAa,GAAG,IAAA,wBAAW,EAAC,MAAM,EAAE,eAAe,EAAE,sBAAsB,CAAC,CAAC;QACnF,MAAM,WAAW,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,EAAE,WAAW,CAAC;QAExD,OAAO;YACL,cAAc,CAAC,IAAa;gBAC1B,IAAI,CAAC,IAAA,wBAAS,EAAC,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,CAAC;oBAC/C,OAAO;gBACT,CAAC;gBAED,KAAK,MAAM,QAAQ,IAAI,IAAA,sBAAa,EAAC,IAAI,CAAC,EAAE,CAAC;oBAC3C,KAAK,MAAM,MAAM,IAAI,IAAA,wBAAe,EAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,CAAC;wBAC3E,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,MAAM;4BACZ,SAAS,EAAE,IAAA,eAAM,EAAC,QAAQ,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,mBAAmB;4BAC5E,IAAI,EAAE,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,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7E,CAAC;AAEY,QAAA,kBAAkB,GAAe;IAC5C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAA,kBAAQ,EACZ,SAAS,EACT,mEAAmE,EACnE,IAAI,CACL;QACD,QAAQ,EAAE;YACR,eAAe,EACb,+LAA+L;YACjM,qBAAqB,EACnB,+HAA+H;SAClI;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE,IAAA,2BAAc,GAAE;oBAClC,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;iBACtC;gBACD,oBAAoB,EAAE,KAAK;aAC5B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,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"}