Skip to content

Commit 2bc571c

Browse files
committed
fix signing
1 parent 0e96912 commit 2bc571c

File tree

8 files changed

+55
-8
lines changed

8 files changed

+55
-8
lines changed

.changeset/mean-waves-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"basehub": patch
3+
---
4+
5+
fix

.changeset/pre.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"lucky-eyes-ring",
3030
"many-cherries-sleep",
3131
"mean-panthers-give",
32+
"mean-waves-study",
3233
"modern-tools-repeat",
3334
"nasty-bananas-ring",
3435
"nasty-insects-teach",
@@ -40,6 +41,7 @@
4041
"perfect-cougars-shout",
4142
"popular-pots-help",
4243
"quick-experts-complain",
44+
"selfish-ligers-roll",
4345
"shaggy-months-talk",
4446
"short-spiders-taste",
4547
"six-sheep-dress",

.changeset/selfish-ligers-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"basehub": patch
3+
---
4+
5+
fix secret parsing

packages/basehub/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# basehub
22

3+
## 8.0.0-canary.45
4+
5+
### Patch Changes
6+
7+
- fix secret parsing
8+
9+
## 8.0.0-canary.44
10+
11+
### Patch Changes
12+
13+
- fix
14+
315
## 8.0.0-canary.43
416

517
### Patch Changes

packages/basehub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "basehub",
33
"description": "A very fast Headless CMS.",
44
"author": "JB <[email protected]>",
5-
"version": "8.0.0-canary.43",
5+
"version": "8.0.0-canary.45",
66
"license": "MIT",
77
"repository": "basehub-ai/basehub",
88
"bugs": "https://github.com/basehub-ai/basehub/issues",

packages/basehub/src/workflows/primitive.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
// @ts-ignore
66
// eslint-disable-next-line import/no-unresolved
77
} from "../schema";
8-
import crypto from "crypto";
98

109
/* -------------------------------------------------------------------------------------------------
1110
* Client
@@ -31,7 +30,7 @@ type WorkflowSchemaMap = {
3130
export const authenticateWebhook = async <
3231
Key extends `${WorkflowKeys}:${string}`,
3332
>({
34-
secret,
33+
secret: _secret,
3534
body,
3635
signature,
3736
}: {
@@ -65,6 +64,14 @@ export const authenticateWebhook = async <
6564
return { success: false, error: "Signature is required" };
6665
}
6766

67+
let secret: string | undefined = _secret;
68+
if (_secret.startsWith("bshb_workflow")) {
69+
secret = _secret.split(":")[1];
70+
}
71+
if (typeof secret !== "string") {
72+
return { success: false, error: "Invalid secret" };
73+
}
74+
6875
// Handle different body types
6976
let rawBody: string;
7077
let parsedBody: unknown;
@@ -131,12 +138,14 @@ export const authenticateWebhook = async <
131138
payload: parsedBody as WorkflowSchemaMap[ExtractWorkflowKey<Key>],
132139
};
133140
} catch (error) {
141+
let message =
142+
error instanceof Error ? error.message : "Signature verification failed";
143+
if (message === "Unexpected end of JSON input") {
144+
message = "Invalid body";
145+
}
134146
return {
135147
success: false,
136-
error:
137-
error instanceof Error
138-
? error.message
139-
: "Signature verification failed",
148+
error: message,
140149
};
141150
}
142151
};

playground/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# playground
22

3+
## 0.0.164-canary.45
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
9+
10+
## 0.0.164-canary.44
11+
12+
### Patch Changes
13+
14+
- Updated dependencies
15+
16+
317
## 0.0.164-canary.43
418

519
### Patch Changes

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "playground",
33
"private": true,
4-
"version": "0.0.164-canary.43",
4+
"version": "0.0.164-canary.45",
55
"scripts": {
66
"dev": "basehub dev & next dev --port 3003",
77
"build": "basehub && next build",

0 commit comments

Comments
 (0)