@terreno/api 57.1.0 → 57.3.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/README.md +17 -7
- package/dist/actions.js +19 -7
- package/dist/adminTypes.d.ts +26 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.js +12 -24
- package/dist/auth.d.ts +23 -10
- package/dist/auth.js +97 -32
- package/dist/authRecovery.d.ts +5 -0
- package/dist/authRecovery.js +350 -0
- package/dist/authTokens.d.ts +8 -0
- package/dist/authTokens.js +162 -0
- package/dist/betterAuth.d.ts +33 -0
- package/dist/betterAuthApp.d.ts +4 -0
- package/dist/betterAuthApp.js +26 -8
- package/dist/betterAuthSetup.d.ts +44 -2
- package/dist/betterAuthSetup.js +288 -18
- package/dist/collectionRegistry.d.ts +38 -0
- package/dist/collectionRegistry.js +72 -0
- package/dist/configurationApp.d.ts +11 -2
- package/dist/configurationApp.js +2 -4
- package/dist/docLoader.js +35 -6
- package/dist/expressServer.d.ts +26 -3
- package/dist/expressServer.js +79 -11
- package/dist/index.d.ts +16 -0
- package/dist/index.js +38 -2
- package/dist/mcp/auth.d.ts +1 -0
- package/dist/mcp/auth.js +47 -25
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +67 -233
- package/dist/mcp/query.d.ts +2 -2
- package/dist/mcp/registry.d.ts +1 -5
- package/dist/mcp/registry.js +31 -20
- package/dist/mcp/schemaGenerator.d.ts +2 -7
- package/dist/mcp/schemaGenerator.js +41 -116
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +1 -0
- package/dist/mcp/serviceTokens.d.ts +16 -0
- package/dist/mcp/serviceTokens.js +345 -0
- package/dist/mcp/types.d.ts +2 -2
- package/dist/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/openApiBuilder.d.ts +5 -4
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.js +0 -2
- package/dist/plugins.d.ts +14 -1
- package/dist/plugins.js +17 -6
- package/dist/populate.d.ts +2 -2
- package/dist/populate.js +47 -42
- package/dist/rateLimit/applyTrustProxy.d.ts +3 -0
- package/dist/rateLimit/applyTrustProxy.js +17 -0
- package/dist/rateLimit/createStore.d.ts +2 -0
- package/dist/rateLimit/createStore.js +28 -0
- package/dist/rateLimit/memoryStore.d.ts +2 -0
- package/dist/rateLimit/memoryStore.js +108 -0
- package/dist/rateLimit/middleware.d.ts +11 -0
- package/dist/rateLimit/middleware.js +110 -0
- package/dist/rateLimit/mongoStore.d.ts +3 -0
- package/dist/rateLimit/mongoStore.js +122 -0
- package/dist/rateLimit/policies.d.ts +14 -0
- package/dist/rateLimit/policies.js +151 -0
- package/dist/rateLimit/redisStore.d.ts +3 -0
- package/dist/rateLimit/redisStore.js +155 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +5 -1
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/modelRouterAccess.d.ts +1 -0
- package/dist/rbac/modelRouterAccess.js +8 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +5 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/rbac/statements.d.ts +10 -0
- package/dist/rbac/statements.js +13 -2
- package/dist/realtime/deprecation.d.ts +12 -0
- package/dist/realtime/deprecation.js +32 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +10 -11
- package/dist/realtime/registry.d.ts +0 -31
- package/dist/realtime/registry.js +44 -31
- package/dist/realtime/socketAuth.d.ts +5 -5
- package/dist/realtime/socketAuth.js +11 -1
- package/dist/realtime/socketUser.d.ts +5 -1
- package/dist/realtime/types.d.ts +14 -4
- package/dist/schemaMetadata.d.ts +56 -0
- package/dist/schemaMetadata.js +513 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/executors.d.ts +12 -2
- package/dist/sync/executors.js +8 -10
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +9 -0
- package/dist/sync/mutationHandler.js +11 -6
- package/dist/sync/registrationSideEffects.d.ts +35 -0
- package/dist/sync/registrationSideEffects.js +151 -0
- package/dist/sync/registry.d.ts +2 -52
- package/dist/sync/registry.js +38 -187
- package/dist/sync/routes.js +3 -2
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/syncApp.d.ts +3 -3
- package/dist/sync/syncApp.js +4 -4
- package/dist/sync/syncBatch.js +3 -2
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/terrenoApp.d.ts +19 -5
- package/dist/terrenoApp.js +66 -18
- package/dist/tests/models.d.ts +2 -0
- package/dist/tests/models.js +6 -0
- package/dist/types/authToken.d.ts +33 -0
- package/dist/types/authToken.js +2 -0
- package/dist/types/mcpServiceToken.d.ts +41 -0
- package/dist/types/mcpServiceToken.js +2 -0
- package/dist/webhooks/headerValue.d.ts +2 -0
- package/dist/webhooks/headerValue.js +14 -0
- package/dist/webhooks/idempotency/memoryStore.d.ts +10 -0
- package/dist/webhooks/idempotency/memoryStore.js +65 -0
- package/dist/webhooks/idempotency/mongoStore.d.ts +4 -0
- package/dist/webhooks/idempotency/mongoStore.js +150 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +62 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +14 -0
- package/dist/webhooks/rawBody.js +22 -0
- package/dist/webhooks/timingSafeEqual.d.ts +4 -0
- package/dist/webhooks/timingSafeEqual.js +17 -0
- package/dist/webhooks/verifiers/hmac.d.ts +15 -0
- package/dist/webhooks/verifiers/hmac.js +49 -0
- package/dist/webhooks/verifiers/sendgrid.d.ts +10 -0
- package/dist/webhooks/verifiers/sendgrid.js +56 -0
- package/dist/webhooks/verifiers/stripe.d.ts +9 -0
- package/dist/webhooks/verifiers/stripe.js +99 -0
- package/dist/webhooks/verifiers/twilio.d.ts +9 -0
- package/dist/webhooks/verifiers/twilio.js +112 -0
- package/dist/webhooks/webhooksApp.d.ts +33 -0
- package/dist/webhooks/webhooksApp.js +195 -0
- package/package.json +5 -6
- package/src/__snapshots__/openApi.test.ts.snap +270 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +30 -12
- package/src/__snapshots__/schemaMetadata.test.ts.snap +197 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/adminTypes.ts +23 -0
- package/src/api.arrayOperations.test.ts +43 -31
- package/src/api.hooks.test.ts +38 -29
- package/src/api.query.test.ts +31 -31
- package/src/api.test.ts +95 -96
- package/src/api.ts +16 -27
- package/src/auth.test.ts +107 -51
- package/src/auth.ts +98 -29
- package/src/authRecovery.test.ts +281 -0
- package/src/authRecovery.ts +279 -0
- package/src/authTokens.test.ts +94 -0
- package/src/authTokens.ts +118 -0
- package/src/authVerification.test.ts +293 -0
- package/src/betterAuth.ts +24 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +568 -38
- package/src/betterAuthSetup.ts +260 -5
- package/src/collectionRegistry.test.ts +165 -0
- package/src/collectionRegistry.ts +115 -0
- package/src/configurationApp.ts +13 -7
- package/src/docLoader.test.ts +45 -1
- package/src/docLoader.ts +37 -6
- package/src/express.d.ts +1 -0
- package/src/expressServer.test.ts +130 -66
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +58 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +2 -4
- package/src/mcp/registry.ts +29 -20
- package/src/mcp/schemaGenerator.test.ts +8 -0
- package/src/mcp/schemaGenerator.ts +49 -131
- package/src/mcp/server.ts +2 -0
- package/src/mcp/serviceTokens.test.ts +330 -0
- package/src/mcp/serviceTokens.ts +307 -0
- package/src/mcp/toolGenerator.test.ts +1 -1
- package/src/mcp/types.ts +2 -6
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/openApi.test.ts +80 -64
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +46 -9
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +49 -54
- package/src/openApiValidator.ts +1 -3
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +34 -9
- package/src/populate.test.ts +34 -0
- package/src/populate.ts +40 -29
- package/src/rateLimit/applyTrustProxy.ts +17 -0
- package/src/rateLimit/createStore.ts +25 -0
- package/src/rateLimit/memoryStore.ts +40 -0
- package/src/rateLimit/middleware.ts +79 -0
- package/src/rateLimit/mongoStore.test.ts +80 -0
- package/src/rateLimit/mongoStore.ts +76 -0
- package/src/rateLimit/policies.ts +130 -0
- package/src/rateLimit/rateLimit.test.ts +328 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +29 -0
- package/src/rateLimit/redisStore.test.ts +114 -0
- package/src/rateLimit/redisStore.ts +85 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +5 -1
- package/src/rbac/assertAllowed.test.ts +325 -0
- package/src/rbac/assertAllowed.ts +157 -0
- package/src/rbac/backfillAdmins.test.ts +124 -0
- package/src/rbac/fieldViews.test.ts +89 -0
- package/src/rbac/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +5 -2
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.ts +5 -4
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/rbac/statements.test.ts +2 -0
- package/src/rbac/statements.ts +12 -1
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +32 -0
- package/src/realtime/realtime.test.ts +8 -4
- package/src/realtime/realtimeApp.ts +10 -11
- package/src/realtime/realtimeAppSetup.test.ts +32 -5
- package/src/realtime/registry.ts +48 -42
- package/src/realtime/sessionRevalidation.test.ts +57 -44
- package/src/realtime/socketAuth.test.ts +75 -23
- package/src/realtime/socketAuth.ts +17 -6
- package/src/realtime/socketUser.ts +5 -3
- package/src/realtime/types.ts +14 -4
- package/src/schemaMetadata.test.ts +405 -0
- package/src/schemaMetadata.ts +593 -0
- package/src/scrubAdminFields.test.ts +105 -0
- package/src/seedRunner.test.ts +591 -0
- package/src/seedRunner.ts +464 -0
- package/src/sync/docMatchesMutationData.test.ts +16 -0
- package/src/sync/ensureSyncIndexes.test.ts +54 -15
- package/src/sync/executors.test.ts +40 -0
- package/src/sync/executors.ts +24 -12
- package/src/sync/integration.test.ts +15 -7
- package/src/sync/loadHarness.ts +28 -19
- package/src/sync/models.ts +32 -18
- package/src/sync/mutationHandler.test.ts +16 -16
- package/src/sync/mutationHandler.ts +9 -7
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +45 -171
- package/src/sync/routes.ts +3 -2
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/sync.test.ts +25 -23
- package/src/sync/syncApp.ts +4 -4
- package/src/sync/syncBatch.ts +3 -2
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +51 -36
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +112 -81
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.ts +87 -15
- package/src/tests/models.ts +14 -1
- package/src/types/authToken.ts +43 -0
- package/src/types/mcpServiceToken.ts +54 -0
- package/src/webhooks/headerValue.test.ts +22 -0
- package/src/webhooks/headerValue.ts +12 -0
- package/src/webhooks/idempotency/memoryStore.ts +34 -0
- package/src/webhooks/idempotency/mongoStore.test.ts +274 -0
- package/src/webhooks/idempotency/mongoStore.ts +83 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +70 -0
- package/src/webhooks/rawBody.test.ts +74 -0
- package/src/webhooks/rawBody.ts +23 -0
- package/src/webhooks/timingSafeEqual.ts +16 -0
- package/src/webhooks/verifiers/hmac.test.ts +110 -0
- package/src/webhooks/verifiers/hmac.ts +54 -0
- package/src/webhooks/verifiers/providerVerifiers.test.ts +388 -0
- package/src/webhooks/verifiers/sendgrid.ts +59 -0
- package/src/webhooks/verifiers/stripe.ts +67 -0
- package/src/webhooks/verifiers/twilio.ts +69 -0
- package/src/webhooks/webhooksApp.test.ts +221 -0
- package/src/webhooks/webhooksApp.ts +144 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {describe, it} from "bun:test";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import type {Application, Request} from "express";
|
|
5
|
+
import {DateTime} from "luxon";
|
|
6
|
+
import supertest from "supertest";
|
|
7
|
+
|
|
8
|
+
import type {UserModel as AuthUserModel} from "../../auth";
|
|
9
|
+
import {TerrenoApp} from "../../terrenoApp";
|
|
10
|
+
import {UserModel} from "../../tests";
|
|
11
|
+
import {WebhooksApp} from "../webhooksApp";
|
|
12
|
+
import {sendgridEventSignature} from "./sendgrid";
|
|
13
|
+
import {stripeSignature} from "./stripe";
|
|
14
|
+
import {twilioSignature} from "./twilio";
|
|
15
|
+
|
|
16
|
+
const STRIPE_SECRET = "whsec_stripe_test";
|
|
17
|
+
const STRIPE_BODY = `{"id":"evt_stripe_1"}`;
|
|
18
|
+
const TWILIO_TOKEN = "twilio_auth_token";
|
|
19
|
+
const TWILIO_URL = "https://api.example.com/comms/webhooks/twilio/status";
|
|
20
|
+
const TWILIO_BODY = "MessageSid=SM123&MessageStatus=delivered";
|
|
21
|
+
|
|
22
|
+
const buildApp = ({
|
|
23
|
+
path,
|
|
24
|
+
source,
|
|
25
|
+
verify,
|
|
26
|
+
}: {
|
|
27
|
+
path: string;
|
|
28
|
+
source: string;
|
|
29
|
+
verify: (req: Request) => boolean;
|
|
30
|
+
}): Application => {
|
|
31
|
+
const webhooks = new WebhooksApp({idempotency: {store: "memory"}});
|
|
32
|
+
webhooks.route({
|
|
33
|
+
eventId: () => "evt",
|
|
34
|
+
handler: () => undefined,
|
|
35
|
+
path,
|
|
36
|
+
source,
|
|
37
|
+
verify,
|
|
38
|
+
});
|
|
39
|
+
return new TerrenoApp({
|
|
40
|
+
logRequests: false,
|
|
41
|
+
skipListen: true,
|
|
42
|
+
userModel: UserModel as unknown as AuthUserModel,
|
|
43
|
+
})
|
|
44
|
+
.register(webhooks)
|
|
45
|
+
.build();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const stripeHeader = ({payload, timestamp}: {payload: string; timestamp: number}): string => {
|
|
49
|
+
const v1 = crypto
|
|
50
|
+
.createHmac("sha256", STRIPE_SECRET)
|
|
51
|
+
.update(`${timestamp}.${payload}`)
|
|
52
|
+
.digest("hex");
|
|
53
|
+
return `t=${timestamp},v1=${v1}`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const twilioHeader = ({body, url}: {body: string; url: string}): string => {
|
|
57
|
+
const params = Object.fromEntries(new URLSearchParams(body));
|
|
58
|
+
const keys = Object.keys(params).sort();
|
|
59
|
+
let data = url;
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
data += key + params[key];
|
|
62
|
+
}
|
|
63
|
+
return crypto.createHmac("sha1", TWILIO_TOKEN).update(data, "utf8").digest("base64");
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe("stripeSignature", () => {
|
|
67
|
+
it("accepts a fixture inside the timestamp window", async () => {
|
|
68
|
+
const app = buildApp({
|
|
69
|
+
path: "/billing/webhooks/stripe",
|
|
70
|
+
source: "stripe",
|
|
71
|
+
verify: stripeSignature({secret: STRIPE_SECRET}),
|
|
72
|
+
});
|
|
73
|
+
const timestamp = DateTime.utc().toUnixInteger();
|
|
74
|
+
const res = await supertest(app)
|
|
75
|
+
.post("/billing/webhooks/stripe")
|
|
76
|
+
.set("Content-Type", "application/json")
|
|
77
|
+
.set("Stripe-Signature", stripeHeader({payload: STRIPE_BODY, timestamp}))
|
|
78
|
+
.send(STRIPE_BODY);
|
|
79
|
+
|
|
80
|
+
assert.equal(res.status, 200);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("rejects a timestamp outside the tolerance window", async () => {
|
|
84
|
+
const app = buildApp({
|
|
85
|
+
path: "/billing/webhooks/stripe",
|
|
86
|
+
source: "stripe",
|
|
87
|
+
verify: stripeSignature({secret: STRIPE_SECRET, toleranceSec: 300}),
|
|
88
|
+
});
|
|
89
|
+
const timestamp = DateTime.utc().toUnixInteger() - 301;
|
|
90
|
+
const res = await supertest(app)
|
|
91
|
+
.post("/billing/webhooks/stripe")
|
|
92
|
+
.set("Content-Type", "application/json")
|
|
93
|
+
.set("Stripe-Signature", stripeHeader({payload: STRIPE_BODY, timestamp}))
|
|
94
|
+
.send(STRIPE_BODY);
|
|
95
|
+
|
|
96
|
+
assert.equal(res.status, 401);
|
|
97
|
+
assert.equal(res.body.code, "webhook-signature-invalid");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("rejects a mutated payload", async () => {
|
|
101
|
+
const app = buildApp({
|
|
102
|
+
path: "/billing/webhooks/stripe",
|
|
103
|
+
source: "stripe",
|
|
104
|
+
verify: stripeSignature({secret: STRIPE_SECRET}),
|
|
105
|
+
});
|
|
106
|
+
const timestamp = DateTime.utc().toUnixInteger();
|
|
107
|
+
const res = await supertest(app)
|
|
108
|
+
.post("/billing/webhooks/stripe")
|
|
109
|
+
.set("Content-Type", "application/json")
|
|
110
|
+
.set("Stripe-Signature", stripeHeader({payload: STRIPE_BODY, timestamp}))
|
|
111
|
+
.send(`{"id":"evt_mutated"}`);
|
|
112
|
+
|
|
113
|
+
assert.equal(res.status, 401);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("twilioSignature", () => {
|
|
118
|
+
it("accepts a form-urlencoded fixture", async () => {
|
|
119
|
+
const app = buildApp({
|
|
120
|
+
path: "/comms/webhooks/twilio/status",
|
|
121
|
+
source: "twilio",
|
|
122
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: TWILIO_URL}),
|
|
123
|
+
});
|
|
124
|
+
const res = await supertest(app)
|
|
125
|
+
.post("/comms/webhooks/twilio/status")
|
|
126
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
127
|
+
.set("X-Twilio-Signature", twilioHeader({body: TWILIO_BODY, url: TWILIO_URL}))
|
|
128
|
+
.send(TWILIO_BODY);
|
|
129
|
+
|
|
130
|
+
assert.equal(res.status, 200);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("rejects JSON on the Twilio route", async () => {
|
|
134
|
+
const app = buildApp({
|
|
135
|
+
path: "/comms/webhooks/twilio/status",
|
|
136
|
+
source: "twilio",
|
|
137
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: TWILIO_URL}),
|
|
138
|
+
});
|
|
139
|
+
const jsonBody = `{"MessageSid":"SM123","MessageStatus":"delivered"}`;
|
|
140
|
+
const res = await supertest(app)
|
|
141
|
+
.post("/comms/webhooks/twilio/status")
|
|
142
|
+
.set("Content-Type", "application/json")
|
|
143
|
+
.set("X-Twilio-Signature", twilioHeader({body: TWILIO_BODY, url: TWILIO_URL}))
|
|
144
|
+
.send(jsonBody);
|
|
145
|
+
|
|
146
|
+
assert.equal(res.status, 401);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("rejects a mutated form body", async () => {
|
|
150
|
+
const app = buildApp({
|
|
151
|
+
path: "/comms/webhooks/twilio/status",
|
|
152
|
+
source: "twilio",
|
|
153
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: TWILIO_URL}),
|
|
154
|
+
});
|
|
155
|
+
const res = await supertest(app)
|
|
156
|
+
.post("/comms/webhooks/twilio/status")
|
|
157
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
158
|
+
.set("X-Twilio-Signature", twilioHeader({body: TWILIO_BODY, url: TWILIO_URL}))
|
|
159
|
+
.send("MessageSid=SM123&MessageStatus=failed");
|
|
160
|
+
|
|
161
|
+
assert.equal(res.status, 401);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("resolves the callback url from a function", async () => {
|
|
165
|
+
const app = buildApp({
|
|
166
|
+
path: "/comms/webhooks/twilio/status",
|
|
167
|
+
source: "twilio",
|
|
168
|
+
verify: twilioSignature({
|
|
169
|
+
authToken: TWILIO_TOKEN,
|
|
170
|
+
url: (req) => `https://api.example.com${req.originalUrl}`,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
const res = await supertest(app)
|
|
174
|
+
.post("/comms/webhooks/twilio/status")
|
|
175
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
176
|
+
.set(
|
|
177
|
+
"X-Twilio-Signature",
|
|
178
|
+
twilioHeader({
|
|
179
|
+
body: TWILIO_BODY,
|
|
180
|
+
url: "https://api.example.com/comms/webhooks/twilio/status",
|
|
181
|
+
})
|
|
182
|
+
)
|
|
183
|
+
.send(TWILIO_BODY);
|
|
184
|
+
|
|
185
|
+
assert.equal(res.status, 200);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("rejects when no callback url is configured", async () => {
|
|
189
|
+
const app = buildApp({
|
|
190
|
+
path: "/comms/webhooks/twilio/status",
|
|
191
|
+
source: "twilio",
|
|
192
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN}),
|
|
193
|
+
});
|
|
194
|
+
const res = await supertest(app)
|
|
195
|
+
.post("/comms/webhooks/twilio/status")
|
|
196
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
197
|
+
.set("X-Twilio-Signature", twilioHeader({body: TWILIO_BODY, url: TWILIO_URL}))
|
|
198
|
+
.send(TWILIO_BODY);
|
|
199
|
+
|
|
200
|
+
assert.equal(res.status, 401);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("rejects when an empty url is configured", async () => {
|
|
204
|
+
const app = buildApp({
|
|
205
|
+
path: "/comms/webhooks/twilio/status",
|
|
206
|
+
source: "twilio",
|
|
207
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: ""}),
|
|
208
|
+
});
|
|
209
|
+
const res = await supertest(app)
|
|
210
|
+
.post("/comms/webhooks/twilio/status")
|
|
211
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
212
|
+
.set("X-Twilio-Signature", twilioHeader({body: TWILIO_BODY, url: TWILIO_URL}))
|
|
213
|
+
.send(TWILIO_BODY);
|
|
214
|
+
|
|
215
|
+
assert.equal(res.status, 401);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("rejects a missing signature header", async () => {
|
|
219
|
+
const app = buildApp({
|
|
220
|
+
path: "/comms/webhooks/twilio/status",
|
|
221
|
+
source: "twilio",
|
|
222
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: TWILIO_URL}),
|
|
223
|
+
});
|
|
224
|
+
const res = await supertest(app)
|
|
225
|
+
.post("/comms/webhooks/twilio/status")
|
|
226
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
227
|
+
.send(TWILIO_BODY);
|
|
228
|
+
|
|
229
|
+
assert.equal(res.status, 401);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("rejects repeated form fields that do not decode to strings", async () => {
|
|
233
|
+
const app = buildApp({
|
|
234
|
+
path: "/comms/webhooks/twilio/status",
|
|
235
|
+
source: "twilio",
|
|
236
|
+
verify: twilioSignature({authToken: TWILIO_TOKEN, url: TWILIO_URL}),
|
|
237
|
+
});
|
|
238
|
+
const body = "MessageSid=SM123&MessageSid=SM456";
|
|
239
|
+
const res = await supertest(app)
|
|
240
|
+
.post("/comms/webhooks/twilio/status")
|
|
241
|
+
.set("Content-Type", "application/x-www-form-urlencoded")
|
|
242
|
+
.set("X-Twilio-Signature", twilioHeader({body, url: TWILIO_URL}))
|
|
243
|
+
.send(body);
|
|
244
|
+
|
|
245
|
+
assert.equal(res.status, 401);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("sendgridEventSignature", () => {
|
|
250
|
+
it("accepts an ECDSA fixture and rejects a mutated payload", async () => {
|
|
251
|
+
const {publicKey, privateKey} = crypto.generateKeyPairSync("ec", {
|
|
252
|
+
namedCurve: "prime256v1",
|
|
253
|
+
});
|
|
254
|
+
const pem = publicKey.export({format: "pem", type: "spki"}).toString();
|
|
255
|
+
const app = buildApp({
|
|
256
|
+
path: "/comms/webhooks/sendgrid",
|
|
257
|
+
source: "sendgrid",
|
|
258
|
+
verify: sendgridEventSignature({publicKey: pem}),
|
|
259
|
+
});
|
|
260
|
+
const payload = `[{"sg_event_id":"sg_1","event":"delivered"}]`;
|
|
261
|
+
const timestamp = String(DateTime.utc().toUnixInteger());
|
|
262
|
+
const signer = crypto.createSign("SHA256");
|
|
263
|
+
signer.update(timestamp);
|
|
264
|
+
signer.update(payload);
|
|
265
|
+
signer.end();
|
|
266
|
+
const signature = signer.sign(privateKey, "base64");
|
|
267
|
+
|
|
268
|
+
const accepted = await supertest(app)
|
|
269
|
+
.post("/comms/webhooks/sendgrid")
|
|
270
|
+
.set("Content-Type", "application/json")
|
|
271
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", timestamp)
|
|
272
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", signature)
|
|
273
|
+
.send(payload);
|
|
274
|
+
assert.equal(accepted.status, 200);
|
|
275
|
+
|
|
276
|
+
const rejected = await supertest(app)
|
|
277
|
+
.post("/comms/webhooks/sendgrid")
|
|
278
|
+
.set("Content-Type", "application/json")
|
|
279
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", timestamp)
|
|
280
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", signature)
|
|
281
|
+
.send(`[{"sg_event_id":"sg_1","event":"bounce"}]`);
|
|
282
|
+
assert.equal(rejected.status, 401);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("accepts a raw public key without PEM headers", async () => {
|
|
286
|
+
const {publicKey, privateKey} = crypto.generateKeyPairSync("ec", {
|
|
287
|
+
namedCurve: "prime256v1",
|
|
288
|
+
});
|
|
289
|
+
const raw = publicKey
|
|
290
|
+
.export({format: "pem", type: "spki"})
|
|
291
|
+
.toString()
|
|
292
|
+
.replace("-----BEGIN PUBLIC KEY-----", "")
|
|
293
|
+
.replace("-----END PUBLIC KEY-----", "")
|
|
294
|
+
.replace(/\s+/g, "");
|
|
295
|
+
const app = buildApp({
|
|
296
|
+
path: "/comms/webhooks/sendgrid",
|
|
297
|
+
source: "sendgrid",
|
|
298
|
+
verify: sendgridEventSignature({publicKey: raw}),
|
|
299
|
+
});
|
|
300
|
+
const payload = `[{"sg_event_id":"sg_raw","event":"delivered"}]`;
|
|
301
|
+
const timestamp = String(DateTime.utc().toUnixInteger());
|
|
302
|
+
const signer = crypto.createSign("SHA256");
|
|
303
|
+
signer.update(timestamp);
|
|
304
|
+
signer.update(payload);
|
|
305
|
+
signer.end();
|
|
306
|
+
const signature = signer.sign(privateKey, "base64");
|
|
307
|
+
const res = await supertest(app)
|
|
308
|
+
.post("/comms/webhooks/sendgrid")
|
|
309
|
+
.set("Content-Type", "application/json")
|
|
310
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", timestamp)
|
|
311
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", signature)
|
|
312
|
+
.send(payload);
|
|
313
|
+
assert.equal(res.status, 200);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("rejects a missing timestamp header", async () => {
|
|
317
|
+
const {publicKey} = crypto.generateKeyPairSync("ec", {namedCurve: "prime256v1"});
|
|
318
|
+
const pem = publicKey.export({format: "pem", type: "spki"}).toString();
|
|
319
|
+
const app = buildApp({
|
|
320
|
+
path: "/comms/webhooks/sendgrid",
|
|
321
|
+
source: "sendgrid",
|
|
322
|
+
verify: sendgridEventSignature({publicKey: pem}),
|
|
323
|
+
});
|
|
324
|
+
const res = await supertest(app)
|
|
325
|
+
.post("/comms/webhooks/sendgrid")
|
|
326
|
+
.set("Content-Type", "application/json")
|
|
327
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", "sig")
|
|
328
|
+
.send(`[{"sg_event_id":"sg_1","event":"delivered"}]`);
|
|
329
|
+
assert.equal(res.status, 401);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("rejects a missing signature header", async () => {
|
|
333
|
+
const {publicKey} = crypto.generateKeyPairSync("ec", {namedCurve: "prime256v1"});
|
|
334
|
+
const pem = publicKey.export({format: "pem", type: "spki"}).toString();
|
|
335
|
+
const app = buildApp({
|
|
336
|
+
path: "/comms/webhooks/sendgrid",
|
|
337
|
+
source: "sendgrid",
|
|
338
|
+
verify: sendgridEventSignature({publicKey: pem}),
|
|
339
|
+
});
|
|
340
|
+
const res = await supertest(app)
|
|
341
|
+
.post("/comms/webhooks/sendgrid")
|
|
342
|
+
.set("Content-Type", "application/json")
|
|
343
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", String(DateTime.utc().toUnixInteger()))
|
|
344
|
+
.send(`[{"sg_event_id":"sg_1","event":"delivered"}]`);
|
|
345
|
+
assert.equal(res.status, 401);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("rejects a timestamp outside the tolerance window", async () => {
|
|
349
|
+
const {publicKey, privateKey} = crypto.generateKeyPairSync("ec", {
|
|
350
|
+
namedCurve: "prime256v1",
|
|
351
|
+
});
|
|
352
|
+
const pem = publicKey.export({format: "pem", type: "spki"}).toString();
|
|
353
|
+
const app = buildApp({
|
|
354
|
+
path: "/comms/webhooks/sendgrid",
|
|
355
|
+
source: "sendgrid",
|
|
356
|
+
verify: sendgridEventSignature({publicKey: pem, toleranceSec: 300}),
|
|
357
|
+
});
|
|
358
|
+
const payload = `[{"sg_event_id":"sg_stale","event":"delivered"}]`;
|
|
359
|
+
const timestamp = String(DateTime.utc().toUnixInteger() - 301);
|
|
360
|
+
const signer = crypto.createSign("SHA256");
|
|
361
|
+
signer.update(timestamp);
|
|
362
|
+
signer.update(payload);
|
|
363
|
+
signer.end();
|
|
364
|
+
const signature = signer.sign(privateKey, "base64");
|
|
365
|
+
const res = await supertest(app)
|
|
366
|
+
.post("/comms/webhooks/sendgrid")
|
|
367
|
+
.set("Content-Type", "application/json")
|
|
368
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", timestamp)
|
|
369
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", signature)
|
|
370
|
+
.send(payload);
|
|
371
|
+
assert.equal(res.status, 401);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("rejects an invalid public key", async () => {
|
|
375
|
+
const app = buildApp({
|
|
376
|
+
path: "/comms/webhooks/sendgrid",
|
|
377
|
+
source: "sendgrid",
|
|
378
|
+
verify: sendgridEventSignature({publicKey: "not-a-key"}),
|
|
379
|
+
});
|
|
380
|
+
const res = await supertest(app)
|
|
381
|
+
.post("/comms/webhooks/sendgrid")
|
|
382
|
+
.set("Content-Type", "application/json")
|
|
383
|
+
.set("X-Twilio-Email-Event-Webhook-Timestamp", String(DateTime.utc().toUnixInteger()))
|
|
384
|
+
.set("X-Twilio-Email-Event-Webhook-Signature", "AAAA")
|
|
385
|
+
.send(`[{"sg_event_id":"sg_1","event":"delivered"}]`);
|
|
386
|
+
assert.equal(res.status, 401);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import type {Request} from "express";
|
|
3
|
+
import {DateTime} from "luxon";
|
|
4
|
+
|
|
5
|
+
import {headerValue} from "../headerValue";
|
|
6
|
+
|
|
7
|
+
export interface SendgridEventSignatureOptions {
|
|
8
|
+
publicKey: string;
|
|
9
|
+
toleranceSec?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const PEM_HEADER = "-----BEGIN PUBLIC KEY-----";
|
|
13
|
+
const PEM_FOOTER = "-----END PUBLIC KEY-----";
|
|
14
|
+
|
|
15
|
+
const toPem = (publicKey: string): string => {
|
|
16
|
+
const trimmed = publicKey.trim();
|
|
17
|
+
if (trimmed.includes(PEM_HEADER)) {
|
|
18
|
+
return trimmed;
|
|
19
|
+
}
|
|
20
|
+
const body = trimmed.replace(/\s+/g, "");
|
|
21
|
+
const wrapped = body.match(/.{1,64}/g)?.join("\n") ?? body;
|
|
22
|
+
return `${PEM_HEADER}\n${wrapped}\n${PEM_FOOTER}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Verifies SendGrid Event Webhook ECDSA P-256 over `${timestamp}${rawBody}`.
|
|
27
|
+
* Timestamps outside `toleranceSec` (default 300) are rejected.
|
|
28
|
+
*/
|
|
29
|
+
export const sendgridEventSignature = (
|
|
30
|
+
options: SendgridEventSignatureOptions
|
|
31
|
+
): ((req: Request) => boolean) => {
|
|
32
|
+
const pem = toPem(options.publicKey);
|
|
33
|
+
const toleranceSec = options.toleranceSec ?? 300;
|
|
34
|
+
|
|
35
|
+
return (req: Request): boolean => {
|
|
36
|
+
const signature = headerValue(req, "X-Twilio-Email-Event-Webhook-Signature");
|
|
37
|
+
const timestampRaw = headerValue(req, "X-Twilio-Email-Event-Webhook-Timestamp");
|
|
38
|
+
if (!signature || !timestampRaw || !req.rawBody) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const timestamp = Number(timestampRaw);
|
|
42
|
+
if (!Number.isFinite(timestamp)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const nowSec = DateTime.utc().toUnixInteger();
|
|
46
|
+
if (Math.abs(nowSec - timestamp) > toleranceSec) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const verifier = crypto.createVerify("SHA256");
|
|
51
|
+
verifier.update(timestampRaw);
|
|
52
|
+
verifier.update(req.rawBody);
|
|
53
|
+
verifier.end();
|
|
54
|
+
return verifier.verify(pem, signature, "base64");
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import type {Request} from "express";
|
|
3
|
+
import {DateTime} from "luxon";
|
|
4
|
+
|
|
5
|
+
import {headerValue} from "../headerValue";
|
|
6
|
+
import {timingSafeEqualUtf8} from "../timingSafeEqual";
|
|
7
|
+
|
|
8
|
+
export interface StripeSignatureOptions {
|
|
9
|
+
secret: string;
|
|
10
|
+
toleranceSec?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const parseStripeSignature = (header: string): {timestamp: string | undefined; v1: string[]} => {
|
|
14
|
+
let timestamp: string | undefined;
|
|
15
|
+
const v1: string[] = [];
|
|
16
|
+
for (const part of header.split(",")) {
|
|
17
|
+
const separator = part.indexOf("=");
|
|
18
|
+
if (separator <= 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const key = part.slice(0, separator).trim();
|
|
22
|
+
const value = part.slice(separator + 1).trim();
|
|
23
|
+
if (key === "t") {
|
|
24
|
+
timestamp = value;
|
|
25
|
+
} else if (key === "v1") {
|
|
26
|
+
v1.push(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {timestamp, v1};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Verifies Stripe `Stripe-Signature` (`t=` / `v1=`) against HMAC-SHA256 of `${t}.${rawBody}`.
|
|
34
|
+
*/
|
|
35
|
+
export const stripeSignature = (options: StripeSignatureOptions): ((req: Request) => boolean) => {
|
|
36
|
+
const toleranceSec = options.toleranceSec ?? 300;
|
|
37
|
+
|
|
38
|
+
return (req: Request): boolean => {
|
|
39
|
+
const header = headerValue(req, "Stripe-Signature");
|
|
40
|
+
if (!header || !req.rawBody) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const parsed = parseStripeSignature(header);
|
|
44
|
+
if (!parsed.timestamp || parsed.v1.length === 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const timestamp = Number(parsed.timestamp);
|
|
48
|
+
if (!Number.isFinite(timestamp)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const nowSec = DateTime.utc().toUnixInteger();
|
|
52
|
+
if (Math.abs(nowSec - timestamp) > toleranceSec) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const expected = crypto
|
|
56
|
+
.createHmac("sha256", options.secret)
|
|
57
|
+
.update(`${parsed.timestamp}.`)
|
|
58
|
+
.update(req.rawBody)
|
|
59
|
+
.digest("hex");
|
|
60
|
+
for (const provided of parsed.v1) {
|
|
61
|
+
if (timingSafeEqualUtf8({expected, provided})) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import type {Request} from "express";
|
|
3
|
+
|
|
4
|
+
import {headerValue} from "../headerValue";
|
|
5
|
+
import {timingSafeEqualUtf8} from "../timingSafeEqual";
|
|
6
|
+
|
|
7
|
+
export interface TwilioSignatureOptions {
|
|
8
|
+
authToken: string;
|
|
9
|
+
url?: string | ((req: Request) => string);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const isUrlencoded = (req: Request): boolean => {
|
|
13
|
+
const contentType = headerValue(req, "content-type") ?? "";
|
|
14
|
+
return contentType.toLowerCase().includes("application/x-www-form-urlencoded");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const resolveUrl = (
|
|
18
|
+
req: Request,
|
|
19
|
+
url?: string | ((req: Request) => string)
|
|
20
|
+
): string | undefined => {
|
|
21
|
+
if (typeof url === "function") {
|
|
22
|
+
return url(req);
|
|
23
|
+
}
|
|
24
|
+
if (typeof url === "string" && url.length > 0) {
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const formParams = (body: unknown): Record<string, string> | undefined => {
|
|
31
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const params: Record<string, string> = {};
|
|
35
|
+
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
|
|
36
|
+
if (typeof value !== "string") {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
params[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return params;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Verifies Twilio `X-Twilio-Signature` (HMAC-SHA1 of callback URL + sorted POST fields).
|
|
46
|
+
*/
|
|
47
|
+
export const twilioSignature = (options: TwilioSignatureOptions): ((req: Request) => boolean) => {
|
|
48
|
+
return (req: Request): boolean => {
|
|
49
|
+
if (!isUrlencoded(req) || !req.rawBody) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const provided = headerValue(req, "X-Twilio-Signature");
|
|
53
|
+
const callbackUrl = resolveUrl(req, options.url);
|
|
54
|
+
const params = formParams(req.body);
|
|
55
|
+
if (!provided || !callbackUrl || !params) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const keys = Object.keys(params).sort();
|
|
59
|
+
let data = callbackUrl;
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
data += key + params[key];
|
|
62
|
+
}
|
|
63
|
+
const expected = crypto
|
|
64
|
+
.createHmac("sha1", options.authToken)
|
|
65
|
+
.update(data, "utf8")
|
|
66
|
+
.digest("base64");
|
|
67
|
+
return timingSafeEqualUtf8({expected, provided});
|
|
68
|
+
};
|
|
69
|
+
};
|