From 0b47f663550a3dd8609128a49d55bccd31a7ecc5 Mon Sep 17 00:00:00 2001 From: RafidMuhymin Date: Tue, 16 Jan 2024 22:04:18 +0600 Subject: [PATCH] refactored cf-secure-worker-token logic --- src/workers/dilmahtea-me-email/src/index.ts | 5 ++++- src/workers/dilmahtea-me-email/src/types/env.ts | 2 +- src/workers/dilmahtea-me-email/wrangler.toml | 2 +- src/workers/dilmahtea-me-exact-account/src/index.ts | 5 ++++- src/workers/dilmahtea-me-exact-account/src/types/env.ts | 2 +- src/workers/dilmahtea-me-exact-account/wrangler.toml | 2 +- src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts | 2 +- .../src/utils/createExactOrder.ts | 2 +- src/workers/dilmahtea-me-stripe-webhook/wrangler.toml | 2 +- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/workers/dilmahtea-me-email/src/index.ts b/src/workers/dilmahtea-me-email/src/index.ts index 454e9dd7..d0953c54 100644 --- a/src/workers/dilmahtea-me-email/src/index.ts +++ b/src/workers/dilmahtea-me-email/src/index.ts @@ -9,7 +9,10 @@ declare interface Body { } async function handlePOST(request: Request, env: ENV) { - if (request.headers.get("x-secret") !== env.EMAIL_WORKER_SECRET) { + if ( + request.headers.get("x-cf-secure-worker-token") !== + env.CF_SECURE_WORKER_TOKEN + ) { return reply({ success: false, error: "Unauthorized" }, 401); } diff --git a/src/workers/dilmahtea-me-email/src/types/env.ts b/src/workers/dilmahtea-me-email/src/types/env.ts index 4bf08e3b..d8b2f699 100644 --- a/src/workers/dilmahtea-me-email/src/types/env.ts +++ b/src/workers/dilmahtea-me-email/src/types/env.ts @@ -8,5 +8,5 @@ export interface ENV { MAILS: KVNamespace; // SECRETS - EMAIL_WORKER_SECRET: string; + CF_SECURE_WORKER_TOKEN: string; } diff --git a/src/workers/dilmahtea-me-email/wrangler.toml b/src/workers/dilmahtea-me-email/wrangler.toml index 2106f52d..ef84adf9 100644 --- a/src/workers/dilmahtea-me-email/wrangler.toml +++ b/src/workers/dilmahtea-me-email/wrangler.toml @@ -13,4 +13,4 @@ services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers" # secrets # DKIM_PRIVATE_KEY -# EMAIL_WORKER_SECRET \ No newline at end of file +# CF_SECURE_WORKER_TOKEN \ No newline at end of file diff --git a/src/workers/dilmahtea-me-exact-account/src/index.ts b/src/workers/dilmahtea-me-exact-account/src/index.ts index 88266159..cf790942 100644 --- a/src/workers/dilmahtea-me-exact-account/src/index.ts +++ b/src/workers/dilmahtea-me-exact-account/src/index.ts @@ -25,7 +25,10 @@ declare interface Body { } async function handlePOST(request: Request, env: ENV) { - if (request.headers.get("x-secret") !== env.EXACT_ACCOUNT_WORKER_SECRET) { + if ( + request.headers.get("x-cf-secure-worker-token") !== + env.CF_SECURE_WORKER_TOKEN + ) { return reply({ success: false, error: "Unauthorized" }, 401); } diff --git a/src/workers/dilmahtea-me-exact-account/src/types/env.ts b/src/workers/dilmahtea-me-exact-account/src/types/env.ts index 13736c1e..b72c0dd8 100644 --- a/src/workers/dilmahtea-me-exact-account/src/types/env.ts +++ b/src/workers/dilmahtea-me-exact-account/src/types/env.ts @@ -13,5 +13,5 @@ export interface ENV { EXACT_API_ENDPOINT: string; // EXACT ACCOUNT WORKER - EXACT_ACCOUNT_WORKER_SECRET: string; + CF_SECURE_WORKER_TOKEN: string; } diff --git a/src/workers/dilmahtea-me-exact-account/wrangler.toml b/src/workers/dilmahtea-me-exact-account/wrangler.toml index 00d76de4..511ef340 100644 --- a/src/workers/dilmahtea-me-exact-account/wrangler.toml +++ b/src/workers/dilmahtea-me-exact-account/wrangler.toml @@ -34,4 +34,4 @@ services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers" # secrets # DKIM_PRIVATE_KEY # EXACT_API_ENDPOINT -# EXACT_ACCOUNT_WORKER_SECRET \ No newline at end of file +# CF_SECURE_WORKER_TOKEN \ No newline at end of file diff --git a/src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts b/src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts index 7366f38c..95be61d9 100644 --- a/src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts +++ b/src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts @@ -42,5 +42,5 @@ export interface ENV { EXACT_API_ENDPOINT: string; // EXACT ACCOUNT WORKER - EXACT_ACCOUNT_WORKER_SECRET: string; + CF_SECURE_WORKER_TOKEN: string; } diff --git a/src/workers/dilmahtea-me-stripe-webhook/src/utils/createExactOrder.ts b/src/workers/dilmahtea-me-stripe-webhook/src/utils/createExactOrder.ts index 9b5330b8..8962a4df 100644 --- a/src/workers/dilmahtea-me-stripe-webhook/src/utils/createExactOrder.ts +++ b/src/workers/dilmahtea-me-stripe-webhook/src/utils/createExactOrder.ts @@ -53,7 +53,7 @@ export default async function createExactOrder( method: "POST", headers: { "content-type": "application/json", - "x-secret": env.EXACT_ACCOUNT_WORKER_SECRET, + "x-cf-secure-worker-token": env.CF_SECURE_WORKER_TOKEN, }, body: JSON.stringify(CustomerData), }, diff --git a/src/workers/dilmahtea-me-stripe-webhook/wrangler.toml b/src/workers/dilmahtea-me-stripe-webhook/wrangler.toml index 21e95770..ca91fbc4 100644 --- a/src/workers/dilmahtea-me-stripe-webhook/wrangler.toml +++ b/src/workers/dilmahtea-me-stripe-webhook/wrangler.toml @@ -56,4 +56,4 @@ services = [ # STRIPE_SECRET_KEY # STRIPE_SIGNING_SECRET_KEY # EXACT_API_ENDPOINT -# EXACT_ACCOUNT_WORKER_SECRET +# CF_SECURE_WORKER_TOKEN