Skip to content

Commit

Permalink
Update validateIPCSender
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfish-shogi committed Nov 10, 2024
1 parent 47f67f8 commit 6e53277
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/background/window/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ const allowedIPCSenders = [
{ protocol: "file:", host: /^$/ },
];

export function validateIPCSender(frame: WebFrameMain) {
export function validateIPCSender(frame: WebFrameMain | null) {
if (!frame) {
// TODO:
// electron 33.0.2 から 33.2.0 へのアップデートで frame が null になる可能性が生じるようになった。
// ただし、null になるのはナビゲーション中やフレーム破棄後であるとされ、ここに null が渡されるケースは無いと思われる。
// null の場合に例外を投げるようにしても良いが、十分な検証ができるまではエラーログの出力に留める。
getAppLogger().error("validateIPCSender: frame is null");
return;
}
const u = new URL(frame.url);
for (const allowed of allowedIPCSenders) {
if (u.protocol === allowed.protocol && allowed.host.test(u.host)) {
Expand Down
1 change: 1 addition & 0 deletions src/tests/background/window/security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe("security", () => {
validateIPCSender({
url: "file:///home/shogi/apps/shogihome/assets.asr",
} as any);
validateIPCSender(null);
});

it("validateIPCSender/notAllowed", () => {
Expand Down

0 comments on commit 6e53277

Please sign in to comment.