1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-20615] Only process incoming messages once (#14645)

* feat: start ipc client

* fix: payload serialization issues

* feat: filter incoming messages by destination

* fix: adapt to SDK renames

* feat: update sdk
This commit is contained in:
Andreas Coroiu
2025-06-12 10:17:03 +02:00
committed by GitHub
parent ed169335bf
commit 0e608639cc
6 changed files with 49 additions and 17 deletions

View File

@@ -23,14 +23,14 @@ export class IpcBackgroundService extends IpcService {
await SdkLoadService.Ready;
this.communicationBackend = new IpcCommunicationBackend({
async send(message: OutgoingMessage): Promise<void> {
if (typeof message.destination === "object") {
if (typeof message.destination === "object" && message.destination.Web != undefined) {
await BrowserApi.tabSendMessage(
{ id: message.destination.Web.id } as chrome.tabs.Tab,
{
type: "bitwarden-ipc-message",
message: {
destination: message.destination,
payload: message.payload,
payload: [...message.payload],
topic: message.topic,
},
} satisfies IpcMessage,
@@ -44,7 +44,7 @@ export class IpcBackgroundService extends IpcService {
});
BrowserApi.messageListener("platform.ipc", (message, sender) => {
if (!isIpcMessage(message)) {
if (!isIpcMessage(message) || message.message.destination !== "BrowserBackground") {
return;
}
@@ -53,10 +53,14 @@ export class IpcBackgroundService extends IpcService {
return;
}
this.communicationBackend?.deliver_message(
new IncomingMessage(message.message.payload, message.message.destination, {
Web: { id: sender.tab.id },
}),
this.communicationBackend?.receive(
new IncomingMessage(
new Uint8Array(message.message.payload),
message.message.destination,
{
Web: { id: sender.tab.id },
},
),
);
});

View File

@@ -27,7 +27,7 @@ export class WebIpcService extends IpcService {
type: "bitwarden-ipc-message",
message: {
destination: message.destination,
payload: message.payload,
payload: [...message.payload],
topic: message.topic,
},
} satisfies IpcMessage,
@@ -50,9 +50,16 @@ export class WebIpcService extends IpcService {
return;
}
this.communicationBackend?.deliver_message(
if (
typeof message.message.destination !== "object" ||
message.message.destination.Web == undefined
) {
return;
}
this.communicationBackend?.receive(
new IncomingMessage(
message.message.payload,
new Uint8Array(message.message.payload),
message.message.destination,
"BrowserBackground",
message.message.topic,