eslint-plugin-webhook-safety 0.0.0-stage → 0.2.0
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +85 -2
- package/dist/index.cjs +574 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +572 -0
- package/dist/index.js.map +1 -0
- package/docs/rules/bullmq-require-job-id.md +40 -0
- package/docs/rules/require-idempotency.md +63 -0
- package/docs/rules/require-raw-body.md +64 -0
- package/docs/rules/require-signature-verification.md +52 -0
- package/package.json +79 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2026-10-22)
|
|
4
|
+
|
|
5
|
+
- `require-idempotency` is now conservative: it reports only **direct** writes in the handler (DB, queue, email,
|
|
6
|
+
payment calls) with no `event.id` use, and points at that write. Helper calls that receive event-derived data
|
|
7
|
+
are treated as possibly idempotent (false positive found on twentyhq/twenty). New `strict` option restores
|
|
8
|
+
the broader check. The message now reads as a suggestion and links the docs.
|
|
9
|
+
- `require-signature-verification` no longer reports handlers that pass the request to a helper (verification in another file).
|
|
10
|
+
- `require-raw-body` ignores `express.json({ verify })` and handlers that verify something other than `req.body` (e.g. `req.rawBody`).
|
|
11
|
+
- README: correct example output and a TypeScript setup section.
|
|
12
|
+
- Release smoke test now covers ESLint 8.57 (flat and legacy), 9, 10 and `@typescript-eslint/parser`. CI adds Windows.
|
|
13
|
+
|
|
14
|
+
## 0.1.0 (2026-10-22)
|
|
15
|
+
|
|
16
|
+
- Rules: `require-raw-body`, `require-signature-verification`, `require-idempotency`, `bullmq-require-job-id`.
|
|
17
|
+
- Configs: `recommended`, `strict`, `legacy-recommended`, `legacy-strict`.
|
|
18
|
+
- Tested on 8 open-source apps (Stripe/BullMQ users). False positives fixed before release:
|
|
19
|
+
- `require-signature-verification` ignores authenticated endpoints (e.g. CRUD APIs that manage webhook subscriptions).
|
|
20
|
+
- `require-idempotency` ignores verify-and-return wrappers that return the event to the caller.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krrish Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# eslint-plugin-webhook-safety
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/Krrishkumar125/eslint-plugin-webhook-safety/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
ESLint rules that catch the Stripe webhook bugs that only show up in production:
|
|
6
|
+
|
|
7
|
+
- the body was parsed before the signature check, so every event fails;
|
|
8
|
+
- the signature is never checked;
|
|
9
|
+
- duplicate deliveries are processed twice;
|
|
10
|
+
- retries enqueue the same BullMQ job twice.
|
|
11
|
+
|
|
12
|
+
The static half of [webhook-crash-lab](https://github.com/Krrishkumar125/webhook-crash-lab).
|
|
13
|
+
This plugin finds the bug in your editor, and crash-lab proves the fix against a running server.
|
|
14
|
+
|
|
15
|
+
## 60-second start
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm i -D eslint eslint-plugin-webhook-safety
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// eslint.config.js
|
|
23
|
+
import webhookSafety from 'eslint-plugin-webhook-safety';
|
|
24
|
+
|
|
25
|
+
export default [
|
|
26
|
+
webhookSafety.configs.recommended, // or .strict
|
|
27
|
+
];
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
// server.js
|
|
32
|
+
app.use(express.json());
|
|
33
|
+
app.post('/webhooks/stripe', async (req, res) => {
|
|
34
|
+
const event = stripe.webhooks.constructEvent(req.body, sig, secret);
|
|
35
|
+
await emailQueue.add('receipt', { to: event.data.object.customer_email });
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
$ npx eslint server.js
|
|
41
|
+
2:1 error `app.use(express.json())` on line 1 runs before this webhook route and parses the body ... webhook-safety/require-raw-body
|
|
42
|
+
4:9 warning Consider a duplicate-event check: Stripe can deliver `event` more than once ... webhook-safety/require-idempotency
|
|
43
|
+
4:9 warning Webhook deliveries are retried, so this queue.add() will enqueue the same work twice ... webhook-safety/bullmq-require-job-id
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Rules
|
|
47
|
+
|
|
48
|
+
| Rule | What it catches | recommended | strict | 💡 |
|
|
49
|
+
| ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | ----------- | ------ | --- |
|
|
50
|
+
| [require-raw-body](docs/rules/require-raw-body.md) | `express.json()` / `req.json()` / `JSON.stringify` before `constructEvent` | error | error | ✅ |
|
|
51
|
+
| [require-signature-verification](docs/rules/require-signature-verification.md) | webhook route or Next.js `POST` with no signature check | error | error | |
|
|
52
|
+
| [require-idempotency](docs/rules/require-idempotency.md) | DB/queue/email/payment write in the handler with no `event.id` dedupe | warn | error | |
|
|
53
|
+
| [bullmq-require-job-id](docs/rules/bullmq-require-job-id.md) | `queue.add()` in a webhook handler without `jobId` | warn | error | ✅ |
|
|
54
|
+
|
|
55
|
+
The rules are tuned for **low false positives**. When in doubt (custom middleware, the event passed to a
|
|
56
|
+
helper, options passed as a variable) they stay quiet. Each rule doc lists exactly what triggers it.
|
|
57
|
+
|
|
58
|
+
Supports Express, Hono, Fastify-style routers and the Next.js App Router, in JavaScript and TypeScript.
|
|
59
|
+
|
|
60
|
+
### TypeScript
|
|
61
|
+
|
|
62
|
+
ESLint only lints `.ts` files that some config object matches, so pair the plugin with
|
|
63
|
+
`typescript-eslint` (or at least its parser):
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// eslint.config.js
|
|
67
|
+
import tseslint from 'typescript-eslint';
|
|
68
|
+
import webhookSafety from 'eslint-plugin-webhook-safety';
|
|
69
|
+
|
|
70
|
+
export default [...tseslint.configs.recommended, webhookSafety.configs.recommended];
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Legacy `.eslintrc` (ESLint 8)
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{ "extends": ["plugin:webhook-safety/legacy-recommended"] }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Requirements
|
|
80
|
+
|
|
81
|
+
ESLint 8.57+, 9 or 10 (flat config, or `.eslintrc` via the legacy configs) and Node ≥ 20. Every release is
|
|
82
|
+
smoke-tested from the packed tarball against ESLint 8.57 (flat and legacy), 9, 10 and `@typescript-eslint/parser`.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT © Krrish Kumar
|