slashbin-receiver-kit 1.1.0-next.1 → 1.1.1-next.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/README.md +76 -0
- package/package.json +7 -1
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# slashbin-receiver-kit
|
|
2
|
+
|
|
3
|
+
Verifies Slashbin's delivery signature in the code behind a Slashbin destination (your receiver). The check fails closed: a request with no key configured, no signature header or a wrong signature is refused.
|
|
4
|
+
|
|
5
|
+
This package is code you run in your own service. It is not a hosted Slashbin service.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install slashbin-receiver-kit express
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## The signature
|
|
14
|
+
|
|
15
|
+
Each delivery carries this header, where the value is the lowercase hex HMAC-SHA256 of the raw request body, keyed with your signing key:
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
x-slashbin-signature: sha256=<hex HMAC-SHA256 of the raw body>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The signature covers the bytes received. Verifying a re-serialized body fails.
|
|
22
|
+
|
|
23
|
+
## Usage with Express
|
|
24
|
+
|
|
25
|
+
**`express.raw()` must be mounted before `slashbinSignatureMiddleware`.** The middleware reads `req.body` as the raw `Buffer` Slashbin sent. If a JSON body parser runs first, the body is no longer the original bytes and every delivery is rejected.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import express from "express";
|
|
29
|
+
import { ReceiverSignatureVerifier, slashbinSignatureMiddleware } from "slashbin-receiver-kit";
|
|
30
|
+
|
|
31
|
+
const verifier = new ReceiverSignatureVerifier({
|
|
32
|
+
keys: [process.env.SLASHBIN_SIGNING_KEY ?? ""],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const app = express();
|
|
36
|
+
|
|
37
|
+
app.post(
|
|
38
|
+
"/slashbin",
|
|
39
|
+
express.raw({ type: "*/*" }),
|
|
40
|
+
slashbinSignatureMiddleware(verifier, { source: "slashbin", logger: console }),
|
|
41
|
+
(req, res) => {
|
|
42
|
+
// req.body is the verified raw Buffer. Parse it here.
|
|
43
|
+
res.sendStatus(202);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
app.get("/health", (_req, res) => {
|
|
48
|
+
res.json(verifier.health());
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Key rotation
|
|
53
|
+
|
|
54
|
+
Pass two keys during a rotation so deliveries signed with either are accepted:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { ReceiverSignatureVerifier } from "slashbin-receiver-kit";
|
|
58
|
+
|
|
59
|
+
export const rotating = new ReceiverSignatureVerifier({
|
|
60
|
+
keys: [process.env.SLASHBIN_SIGNING_KEY_OLD ?? "", process.env.SLASHBIN_SIGNING_KEY_NEW ?? ""],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`verify()` returns the index of the key that matched. Empty strings are dropped.
|
|
65
|
+
|
|
66
|
+
## Failures you can see
|
|
67
|
+
|
|
68
|
+
- A rejected request gets status 401 with the fixed body `{"error":"Invalid signature"}`. The reason is never sent to the caller.
|
|
69
|
+
- The reason (`missing-key`, `missing-header` or `bad-signature`) is written to your logger as a `slashbin.signature.rejected` event, with `source`, `reason` and `signingKeys`.
|
|
70
|
+
- With zero keys configured, `health()` reports `{ status: "degraded", signingKeys: 0 }` and every request is refused as `missing-key`. A missing or blank key shows up in health and logs instead of silently accepting traffic.
|
|
71
|
+
|
|
72
|
+
## Source and licence
|
|
73
|
+
|
|
74
|
+
Source and issues: <https://github.com/slashbin-io/slashbin_kits>
|
|
75
|
+
|
|
76
|
+
MIT licence.
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slashbin-receiver-kit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1-next.1",
|
|
4
4
|
"description": "Receiver-side kit for code behind a Slashbin destination: fail-closed, multi-key verification of Slashbin's delivery signature.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/slashbin-io/slashbin_kits.git",
|
|
9
|
+
"directory": "packages/receiver-kit"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/slashbin-io/slashbin_kits/tree/main/packages/receiver-kit#readme",
|
|
6
12
|
"type": "module",
|
|
7
13
|
"main": "./dist/index.js",
|
|
8
14
|
"types": "./dist/index.d.ts",
|