@pluv/platform-pluv 0.38.3 → 0.38.4

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/platform-pluv@0.38.3 build /home/runner/work/pluv/pluv/packages/platform-pluv
2
+ > @pluv/platform-pluv@0.38.4 build /home/runner/work/pluv/pluv/packages/platform-pluv
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 9.86 KB
12
- ESM ⚡️ Build success in 80ms
13
- CJS dist/index.js 11.40 KB
11
+ ESM dist/index.mjs 10.13 KB
12
+ ESM ⚡️ Build success in 87ms
13
+ CJS dist/index.js 11.66 KB
14
14
  CJS ⚡️ Build success in 88ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 6145ms
16
+ DTS ⚡️ Build success in 6854ms
17
17
  DTS dist/index.d.mts 3.56 KB
18
18
  DTS dist/index.d.ts 3.56 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 0.38.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 15399b7: Fix webhook signature validation.
8
+ - @pluv/crdt@0.38.4
9
+ - @pluv/io@0.38.4
10
+ - @pluv/types@0.38.4
11
+
3
12
  ## 0.38.3
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ var import_fast_json_stable_stringify = __toESM(require("fast-json-stable-string
75
75
  var import_hono = require("hono");
76
76
 
77
77
  // src/constants.ts
78
+ var SIGNATURE_ALGORITHM = "sha256";
78
79
  var SIGNATURE_HEADER = "x-pluv-signature-256";
79
80
 
80
81
  // src/schemas.ts
@@ -214,9 +215,11 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
214
215
  return token;
215
216
  });
216
217
  this._webhooks = new import_hono.Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
217
- var _a, _b, _c, _d, _e;
218
- const signature = c.req.header(SIGNATURE_HEADER);
219
- if (!this._webhookSecret || !signature) return c.json({ error: "Unauthorized" }, 401);
218
+ var _a, _b, _c, _d, _e, _f, _g;
219
+ const [algorithm, signature] = (_b = (_a = c.req.header(SIGNATURE_HEADER)) == null ? void 0 : _a.split("=")) != null ? _b : [];
220
+ if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
221
+ if (algorithm !== SIGNATURE_ALGORITHM) return c.json({ error: "Unauthorized" }, 401);
222
+ if (!signature) return c.json({ error: "Unauthorized" }, 401);
220
223
  const payload = yield c.req.json();
221
224
  const verified = yield verifyWebhook({
222
225
  payload: (0, import_fast_json_stable_stringify.default)(payload),
@@ -230,26 +233,26 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
230
233
  switch (event) {
231
234
  case "initial-storage": {
232
235
  const room = data.room;
233
- const storage = typeof room === "string" ? (_b = yield (_a = this._getInitialStorage) == null ? void 0 : _a.call(this, { context: {}, room })) != null ? _b : null : null;
236
+ const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context: {}, room })) != null ? _d : null : null;
234
237
  return c.json({ data: { storage } }, 200);
235
238
  }
236
239
  case "room-deleted": {
237
240
  const room = data.room;
238
241
  const encodedState = data.storage;
239
- yield Promise.resolve((_c = this._listeners) == null ? void 0 : _c.onRoomDeleted({ encodedState, room }));
242
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ encodedState, room }));
240
243
  return c.json({ data: { room } }, 200);
241
244
  }
242
245
  case "user-connected": {
243
246
  const room = data.room;
244
247
  const encodedState = data.storage;
245
248
  const user = data.user;
246
- yield Promise.resolve((_d = this._listeners) == null ? void 0 : _d.onUserConnected({ encodedState, room, user }));
249
+ yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ encodedState, room, user }));
247
250
  }
248
251
  case "user-disconnected": {
249
252
  const room = data.room;
250
253
  const encodedState = data.storage;
251
254
  const user = data.user;
252
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onUserDisconnected({ encodedState, room, user }));
255
+ yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ encodedState, room, user }));
253
256
  }
254
257
  default:
255
258
  return c.json({ data: { ok: true } }, 200);
package/dist/index.mjs CHANGED
@@ -47,6 +47,7 @@ import stringify from "fast-json-stable-stringify";
47
47
  import { Hono } from "hono";
48
48
 
49
49
  // src/constants.ts
50
+ var SIGNATURE_ALGORITHM = "sha256";
50
51
  var SIGNATURE_HEADER = "x-pluv-signature-256";
51
52
 
52
53
  // src/schemas.ts
@@ -186,9 +187,11 @@ var PluvPlatform = class extends AbstractPlatform {
186
187
  return token;
187
188
  });
188
189
  this._webhooks = new Hono().basePath("/").post("/", (c) => __async(this, null, function* () {
189
- var _a, _b, _c, _d, _e;
190
- const signature = c.req.header(SIGNATURE_HEADER);
191
- if (!this._webhookSecret || !signature) return c.json({ error: "Unauthorized" }, 401);
190
+ var _a, _b, _c, _d, _e, _f, _g;
191
+ const [algorithm, signature] = (_b = (_a = c.req.header(SIGNATURE_HEADER)) == null ? void 0 : _a.split("=")) != null ? _b : [];
192
+ if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
193
+ if (algorithm !== SIGNATURE_ALGORITHM) return c.json({ error: "Unauthorized" }, 401);
194
+ if (!signature) return c.json({ error: "Unauthorized" }, 401);
192
195
  const payload = yield c.req.json();
193
196
  const verified = yield verifyWebhook({
194
197
  payload: stringify(payload),
@@ -202,26 +205,26 @@ var PluvPlatform = class extends AbstractPlatform {
202
205
  switch (event) {
203
206
  case "initial-storage": {
204
207
  const room = data.room;
205
- const storage = typeof room === "string" ? (_b = yield (_a = this._getInitialStorage) == null ? void 0 : _a.call(this, { context: {}, room })) != null ? _b : null : null;
208
+ const storage = typeof room === "string" ? (_d = yield (_c = this._getInitialStorage) == null ? void 0 : _c.call(this, { context: {}, room })) != null ? _d : null : null;
206
209
  return c.json({ data: { storage } }, 200);
207
210
  }
208
211
  case "room-deleted": {
209
212
  const room = data.room;
210
213
  const encodedState = data.storage;
211
- yield Promise.resolve((_c = this._listeners) == null ? void 0 : _c.onRoomDeleted({ encodedState, room }));
214
+ yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onRoomDeleted({ encodedState, room }));
212
215
  return c.json({ data: { room } }, 200);
213
216
  }
214
217
  case "user-connected": {
215
218
  const room = data.room;
216
219
  const encodedState = data.storage;
217
220
  const user = data.user;
218
- yield Promise.resolve((_d = this._listeners) == null ? void 0 : _d.onUserConnected({ encodedState, room, user }));
221
+ yield Promise.resolve((_f = this._listeners) == null ? void 0 : _f.onUserConnected({ encodedState, room, user }));
219
222
  }
220
223
  case "user-disconnected": {
221
224
  const room = data.room;
222
225
  const encodedState = data.storage;
223
226
  const user = data.user;
224
- yield Promise.resolve((_e = this._listeners) == null ? void 0 : _e.onUserDisconnected({ encodedState, room, user }));
227
+ yield Promise.resolve((_g = this._listeners) == null ? void 0 : _g.onUserDisconnected({ encodedState, room, user }));
225
228
  }
226
229
  default:
227
230
  return c.json({ data: { ok: true } }, 200);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "0.38.3",
3
+ "version": "0.38.4",
4
4
  "description": "@pluv/io adapter for pluv.io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "fast-json-stable-stringify": "^2.1.0",
22
22
  "hono": "^4.7.4",
23
23
  "zod": "^3.24.2",
24
- "@pluv/crdt": "^0.38.3",
25
- "@pluv/io": "^0.38.3",
26
- "@pluv/types": "^0.38.3"
24
+ "@pluv/crdt": "^0.38.4",
25
+ "@pluv/io": "^0.38.4",
26
+ "@pluv/types": "^0.38.4"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^8.57.1",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.2",
32
- "@pluv/tsconfig": "^0.38.3",
33
- "eslint-config-pluv": "^0.38.3"
32
+ "@pluv/tsconfig": "^0.38.4",
33
+ "eslint-config-pluv": "^0.38.4"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -9,7 +9,7 @@ import type {
9
9
  import { AbstractPlatform } from "@pluv/io";
10
10
  import stringify from "fast-json-stable-stringify";
11
11
  import { Hono } from "hono";
12
- import { SIGNATURE_HEADER } from "./constants";
12
+ import { SIGNATURE_ALGORITHM, SIGNATURE_HEADER } from "./constants";
13
13
  import { ZodEvent } from "./schemas";
14
14
  import { verifyWebhook } from "./shared";
15
15
  import type { PluvIOEndpoints, PluvIOListeners } from "./types";
@@ -183,9 +183,11 @@ export class PluvPlatform extends AbstractPlatform<
183
183
  }
184
184
 
185
185
  private _webhooks = new Hono().basePath("/").post("/", async (c) => {
186
- const signature = c.req.header(SIGNATURE_HEADER);
186
+ const [algorithm, signature] = c.req.header(SIGNATURE_HEADER)?.split("=") ?? [];
187
187
 
188
- if (!this._webhookSecret || !signature) return c.json({ error: "Unauthorized" }, 401);
188
+ if (!this._webhookSecret) return c.json({ error: "Unauthorized" }, 401);
189
+ if (algorithm !== SIGNATURE_ALGORITHM) return c.json({ error: "Unauthorized" }, 401);
190
+ if (!signature) return c.json({ error: "Unauthorized" }, 401);
189
191
 
190
192
  const payload = await c.req.json();
191
193
 
package/src/constants.ts CHANGED
@@ -1 +1,2 @@
1
+ export const SIGNATURE_ALGORITHM = "sha256";
1
2
  export const SIGNATURE_HEADER = "x-pluv-signature-256";