From 99ab025e8be5d51f2cc28e7d8f6a45cf00b2d3f0 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Wed, 3 Jul 2024 11:59:04 +0100 Subject: [PATCH] replace `atob`/`btoa` with `Buffer.from` --- app/root.test.ts | 2 +- app/root.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/root.test.ts b/app/root.test.ts index 96e868fa..edeb0169 100644 --- a/app/root.test.ts +++ b/app/root.test.ts @@ -37,7 +37,7 @@ describe('root loader', () => { { ...payload, exp: Math.round(inFiveMinutes.getTime() / 1000) }, signature, ] - .map((s) => btoa(JSON.stringify(s))) + .map((s) => Buffer.from(JSON.stringify(s)).toString('base64')) .join('.')}` const url = new URL('https://orange.cloudflare.dev/') diff --git a/app/root.tsx b/app/root.tsx index e8bbe34a..b87e6343 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -56,7 +56,7 @@ export const loader = async ({ request, context }: LoaderFunctionArgs) => { if (!CF_Authorization) return defaultResponse const [, payload] = CF_Authorization.split('.') - const data = JSON.parse(atob(payload)) + const data = JSON.parse(Buffer.from(payload, 'base64').toString()) const expires = new Date(data.exp * 1000) const now = new Date() if (addOneDay(now) > expires) {