From 9f8359c52162c7115d64578fb73b94b065336d77 Mon Sep 17 00:00:00 2001 From: Craig Slusher Date: Thu, 25 Apr 2024 17:42:16 -0400 Subject: [PATCH] fix(external_messaging_name): Fix untrusted external messaging name check (#963) * Name can be missing on external messages * Fixes order to prioritize the sender since data is untrusted --- .../features/background-service-worker/bgsw-messaging.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/plasmo/src/features/background-service-worker/bgsw-messaging.ts b/cli/plasmo/src/features/background-service-worker/bgsw-messaging.ts index 51df68cce..5afe3456d 100644 --- a/cli/plasmo/src/features/background-service-worker/bgsw-messaging.ts +++ b/cli/plasmo/src/features/background-service-worker/bgsw-messaging.ts @@ -30,7 +30,7 @@ globalThis.__plasmoInternalPortMap = new Map() ${importSection} chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => { - switch (request.name) { + switch (request?.name) { ${externalMessageSection} default: break @@ -97,8 +97,8 @@ const getHandlerList = async ( const getMessageCode = (name: string, importName: string) => `case "${name}": ${importName}({ - sender, - ...request + ...request, + sender }, { send: (p) => sendResponse(p) })