@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
package/dist/docs.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * Where a rule's documentation lives.
4
+ *
5
+ * `meta.docs.url` is what an editor turns into the "learn more" link on a
6
+ * report, and ESLint requires an absolute URL for it. This project has no
7
+ * public repository yet, so there is no honest absolute URL to give: pointing
8
+ * the link at a guessed host would put a dead link in front of every developer
9
+ * who hovers a finding, which is worse than no link at all.
10
+ *
11
+ * The markdown under `docs/rules/` ships in the package either way, so the
12
+ * documentation is present in `node_modules` regardless. When the project gets
13
+ * a home, set {@link DOCS_BASE_URL} and every rule picks the link up.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.DOCS_BASE_URL = void 0;
17
+ exports.ruleDocs = ruleDocs;
18
+ /** The published location of `docs/rules/`, with a trailing slash, or `undefined`. */
19
+ exports.DOCS_BASE_URL = undefined;
20
+ /**
21
+ * The `docs` block for a rule, carrying a `url` only when there is one to give.
22
+ *
23
+ * `url` is omitted rather than set to `undefined` because `exactOptionalPropertyTypes`
24
+ * distinguishes the two, and because ESLint's own config-inspector renders an
25
+ * explicit `undefined` as a broken link.
26
+ */
27
+ function ruleDocs(ruleName, description, recommended, base = exports.DOCS_BASE_URL) {
28
+ if (base === undefined) {
29
+ return { description, recommended };
30
+ }
31
+ return { description, recommended, url: `${base}${ruleName}.md` };
32
+ }
33
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAYH,4BAUC;AApBD,sFAAsF;AACzE,QAAA,aAAa,GAAuB,SAAS,CAAC;AAE3D;;;;;;GAMG;AACH,SAAgB,QAAQ,CACtB,QAAgB,EAChB,WAAmB,EACnB,WAAoB,EACpB,OAA2B,qBAAa;IAExC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,QAAQ,KAAK,EAAE,CAAC;AACpE,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { explicitClass } from './rules/explicit-class.js';
2
+ import { noAllowUnaudited } from './rules/no-allow-unaudited.js';
3
+ import { noCredentialEquality } from './rules/no-credential-equality.js';
4
+ import { noLogReveal } from './rules/no-log-reveal.js';
5
+ import { noNetworkSensitive } from './rules/no-network-sensitive.js';
6
+ import { noStringifySensitive } from './rules/no-stringify-sensitive.js';
7
+ import { preferSafeLog } from './rules/prefer-safe-log.js';
8
+ import { requireRevealContext } from './rules/require-reveal-context.js';
9
+ import type { Plugin, RuleModule } from './types.js';
10
+ /** Every rule this plugin defines, keyed by the name a config uses. */
11
+ export declare const rules: Readonly<Record<string, RuleModule>>;
12
+ /**
13
+ * Plugin identity, which flat config uses to name the plugin in its output and
14
+ * which ESLint's config inspector reads.
15
+ */
16
+ export declare const meta: {
17
+ readonly name: "@platform-sec/eslint-plugin-sensitive-string";
18
+ readonly version: "0.2.1";
19
+ };
20
+ /**
21
+ * The presets: `recommended`, `strict`, their `-type-checked` forms and
22
+ * `disable-type-checked`, each in a flat and a `legacy-` eslintrc shape.
23
+ *
24
+ * Filled in after the plugin exists, because a flat preset holds the plugin
25
+ * object it configures and the plugin holds its presets. The two names are one
26
+ * object, so a config reached through `plugin.configs` and one reached through
27
+ * this export cannot come apart.
28
+ */
29
+ export declare const configs: Record<string, unknown>;
30
+ declare const plugin: Plugin;
31
+ export { explicitClass, noAllowUnaudited, noCredentialEquality, noLogReveal, noNetworkSensitive, noStringifySensitive, preferSafeLog, requireRevealContext, };
32
+ export { PLUGIN_NAMESPACE } from './configs.js';
33
+ export type { AstNode, Plugin, ReportDescriptor, RuleContext, RuleFix, RuleFixer, RuleListener, RuleMeta, RuleMetaDocs, RuleModule, SourceCode, SuggestionDescriptor, } from './types.js';
34
+ /**
35
+ * The plugin object.
36
+ *
37
+ * Both module shapes work on purpose. Flat config does
38
+ * `import plugin from '...'` and gets this default; eslintrc does
39
+ * `require('...')` and gets the module namespace, whose `rules` and `configs`
40
+ * named exports are the same objects this default holds. Neither format needs
41
+ * an interop shim.
42
+ */
43
+ export default plugin;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoDA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,uEAAuE;AACvE,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAUtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI;;;CAGP,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,CAAC;AAEnD,QAAA,MAAM,MAAM,EAAE,MAAiC,CAAC;AAGhD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,oBAAoB,GACrB,CAAC;AACF,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EACV,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,OAAO,EACP,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLUGIN_NAMESPACE = exports.requireRevealContext = exports.preferSafeLog = exports.noStringifySensitive = exports.noNetworkSensitive = exports.noLogReveal = exports.noCredentialEquality = exports.noAllowUnaudited = exports.explicitClass = exports.configs = exports.meta = exports.rules = void 0;
4
+ /**
5
+ * @platform-sec/eslint-plugin-sensitive-string
6
+ *
7
+ * Lint rules for the mistakes `SensitiveString`'s type system cannot catch.
8
+ *
9
+ * A type keeps a secret wrapped. It cannot stop `console.log(secret.reveal())`,
10
+ * because the reveal produces an ordinary string and logging a string is
11
+ * ordinary code. Nine rules read the call instead.
12
+ *
13
+ * Seven of them read syntax alone, so they run under any parser and cost
14
+ * nothing beyond the parse:
15
+ *
16
+ * - `no-log-reveal` stops a revealed value reaching a logger.
17
+ * - `no-credential-equality` stops `===` on a revealed value, which leaks its
18
+ * contents through timing.
19
+ * - `no-network-sensitive` stops an unaudited reveal crossing the network.
20
+ * - `explicit-class` asks for the sensitivity class at construction.
21
+ * - `require-reveal-context` asks a reveal to say who is reading and why, and
22
+ * asks the same of the other audited reads where types are available.
23
+ * - `no-password-fast-hash` stops a password being stored under a digest that
24
+ * a wordlist runs through at billions of guesses a second.
25
+ * - `no-allow-unaudited` stops a worker accepting a payload without the audit
26
+ * hook its sender asked for.
27
+ *
28
+ * Two answer a question no syntax can, "does this value carry a sensitive one
29
+ * inside it", and so need typescript-eslint's type-aware mode:
30
+ *
31
+ * - `no-stringify-sensitive` stops `JSON.stringify` silently substituting a
32
+ * redaction, and stops it writing a `serialize()` result in the clear.
33
+ * - `prefer-safe-log` moves the redaction of a logged structure out of
34
+ * whichever serializer the transport installed and into the call site.
35
+ *
36
+ * The type-aware pair lives only in the `*-type-checked` presets, so a
37
+ * consumer who has not configured a program never meets them.
38
+ *
39
+ * @example Flat config
40
+ * ```js
41
+ * import sensitive from '@platform-sec/eslint-plugin-sensitive-string';
42
+ *
43
+ * export default [sensitive.configs.recommended];
44
+ * ```
45
+ *
46
+ * @example eslintrc
47
+ * ```js
48
+ * module.exports = {
49
+ * extends: ['plugin:@platform-sec/sensitive-string/legacy-recommended'],
50
+ * };
51
+ * ```
52
+ *
53
+ * @packageDocumentation
54
+ */
55
+ const configs_js_1 = require("./configs.js");
56
+ const explicit_class_js_1 = require("./rules/explicit-class.js");
57
+ Object.defineProperty(exports, "explicitClass", { enumerable: true, get: function () { return explicit_class_js_1.explicitClass; } });
58
+ const no_allow_unaudited_js_1 = require("./rules/no-allow-unaudited.js");
59
+ Object.defineProperty(exports, "noAllowUnaudited", { enumerable: true, get: function () { return no_allow_unaudited_js_1.noAllowUnaudited; } });
60
+ const no_credential_equality_js_1 = require("./rules/no-credential-equality.js");
61
+ Object.defineProperty(exports, "noCredentialEquality", { enumerable: true, get: function () { return no_credential_equality_js_1.noCredentialEquality; } });
62
+ const no_log_reveal_js_1 = require("./rules/no-log-reveal.js");
63
+ Object.defineProperty(exports, "noLogReveal", { enumerable: true, get: function () { return no_log_reveal_js_1.noLogReveal; } });
64
+ const no_network_sensitive_js_1 = require("./rules/no-network-sensitive.js");
65
+ Object.defineProperty(exports, "noNetworkSensitive", { enumerable: true, get: function () { return no_network_sensitive_js_1.noNetworkSensitive; } });
66
+ const no_password_fast_hash_js_1 = require("./rules/no-password-fast-hash.js");
67
+ const no_stringify_sensitive_js_1 = require("./rules/no-stringify-sensitive.js");
68
+ Object.defineProperty(exports, "noStringifySensitive", { enumerable: true, get: function () { return no_stringify_sensitive_js_1.noStringifySensitive; } });
69
+ const prefer_safe_log_js_1 = require("./rules/prefer-safe-log.js");
70
+ Object.defineProperty(exports, "preferSafeLog", { enumerable: true, get: function () { return prefer_safe_log_js_1.preferSafeLog; } });
71
+ const require_reveal_context_js_1 = require("./rules/require-reveal-context.js");
72
+ Object.defineProperty(exports, "requireRevealContext", { enumerable: true, get: function () { return require_reveal_context_js_1.requireRevealContext; } });
73
+ /** Every rule this plugin defines, keyed by the name a config uses. */
74
+ exports.rules = {
75
+ 'explicit-class': explicit_class_js_1.explicitClass,
76
+ 'no-allow-unaudited': no_allow_unaudited_js_1.noAllowUnaudited,
77
+ 'no-credential-equality': no_credential_equality_js_1.noCredentialEquality,
78
+ 'no-log-reveal': no_log_reveal_js_1.noLogReveal,
79
+ 'no-network-sensitive': no_network_sensitive_js_1.noNetworkSensitive,
80
+ 'no-password-fast-hash': no_password_fast_hash_js_1.noPasswordFastHash,
81
+ 'no-stringify-sensitive': no_stringify_sensitive_js_1.noStringifySensitive,
82
+ 'prefer-safe-log': prefer_safe_log_js_1.preferSafeLog,
83
+ 'require-reveal-context': require_reveal_context_js_1.requireRevealContext,
84
+ };
85
+ /**
86
+ * Plugin identity, which flat config uses to name the plugin in its output and
87
+ * which ESLint's config inspector reads.
88
+ */
89
+ exports.meta = {
90
+ name: '@platform-sec/eslint-plugin-sensitive-string',
91
+ version: '0.2.1',
92
+ };
93
+ /**
94
+ * The presets: `recommended`, `strict`, their `-type-checked` forms and
95
+ * `disable-type-checked`, each in a flat and a `legacy-` eslintrc shape.
96
+ *
97
+ * Filled in after the plugin exists, because a flat preset holds the plugin
98
+ * object it configures and the plugin holds its presets. The two names are one
99
+ * object, so a config reached through `plugin.configs` and one reached through
100
+ * this export cannot come apart.
101
+ */
102
+ exports.configs = {};
103
+ const plugin = { meta: exports.meta, rules: exports.rules, configs: exports.configs };
104
+ Object.assign(exports.configs, (0, configs_js_1.buildConfigs)(plugin));
105
+ var configs_js_2 = require("./configs.js");
106
+ Object.defineProperty(exports, "PLUGIN_NAMESPACE", { enumerable: true, get: function () { return configs_js_2.PLUGIN_NAMESPACE; } });
107
+ /**
108
+ * The plugin object.
109
+ *
110
+ * Both module shapes work on purpose. Flat config does
111
+ * `import plugin from '...'` and gets this default; eslintrc does
112
+ * `require('...')` and gets the module namespace, whose `rules` and `configs`
113
+ * named exports are the same objects this default holds. Neither format needs
114
+ * an interop shim.
115
+ */
116
+ exports.default = plugin;
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,6CAA4C;AAC5C,iEAA0D;AAgDxD,8FAhDO,iCAAa,OAgDP;AA/Cf,yEAAiE;AAgD/D,iGAhDO,wCAAgB,OAgDP;AA/ClB,iFAAyE;AAgDvE,qGAhDO,gDAAoB,OAgDP;AA/CtB,+DAAuD;AAgDrD,4FAhDO,8BAAW,OAgDP;AA/Cb,6EAAqE;AAgDnE,mGAhDO,4CAAkB,OAgDP;AA/CpB,+EAAsE;AACtE,iFAAyE;AA+CvE,qGA/CO,gDAAoB,OA+CP;AA9CtB,mEAA2D;AA+CzD,8FA/CO,kCAAa,OA+CP;AA9Cf,iFAAyE;AA+CvE,qGA/CO,gDAAoB,OA+CP;AA5CtB,uEAAuE;AAC1D,QAAA,KAAK,GAAyC;IACzD,gBAAgB,EAAE,iCAAa;IAC/B,oBAAoB,EAAE,wCAAgB;IACtC,wBAAwB,EAAE,gDAAoB;IAC9C,eAAe,EAAE,8BAAW;IAC5B,sBAAsB,EAAE,4CAAkB;IAC1C,uBAAuB,EAAE,6CAAkB;IAC3C,wBAAwB,EAAE,gDAAoB;IAC9C,iBAAiB,EAAE,kCAAa;IAChC,wBAAwB,EAAE,gDAAoB;CAC/C,CAAC;AAEF;;;GAGG;AACU,QAAA,IAAI,GAAG;IAClB,IAAI,EAAE,8CAA8C;IACpD,OAAO,EAAE,OAAO;CACR,CAAC;AAEX;;;;;;;;GAQG;AACU,QAAA,OAAO,GAA4B,EAAE,CAAC;AAEnD,MAAM,MAAM,GAAW,EAAE,IAAI,EAAJ,YAAI,EAAE,KAAK,EAAL,aAAK,EAAE,OAAO,EAAP,eAAO,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,CAAC,eAAO,EAAE,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC,CAAC;AAY7C,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AAgBzB;;;;;;;;GAQG;AACH,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { AstNode } from './types.js';
2
+ /**
3
+ * Method names on a logger, plus `write`.
4
+ *
5
+ * `write` is here for `process.stdout.write(secret.reveal())`, which leaks
6
+ * exactly what `console.log` leaks and is the first thing reached for when a
7
+ * log line needs no newline. It only ever matches alongside a name from
8
+ * {@link DEFAULT_LOG_OBJECTS}, so an unrelated `stream.write` is untouched.
9
+ */
10
+ export declare const DEFAULT_LOG_FUNCTIONS: readonly string[];
11
+ /** Names a logger is reached by, anywhere along the callee chain. */
12
+ export declare const DEFAULT_LOG_OBJECTS: readonly string[];
13
+ /**
14
+ * Whether a call reaches a logger.
15
+ *
16
+ * Two shapes count. A method call needs its method name in `logFunctions` and
17
+ * some name along its callee chain in `logObjects`, which covers `console.log`,
18
+ * `this.logger.info`, `req.log.warn` and `logger.child({ id }).info` alike. A
19
+ * bare call counts when the function's own name is in `logObjects`, which is
20
+ * how `log(...)` from a destructured import is caught.
21
+ *
22
+ * Matching anywhere in the chain rather than at its head is a deliberate trade:
23
+ * it takes an object named one of eight logger names carrying a method named
24
+ * one of ten logger methods to produce a false positive, and it is the only way
25
+ * to see a logger that arrives as a property.
26
+ */
27
+ export declare function isLogCall(node: AstNode, logFunctions: ReadonlySet<string>, logObjects: ReadonlySet<string>): boolean;
28
+ //# sourceMappingURL=log-calls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-calls.d.ts","sourceRoot":"","sources":["../src/log-calls.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAWlD,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAShD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,EACjC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAC9B,OAAO,CAsBT"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_LOG_OBJECTS = exports.DEFAULT_LOG_FUNCTIONS = void 0;
4
+ exports.isLogCall = isLogCall;
5
+ /**
6
+ * Recognising a call to a logger.
7
+ *
8
+ * Two rules ask the same question. `no-log-reveal` asks it of a call's
9
+ * arguments, `prefer-safe-log` of their types, and neither is useful if they
10
+ * disagree about what a logger is: a project that configures its own logger
11
+ * name for one and finds the other still blind to it has been given two rules
12
+ * where it configured one. The vocabulary and the matcher live here so there
13
+ * is one answer.
14
+ */
15
+ const ast_js_1 = require("./ast.js");
16
+ /**
17
+ * Method names on a logger, plus `write`.
18
+ *
19
+ * `write` is here for `process.stdout.write(secret.reveal())`, which leaks
20
+ * exactly what `console.log` leaks and is the first thing reached for when a
21
+ * log line needs no newline. It only ever matches alongside a name from
22
+ * {@link DEFAULT_LOG_OBJECTS}, so an unrelated `stream.write` is untouched.
23
+ */
24
+ exports.DEFAULT_LOG_FUNCTIONS = [
25
+ 'log',
26
+ 'info',
27
+ 'warn',
28
+ 'error',
29
+ 'debug',
30
+ 'trace',
31
+ 'fatal',
32
+ 'verbose',
33
+ 'silly',
34
+ 'write',
35
+ ];
36
+ /** Names a logger is reached by, anywhere along the callee chain. */
37
+ exports.DEFAULT_LOG_OBJECTS = [
38
+ 'console',
39
+ 'logger',
40
+ 'log',
41
+ 'winston',
42
+ 'pino',
43
+ 'bunyan',
44
+ 'stdout',
45
+ 'stderr',
46
+ ];
47
+ /**
48
+ * Whether a call reaches a logger.
49
+ *
50
+ * Two shapes count. A method call needs its method name in `logFunctions` and
51
+ * some name along its callee chain in `logObjects`, which covers `console.log`,
52
+ * `this.logger.info`, `req.log.warn` and `logger.child({ id }).info` alike. A
53
+ * bare call counts when the function's own name is in `logObjects`, which is
54
+ * how `log(...)` from a destructured import is caught.
55
+ *
56
+ * Matching anywhere in the chain rather than at its head is a deliberate trade:
57
+ * it takes an object named one of eight logger names carrying a method named
58
+ * one of ten logger methods to produce a false positive, and it is the only way
59
+ * to see a logger that arrives as a property.
60
+ */
61
+ function isLogCall(node, logFunctions, logObjects) {
62
+ const callee = (0, ast_js_1.calleeOf)(node);
63
+ if (callee === undefined) {
64
+ return false;
65
+ }
66
+ const bareName = (0, ast_js_1.identifierName)(callee);
67
+ if (bareName !== undefined) {
68
+ return logObjects.has(bareName);
69
+ }
70
+ if (callee.type !== 'MemberExpression') {
71
+ return false;
72
+ }
73
+ const names = (0, ast_js_1.calleeChainNames)(callee);
74
+ const method = names[0];
75
+ if (method === undefined || !logFunctions.has(method)) {
76
+ return false;
77
+ }
78
+ return names.slice(1).some((name) => logObjects.has(name));
79
+ }
80
+ //# sourceMappingURL=log-calls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-calls.js","sourceRoot":"","sources":["../src/log-calls.ts"],"names":[],"mappings":";;;AA4DA,8BA0BC;AAtFD;;;;;;;;;GASG;AACH,qCAAsE;AAGtE;;;;;;;GAOG;AACU,QAAA,qBAAqB,GAAsB;IACtD,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,SAAS;IACT,OAAO;IACP,OAAO;CACR,CAAC;AAEF,qEAAqE;AACxD,QAAA,mBAAmB,GAAsB;IACpD,SAAS;IACT,QAAQ;IACR,KAAK;IACL,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,IAAa,EACb,YAAiC,EACjC,UAA+B;IAE/B,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,uBAAc,EAAC,MAAM,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,GAAG,IAAA,yBAAgB,EAAC,MAAM,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Reading a rule's options.
3
+ *
4
+ * ESLint validates options against each rule's `meta.schema` before `create` is
5
+ * called, so these readers are not the enforcement point. They exist because
6
+ * the options arrive as `unknown` and a rule should not cast its way out of
7
+ * that: a schema can be edited into disagreement with the code it guards, and
8
+ * on that day a wrong option should fall back to a safe default rather than
9
+ * reach a rule as a string where a list belongs.
10
+ */
11
+ /**
12
+ * One positional option, as an object, or an empty one when it is absent or is
13
+ * not an object. Every reader below then falls back to its default, which is
14
+ * what an omitted option should do.
15
+ */
16
+ export declare function optionObject(options: readonly unknown[], index: number): Readonly<Record<string, unknown>>;
17
+ /** A boolean field of an options object, or `fallback` when it is absent. */
18
+ export declare function readBoolean(option: Readonly<Record<string, unknown>>, key: string, fallback: boolean): boolean;
19
+ /**
20
+ * A list-of-strings field of an options object, as a set, or `fallback` when it
21
+ * is absent.
22
+ *
23
+ * A configured list replaces the default rather than extending it. That is the
24
+ * ESLint convention, and for these rules it is also the useful behaviour: a
25
+ * project that names its logger `report` wants `report` recognised, and a
26
+ * project that has deliberately narrowed the list wants the entries it removed
27
+ * to stay removed.
28
+ */
29
+ export declare function readNameSet(option: Readonly<Record<string, unknown>>, key: string, fallback: readonly string[]): ReadonlySet<string>;
30
+ /** The JSON Schema for an option that is a list of names. */
31
+ export declare function nameListSchema(): Readonly<Record<string, unknown>>;
32
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMnC;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CACzB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,OAAO,GAChB,OAAO,CAGT;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,WAAW,CAAC,MAAM,CAAC,CAOrB;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAElE"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * Reading a rule's options.
4
+ *
5
+ * ESLint validates options against each rule's `meta.schema` before `create` is
6
+ * called, so these readers are not the enforcement point. They exist because
7
+ * the options arrive as `unknown` and a rule should not cast its way out of
8
+ * that: a schema can be edited into disagreement with the code it guards, and
9
+ * on that day a wrong option should fall back to a safe default rather than
10
+ * reach a rule as a string where a list belongs.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.optionObject = optionObject;
14
+ exports.readBoolean = readBoolean;
15
+ exports.readNameSet = readNameSet;
16
+ exports.nameListSchema = nameListSchema;
17
+ /**
18
+ * One positional option, as an object, or an empty one when it is absent or is
19
+ * not an object. Every reader below then falls back to its default, which is
20
+ * what an omitted option should do.
21
+ */
22
+ function optionObject(options, index) {
23
+ const value = options[index];
24
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
25
+ return value;
26
+ }
27
+ return {};
28
+ }
29
+ /** A boolean field of an options object, or `fallback` when it is absent. */
30
+ function readBoolean(option, key, fallback) {
31
+ const value = option[key];
32
+ return typeof value === 'boolean' ? value : fallback;
33
+ }
34
+ /**
35
+ * A list-of-strings field of an options object, as a set, or `fallback` when it
36
+ * is absent.
37
+ *
38
+ * A configured list replaces the default rather than extending it. That is the
39
+ * ESLint convention, and for these rules it is also the useful behaviour: a
40
+ * project that names its logger `report` wants `report` recognised, and a
41
+ * project that has deliberately narrowed the list wants the entries it removed
42
+ * to stay removed.
43
+ */
44
+ function readNameSet(option, key, fallback) {
45
+ const value = option[key];
46
+ if (Array.isArray(value)) {
47
+ const names = value.filter((entry) => typeof entry === 'string');
48
+ return new Set(names);
49
+ }
50
+ return new Set(fallback);
51
+ }
52
+ /** The JSON Schema for an option that is a list of names. */
53
+ function nameListSchema() {
54
+ return { type: 'array', items: { type: 'string' }, uniqueItems: true };
55
+ }
56
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAOH,oCASC;AAGD,kCAOC;AAYD,kCAWC;AAGD,wCAEC;AApDD;;;;GAIG;AACH,SAAgB,YAAY,CAC1B,OAA2B,EAC3B,KAAa;IAEb,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,OAAO,KAA0C,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,6EAA6E;AAC7E,SAAgB,WAAW,CACzB,MAAyC,EACzC,GAAW,EACX,QAAiB;IAEjB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,WAAW,CACzB,MAAyC,EACzC,GAAW,EACX,QAA2B;IAE3B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;QAClF,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED,6DAA6D;AAC7D,SAAgB,cAAc;IAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from '../types.js';
2
+ export declare const explicitClass: RuleModule;
3
+ //# sourceMappingURL=explicit-class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explicit-class.d.ts","sourceRoot":"","sources":["../../src/rules/explicit-class.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAIV,UAAU,EAEX,MAAM,aAAa,CAAC;AAUrB,eAAO,MAAM,aAAa,EAAE,UA2F3B,CAAC"}
@@ -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":"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"}
@@ -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,yBAAyB,GAAsB,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;AAEhG;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,IAAa;IACnC,MAAM,KAAK,GAAG,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,IAAK,KAAwC,CAAC,KAAK,KAAK,KAAK,CAAC;AAC/F,CAAC;AAEY,QAAA,gBAAgB,GAAe;IAC1C,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAA,kBAAQ,EACZ,SAAS,EACT,wHAAwH,EACxH,IAAI,CACL;QACD,QAAQ,EAAE;YACR,cAAc,EACZ,mWAAmW;SACtW;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE,IAAA,2BAAc,GAAE;iBACnC;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,gBAAgB,GAAG,IAAA,wBAAW,EAAC,MAAM,EAAE,kBAAkB,EAAE,yBAAyB,CAAC,CAAC;QAE5F,OAAO;YACL,cAAc,CAAC,IAAa;gBAC1B,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC;gBAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACzB,OAAO;gBACT,CAAC;gBAED,sEAAsE;gBACtE,4BAA4B;gBAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,yBAAgB,EAAC,MAAM,CAAC,CAAC;gBAC1C,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1D,OAAO;gBACT,CAAC;gBAED,mEAAmE;gBACnE,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"}