Skip to content

Commit

Permalink
refactored cf-secure-worker-token logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RafidMuhymin committed Jan 16, 2024
1 parent f135bd1 commit 0b47f66
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/workers/dilmahtea-me-email/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-email/src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface ENV {
MAILS: KVNamespace;

// SECRETS
EMAIL_WORKER_SECRET: string;
CF_SECURE_WORKER_TOKEN: string;
}
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-email/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers"

# secrets
# DKIM_PRIVATE_KEY
# EMAIL_WORKER_SECRET
# CF_SECURE_WORKER_TOKEN
5 changes: 4 additions & 1 deletion src/workers/dilmahtea-me-exact-account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-exact-account/src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export interface ENV {
EXACT_API_ENDPOINT: string;

// EXACT ACCOUNT WORKER
EXACT_ACCOUNT_WORKER_SECRET: string;
CF_SECURE_WORKER_TOKEN: string;
}
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-exact-account/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers"
# secrets
# DKIM_PRIVATE_KEY
# EXACT_API_ENDPOINT
# EXACT_ACCOUNT_WORKER_SECRET
# CF_SECURE_WORKER_TOKEN
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-stripe-webhook/src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export interface ENV {
EXACT_API_ENDPOINT: string;

// EXACT ACCOUNT WORKER
EXACT_ACCOUNT_WORKER_SECRET: string;
CF_SECURE_WORKER_TOKEN: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-stripe-webhook/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ services = [
# STRIPE_SECRET_KEY
# STRIPE_SIGNING_SECRET_KEY
# EXACT_API_ENDPOINT
# EXACT_ACCOUNT_WORKER_SECRET
# CF_SECURE_WORKER_TOKEN

0 comments on commit 0b47f66

Please sign in to comment.