Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/browser/src/platform/ipc/ipc-background.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -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 },
},
),
);
});

Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/app/platform/ipc/web-ipc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type: "bitwarden-ipc-message",
message: {
destination: message.destination,
payload: message.payload,
payload: [...message.payload],
topic: message.topic,
},
} satisfies IpcMessage,
Expand All @@ -50,9 +50,16 @@
return;
}

this.communicationBackend?.deliver_message(
if (
typeof message.message.destination !== "object" ||
message.message.destination.Web == undefined
) {
return;

Check warning on line 57 in apps/web/src/app/platform/ipc/web-ipc.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/platform/ipc/web-ipc.service.ts#L57

Added line #L57 was not covered by tests
}

this.communicationBackend?.receive(
new IncomingMessage(
message.message.payload,
new Uint8Array(message.message.payload),
message.message.destination,
"BrowserBackground",
message.message.topic,
Expand Down
6 changes: 5 additions & 1 deletion libs/common/src/platform/ipc/ipc-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { OutgoingMessage } from "@bitwarden/sdk-internal";

export interface IpcMessage {
type: "bitwarden-ipc-message";
message: Omit<OutgoingMessage, "free">;
message: SerializedOutgoingMessage;
}

export interface SerializedOutgoingMessage extends Omit<OutgoingMessage, "free" | "payload"> {
payload: number[];
}

export function isIpcMessage(message: any): message is IpcMessage {
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/platform/ipc/ipc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

protected async initWithClient(client: IpcClient): Promise<void> {
this._client = client;
await this._client.start();

Check warning on line 26 in libs/common/src/platform/ipc/ipc.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/platform/ipc/ipc.service.ts#L26

Added line #L26 was not covered by tests

this._messages$ = new Observable<IncomingMessage>((subscriber) => {
let isSubscribed = true;
const receiveLoop = async () => {
Expand Down
25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"@angular/platform-browser": "19.2.14",
"@angular/platform-browser-dynamic": "19.2.14",
"@angular/router": "19.2.14",
"@bitwarden/sdk-internal": "0.2.0-main.177",
"@bitwarden/sdk-internal": "0.2.0-main.198",
"@electron/fuses": "1.8.0",
"@emotion/css": "11.13.5",
"@koa/multer": "3.1.0",
Expand Down
Loading