Skip to content

Commit 3ecc8e7

Browse files
committed
🐞fix(mac/statusbar): 响应安全审查优化配置更新逻辑
- 在 ipc-mac-statusbar.ts 和 ipc-taskbar.ts 的 SET_OPTION 处理器中引入动态允许列表机制。 - 利用 DEFAULT_TASKBAR_CONFIG 的键名自动过滤合法配置项,防止通过 IPC 进行非法属性注入,增强全平台配置安全性。
1 parent 34635e5 commit 3ecc8e7

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

electron/main/ipc/ipc-mac-statusbar.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LyricLine } from "@applemusic-like-lyrics/lyric";
22
import {
3+
DEFAULT_TASKBAR_CONFIG,
34
TASKBAR_IPC_CHANNELS,
45
type SyncStatePayload,
56
type SyncTickPayload,
@@ -161,8 +162,14 @@ export const initMacStatusBarIpc = () => {
161162

162163
ipcMain.on(TASKBAR_IPC_CHANNELS.SET_OPTION, (_event, option: Partial<TaskbarConfig>) => {
163164
if (!option) return;
165+
166+
// 安全过滤:仅允许写入 DEFAULT_TASKBAR_CONFIG 中定义的合法键
167+
const allowedKeys = Object.keys(DEFAULT_TASKBAR_CONFIG);
168+
164169
Object.entries(option).forEach(([key, value]) => {
165-
store.set(`taskbar.${key}`, value);
170+
if (allowedKeys.includes(key)) {
171+
store.set(`taskbar.${key}`, value);
172+
}
166173
});
167174
// macOS 模式下不处理窗口可见性,仅同步配置
168175
});

electron/main/ipc/ipc-taskbar.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { TASKBAR_IPC_CHANNELS, type SyncStatePayload, type TaskbarConfig } from "@shared";
1+
import {
2+
DEFAULT_TASKBAR_CONFIG,
3+
TASKBAR_IPC_CHANNELS,
4+
type SyncStatePayload,
5+
type TaskbarConfig,
6+
} from "@shared";
27
import { app, ipcMain, nativeTheme } from "electron";
38
import type EventEmitter from "node:events";
49
import { useStore } from "../store";
@@ -45,12 +50,21 @@ const initTaskbarIpc = () => {
4550
TASKBAR_IPC_CHANNELS.SET_OPTION,
4651
(_event, option: Partial<TaskbarConfig>, pushToWindow = true) => {
4752
if (!option) return;
53+
54+
// 安全过滤:仅允许写入 DEFAULT_TASKBAR_CONFIG 中定义的合法键
55+
const allowedKeys = Object.keys(DEFAULT_TASKBAR_CONFIG);
56+
4857
// 增量更新
4958
const prev = getTaskbarConfig();
50-
const next = { ...prev, ...option };
59+
const next = { ...prev };
60+
5161
Object.entries(option).forEach(([key, value]) => {
52-
store.set(`taskbar.${key}`, value);
62+
if (allowedKeys.includes(key)) {
63+
store.set(`taskbar.${key}`, value);
64+
(next as any)[key] = value;
65+
}
5366
});
67+
5468
// 推送到歌词窗口
5569
if (pushToWindow) {
5670
taskbarLyricManager.send(TASKBAR_IPC_CHANNELS.SYNC_STATE, {

0 commit comments

Comments
 (0)