From 725de66758e77d94f5bf917cde8069f7a215de6b Mon Sep 17 00:00:00 2001 From: Tristan Lee Date: Tue, 9 Jan 2024 10:05:00 -0500 Subject: [PATCH] Fix --- .../functions/general/signed-request/main.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/v7-edge-functions/functions/general/signed-request/main.js b/examples/v7-edge-functions/functions/general/signed-request/main.js index cc6bd132c..3c0919415 100644 --- a/examples/v7-edge-functions/functions/general/signed-request/main.js +++ b/examples/v7-edge-functions/functions/general/signed-request/main.js @@ -70,12 +70,12 @@ async function generateSignedUrl(request, key) { * Verifies the MAC and expiry of the given URL. If the URL is valid, the request is forwarded to the origin. */ async function verifyAndFetch(request, key) { - const invalidResponse = new Response('Invalid request', { status: 403 }); + const invalidResponse = (reason) => + new Response(`Invalid request - ${reason}`, { status: 403 }); const url = new URL(request.url); if (!url.searchParams.has('mac') || !url.searchParams.has('expiry')) { - invalidResponse.body += ' - Missing MAC or expiry'; - return invalidResponse; + return invalidResponse('Missing MAC or expiry'); } const expiry = Number(url.searchParams.get('expiry')); @@ -89,14 +89,12 @@ async function verifyAndFetch(request, key) { // Ensure that the MAC is valid if (hashInBase64 !== receivedMacBase64) { - invalidResponse.body += ' - Bad MAC'; - return invalidResponse; + return invalidResponse('Invalid MAC'); } // Ensure that the URL has not expired if (Date.now() > expiry) { - invalidResponse.body += ' - Expired'; - return invalidResponse; + return invalidResponse('URL has expired'); } // Forward the remaining request path after **/verify/* to the origin