Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): allow clearing local data from the scoped userData directory (#585)

yulei666d26988e0eefb
diff --git a/apps/desktop/src/main/local-data-reset.mjs b/apps/desktop/src/main/local-data-reset.mjs
index a50cc1b6..624e280d 100644
--- a/apps/desktop/src/main/local-data-reset.mjs
+++ b/apps/desktop/src/main/local-data-reset.mjs
@@ -30,20 +30,27 @@ export class LocalDataResetError extends Error {
}
}
+// Electron derives userData from the package name, so a scoped package such as
+// "@edgeever/desktop" lives at "<appData>/@edgeever/desktop".
+const isManagedRelativePath = (relativeTarget) => {
+ const segments = relativeTarget.split(sep);
+ if (segments.some((segment) => !segment || segment === "." || segment === "..")) return false;
+ if (segments.length === 1) return true;
+ return segments.length === 2 && /^@[^@]+$/.test(segments[0]);
+};
+
export const managedUserDataDirectory = (userDataDirectory, appDataDirectory) => {
const target = resolve(userDataDirectory);
const appData = resolve(appDataDirectory);
const relativeTarget = relative(appData, target);
if (
!relativeTarget ||
- relativeTarget === ".." ||
- relativeTarget.startsWith(`..${sep}`) ||
isAbsolute(relativeTarget) ||
- relativeTarget.includes(sep)
+ !isManagedRelativePath(relativeTarget)
) {
throw new LocalDataResetError(
"unsafe-data-directory",
- "EdgeEver local data must be a direct child of the application-data directory",
+ "EdgeEver local data must be a direct child of the application-data directory or a single @scope/name directory in it",
);
}
return target;
diff --git a/apps/desktop/src/main/local-data-reset.test.mjs b/apps/desktop/src/main/local-data-reset.test.mjs
index a61c7c80..1aec9d17 100644
--- a/apps/desktop/src/main/local-data-reset.test.mjs
+++ b/apps/desktop/src/main/local-data-reset.test.mjs
@@ -8,12 +8,37 @@ import {
} from "./local-data-reset.mjs";
describe("desktop local data reset", () => {
- test("only accepts a direct child of the application-data directory", () => {
+ test("only accepts a direct child or a single @scope/name directory of the application-data directory", () => {
expect(managedUserDataDirectory(
"/Users/example/Library/Application Support/EdgeEver",
"/Users/example/Library/Application Support",
)).toBe("/Users/example/Library/Application Support/EdgeEver");
+ expect(managedUserDataDirectory(
+ "/Users/example/Library/Application Support/@edgeever/desktop",
+ "/Users/example/Library/Application Support",
+ )).toBe("/Users/example/Library/Application Support/@edgeever/desktop");
+ expect(() => managedUserDataDirectory(
+ "/Users/example/Library/Application Support/@edgeever/desktop/accounts",
+ "/Users/example/Library/Application Support",
+ )).toThrow();
+ // Two levels are allowed only under an @scope; another app's vendor folder is not.
+ expect(() => managedUserDataDirectory(
+ "/Users/example/Library/Application Support/SomeVendor/SomeApp",
+ "/Users/example/Library/Application Support",
+ )).toThrow();
+ for (const scoped of ["@/desktop", "@a@b/desktop"]) {
+ try {
+ managedUserDataDirectory(
+ `/Users/example/Library/Application Support/${scoped}`,
+ "/Users/example/Library/Application Support",
+ );
+ throw new Error(`expected ${scoped} to be rejected`);
+ } catch (error) {
+ expect(error).toBeInstanceOf(LocalDataResetError);
+ expect(error.code).toBe("unsafe-data-directory");
+ }
+ }
expect(() => managedUserDataDirectory(
"/Users/example/Library/Application Support",
"/Users/example/Library/Application Support",