@platform-sec/eslint-plugin-sensitive-string 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +193 -2
- package/dist/ast.d.ts +172 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +418 -0
- package/dist/ast.js.map +1 -0
- package/dist/configs.d.ts +38 -0
- package/dist/configs.d.ts.map +1 -0
- package/dist/configs.js +131 -0
- package/dist/configs.js.map +1 -0
- package/dist/docs.d.ts +28 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +33 -0
- package/dist/docs.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/log-calls.d.ts +28 -0
- package/dist/log-calls.d.ts.map +1 -0
- package/dist/log-calls.js +80 -0
- package/dist/log-calls.js.map +1 -0
- package/dist/options.d.ts +32 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +56 -0
- package/dist/options.js.map +1 -0
- package/dist/rules/explicit-class.d.ts +3 -0
- package/dist/rules/explicit-class.d.ts.map +1 -0
- package/dist/rules/explicit-class.js +93 -0
- package/dist/rules/explicit-class.js.map +1 -0
- package/dist/rules/no-allow-unaudited.d.ts +3 -0
- package/dist/rules/no-allow-unaudited.d.ts.map +1 -0
- package/dist/rules/no-allow-unaudited.js +92 -0
- package/dist/rules/no-allow-unaudited.js.map +1 -0
- package/dist/rules/no-credential-equality.d.ts +3 -0
- package/dist/rules/no-credential-equality.d.ts.map +1 -0
- package/dist/rules/no-credential-equality.js +146 -0
- package/dist/rules/no-credential-equality.js.map +1 -0
- package/dist/rules/no-log-reveal.d.ts +3 -0
- package/dist/rules/no-log-reveal.d.ts.map +1 -0
- package/dist/rules/no-log-reveal.js +67 -0
- package/dist/rules/no-log-reveal.js.map +1 -0
- package/dist/rules/no-network-sensitive.d.ts +3 -0
- package/dist/rules/no-network-sensitive.d.ts.map +1 -0
- package/dist/rules/no-network-sensitive.js +106 -0
- package/dist/rules/no-network-sensitive.js.map +1 -0
- package/dist/rules/no-password-fast-hash.d.ts +3 -0
- package/dist/rules/no-password-fast-hash.d.ts.map +1 -0
- package/dist/rules/no-password-fast-hash.js +84 -0
- package/dist/rules/no-password-fast-hash.js.map +1 -0
- package/dist/rules/no-stringify-sensitive.d.ts +3 -0
- package/dist/rules/no-stringify-sensitive.d.ts.map +1 -0
- package/dist/rules/no-stringify-sensitive.js +96 -0
- package/dist/rules/no-stringify-sensitive.js.map +1 -0
- package/dist/rules/prefer-safe-log.d.ts +3 -0
- package/dist/rules/prefer-safe-log.d.ts.map +1 -0
- package/dist/rules/prefer-safe-log.js +85 -0
- package/dist/rules/prefer-safe-log.js.map +1 -0
- package/dist/rules/require-reveal-context.d.ts +3 -0
- package/dist/rules/require-reveal-context.d.ts.map +1 -0
- package/dist/rules/require-reveal-context.js +149 -0
- package/dist/rules/require-reveal-context.js.map +1 -0
- package/dist/type-info.d.ts +134 -0
- package/dist/type-info.d.ts.map +1 -0
- package/dist/type-info.js +282 -0
- package/dist/type-info.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/docs/rules/explicit-class.md +62 -0
- package/docs/rules/no-allow-unaudited.md +93 -0
- package/docs/rules/no-credential-equality.md +69 -0
- package/docs/rules/no-log-reveal.md +104 -0
- package/docs/rules/no-network-sensitive.md +74 -0
- package/docs/rules/no-password-fast-hash.md +95 -0
- package/docs/rules/no-stringify-sensitive.md +144 -0
- package/docs/rules/prefer-safe-log.md +131 -0
- package/docs/rules/require-reveal-context.md +128 -0
- package/package.json +49 -3
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# require-reveal-context
|
|
2
|
+
|
|
3
|
+
Require an audit context on `reveal()`, and on `mask()`, `hash()`, `hmac()` and
|
|
4
|
+
`serialize()` where types are available, from an argument or an enclosing
|
|
5
|
+
`withRevealContext()`.
|
|
6
|
+
|
|
7
|
+
Severity in `recommended`: **warn**.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
The audit hook records that a value was read. Without a context it cannot record
|
|
12
|
+
*who* read it or *why*, which is the part an incident review needs.
|
|
13
|
+
|
|
14
|
+
Four other methods are read the same way by the library. `mask()` returns a
|
|
15
|
+
partial view as a plain string and `serialize()` returns the raw value in a wire
|
|
16
|
+
object; `hash()` and `hmac()` keep the result wrapped but reach the value
|
|
17
|
+
through the same gate, charge the same reveal budget, and write the same audit
|
|
18
|
+
record with `operation: 'hash'` on it. A record saying a credential was read,
|
|
19
|
+
with nothing about who read it, is the gap this rule exists to close, whichever
|
|
20
|
+
method produced it.
|
|
21
|
+
|
|
22
|
+
What is not covered is the transforms, `substring` and `map` and the rest. They
|
|
23
|
+
audit too, and requiring a context on `token.trim()` would make the rule
|
|
24
|
+
unusable long before it made an audit log better.
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
Incorrect:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const raw = secret.reveal();
|
|
32
|
+
secret.reveal(undefined);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Only where types are available; see below.
|
|
37
|
+
const lookupKey = token.hash('sha256');
|
|
38
|
+
const pseudonym = email.hmac('sha256', key);
|
|
39
|
+
const shown = card.mask({ showLast: 4 });
|
|
40
|
+
const payload = token.serialize();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Correct:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
const raw = secret.reveal({ name: 'payment', reason: 'charging the card' });
|
|
47
|
+
|
|
48
|
+
await withRevealContext({ name: 'handler' }, async () => {
|
|
49
|
+
const raw = secret.reveal(); // context comes from AsyncLocalStorage
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const lookupKey = token.hash('sha256', {}, { name: 'session-lookup' });
|
|
55
|
+
const pseudonym = email.hmac('sha256', key, {}, ctx);
|
|
56
|
+
const shown = card.mask({ showLast: 4 }, { name: 'support-screen' });
|
|
57
|
+
const payload = token.serialize({ name: 'transfer' });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The context is the argument each method actually takes it in: the first for
|
|
61
|
+
`reveal()` and `serialize()`, the second for `mask()`, the third for `hash()`,
|
|
62
|
+
the fourth for `hmac()`. An options object in the position before it is not a
|
|
63
|
+
context, and is reported as one missing.
|
|
64
|
+
|
|
65
|
+
## What needs type information
|
|
66
|
+
|
|
67
|
+
`reveal()` is matched by its name, in every configuration. The other four are
|
|
68
|
+
matched only when the receiver's type can be read and is a `SensitiveString` or
|
|
69
|
+
something extending one. `reveal` by name and everything else by type is the
|
|
70
|
+
whole rule in a line.
|
|
71
|
+
|
|
72
|
+
That asymmetry is deliberate. `magician.reveal()` being reported is the standing
|
|
73
|
+
cost of an untyped rule, and `.reveal()` is rare enough for that to be a fair
|
|
74
|
+
trade. The others are not: `bcrypt` and `node:crypto` have a `hash`, every ORM
|
|
75
|
+
and form library has a `serialize`, `mask` belongs to half the input libraries
|
|
76
|
+
on npm, and a rule that reported those in a codebase would be turned off within
|
|
77
|
+
the hour.
|
|
78
|
+
|
|
79
|
+
In a file with no program the rule stays on and checks `reveal()` alone. It does
|
|
80
|
+
not report the missing type information the way `no-stringify-sensitive` does,
|
|
81
|
+
because it is not reduced to silence: most of its job needs no types.
|
|
82
|
+
|
|
83
|
+
The same goes for a receiver the checker knows nothing about. A value typed
|
|
84
|
+
`any` is not a wrapper as far as this rule can tell, so a `.hash()` on one is
|
|
85
|
+
not reported. That is the direction to miss in: the alternative is reporting
|
|
86
|
+
every `.hash()` call in a file that lost its types to one `any`.
|
|
87
|
+
|
|
88
|
+
## Options
|
|
89
|
+
|
|
90
|
+
| Option | Default |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `requireReason` | `false` |
|
|
93
|
+
| `contextFunctions` | `withRevealContext`, `withAuditedReveals` |
|
|
94
|
+
| `sensitiveTypes` | `SensitiveString` |
|
|
95
|
+
|
|
96
|
+
`requireReason: true` additionally reports a context object literal with no
|
|
97
|
+
`reason` key. An object built elsewhere, or one carrying a spread, is left
|
|
98
|
+
alone: reading what it contributes means following a value rather than naming a
|
|
99
|
+
type, which is not what the receiver check above does, and warning on a context
|
|
100
|
+
that is very likely complete would train people to disable the rule. The `strict` preset sets it.
|
|
101
|
+
|
|
102
|
+
## Why this is a warning
|
|
103
|
+
|
|
104
|
+
The enclosing-context check is lexical. It sees
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
withRevealContext(ctx, () => secret.reveal());
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
and misses a reveal in a function that is merely *called* from inside one:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
withRevealContext(ctx, () => readSecret());
|
|
114
|
+
function readSecret() {
|
|
115
|
+
return secret.reveal(); // reported, though the context is present at runtime
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Following that would need a call graph. The rule is therefore wrong in the
|
|
120
|
+
direction of a needless warning, never a missed one, and a warning is the honest
|
|
121
|
+
severity for a check with that shape.
|
|
122
|
+
|
|
123
|
+
`reveal` is also matched by name, so an unrelated `magician.reveal()` is
|
|
124
|
+
reported. That is the standing cost of a rule that reads syntax rather than
|
|
125
|
+
types, and the reason the other four are not matched that way.
|
|
126
|
+
|
|
127
|
+
A spread ahead of the context argument, `secret.hash(...args)`, is left alone:
|
|
128
|
+
which argument is the context stops being a question syntax can answer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platform-sec/eslint-plugin-sensitive-string",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "ESLint rules that catch the mistakes SensitiveString's type system cannot: logged reveals, timing-unsafe comparisons, and unaudited transmission",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"docs"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"eslint",
|
|
20
|
+
"eslintplugin",
|
|
21
|
+
"eslint-plugin",
|
|
22
|
+
"security",
|
|
23
|
+
"sensitive-data",
|
|
24
|
+
"redaction",
|
|
25
|
+
"static-analysis",
|
|
26
|
+
"typescript"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/platform-sec/sensitive-string-js.git",
|
|
32
|
+
"directory": "packages/sensitive-eslint-plugin"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.12.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"eslint": ">=8.40.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.20.5",
|
|
42
|
+
"@typescript-eslint/parser": "^8.72.1",
|
|
43
|
+
"eslint": "^9.39.5",
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"vitest": "^4.1.12"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "vitest run --root ../.. packages/sensitive-eslint-plugin/",
|
|
50
|
+
"test:watch": "vitest --root ../.. packages/sensitive-eslint-plugin/"
|
|
51
|
+
}
|
|
6
52
|
}
|