fix: harden app lock system unlock flow

This commit is contained in:
Zheng Liu committed 2026-06-24 14:42:49 +08:00
1 parent f6a49dbf0a
commit 0ea707f70f
14 files changed
+114 -26

No files matched your search

+6 -2
View File
@@ -383,8 +383,11 @@ function createAppLockController({
return saved;
}
async function requestReset() {
async function requestReset(currentPassword) {
const current = getSettings();
const verified = await verifyCurrentPassword(current, currentPassword);
if (verified !== true) return verified;
const saved = await saveSettings({
enabled: false,
timeoutMinutes: current.timeoutMinutes,
@@ -547,7 +550,8 @@ function createAppLockController({
ipcMain.handle("netcatty:appLock:requestEnable", () => requestEnable());
ipcMain.handle("netcatty:appLock:requestDisable", (_event, currentPassword) =>
requestDisable(currentPassword));
ipcMain.handle("netcatty:appLock:requestReset", () => requestReset());
ipcMain.handle("netcatty:appLock:requestReset", (_event, currentPassword) =>
requestReset(currentPassword));
ipcMain.handle("netcatty:appLock:requestPasswordChange", (_event, input) =>
requestPasswordChange(input));
ipcMain.handle("netcatty:appLock:setLocked", (_event, reason) => setLocked(reason));
+19 -1
View File
@@ -571,6 +571,24 @@ test("disabling app lock removes the saved password verifier", async () => {
assert.equal(saved.passwordVerifier, null);
});
test("resetting app lock requires the current password before clearing the verifier", async () => {
const { controller, runtimeBridge } = await createControllerHarness();
await controller.requestPasswordChange({ nextPassword: "alpha" });
await controller.requestEnable();
controller.setLocked("manual");
assert.deepEqual(
await controller.requestReset(),
{ ok: false, error: "empty-current" },
);
assert.deepEqual(
await controller.requestReset("wrong"),
{ ok: false, error: "incorrect" },
);
assert.equal(controller.getSettings().passwordVerifier !== null, true);
assert.equal(runtimeBridge.getState().locked, true);
});
test("resetting app lock clears the verifier, unlocks runtime, and broadcasts settings and runtime", async () => {
const { controller, runtimeBridge, windows } = await createControllerHarness();
await controller.requestPasswordChange({ nextPassword: "alpha" });
@@ -580,7 +598,7 @@ test("resetting app lock clears the verifier, unlocks runtime, and broadcasts se
win.sent.length = 0;
}
const saved = await controller.requestReset();
const saved = await controller.requestReset("alpha");
assert.equal(saved.enabled, false);
assert.equal(saved.passwordVerifier, null);
+2 -2
View File
@@ -492,8 +492,8 @@ function createPreloadApi(ctx) {
requestAppLockEnable: () => ipcRenderer.invoke("netcatty:appLock:requestEnable"),
requestAppLockDisable: (currentPassword) =>
ipcRenderer.invoke("netcatty:appLock:requestDisable", currentPassword),
requestAppLockReset: () =>
ipcRenderer.invoke("netcatty:appLock:requestReset"),
requestAppLockReset: (currentPassword) =>
ipcRenderer.invoke("netcatty:appLock:requestReset", currentPassword),
requestAppLockPasswordChange: (input) =>
ipcRenderer.invoke("netcatty:appLock:requestPasswordChange", input),
setAppLockRuntimeLocked: (reason) =>