An open-source, self-hosted system for apps built with web technologies.
Allow System storage across the filesystem
zohayrslileh1c7f373c9f46
diff --git a/scripts/contracts/storage.ts b/scripts/contracts/storage.tsindex 1b62040..93454ce 100644--- a/scripts/contracts/storage.ts+++ b/scripts/contracts/storage.ts@@ -1,8 +1,8 @@import assert from "node:assert/strict"import { mkdirSync, mkdtempSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs"import { tmpdir } from "node:os"-import { join } from "node:path"-import FileArea from "@libs/file-area"+import { join, resolve } from "node:path"+import FileArea, { FileSystem } from "@libs/file-area"import AuthManager from "@server/core/link-manager/auth-manager/auth-manager"const fixture = mkdtempSync(join(tmpdir(), "phreshos-storage-"))@@ -11,7 +11,7 @@ const outside = join(fixture, "outside")try {const storage = new FileArea(root)- const home = new FileArea(join(fixture, "home"))+ const home = new FileSystem(resolve(fixture, "home"))const authManager = Object.assign(Object.create(AuthManager.prototype), {linkManager: { application: { home, storage: { path: root } } },$outbound: { async publish() {} }@@ -21,6 +21,7 @@ try {}).storageassert.equal(await systemStorage.call(authManager, "path", []), home.path)+ assert.equal(await systemStorage.call(authManager, "resolve", ["..", "outside"]), outside)mkdirSync(join(root, "kept"), { recursive: true })mkdirSync(join(root, "nested"), { recursive: true })@@ -36,6 +37,10 @@ try {mkdirSync(outside, { recursive: true })writeFileSync(join(outside, "value.txt"), "outside")symlinkSync(outside, join(root, "escape"), "dir")+ symlinkSync(outside, join(home.path, "escape"), "dir")++ assert.equal(home.resolve(["escape", "value.txt"]), join(home.path, "escape", "value.txt"))+ assert.equal(home.stat(["escape", "value.txt"])?.kind, "file")assert.throws(() => storage.stat(["escape", "value.txt"]), /symbolic link/)assert.throws(() => storage.list(["escape"]), /symbolic link/)diff --git a/source/libs/file-area.ts b/source/libs/file-area.tsindex d34401a..c7a367f 100644--- a/source/libs/file-area.ts+++ b/source/libs/file-area.ts@@ -1,6 +1,6 @@import { createReadStream, createWriteStream, lstatSync, mkdirSync, readdirSync, renameSync, rmSync, statSync } from "node:fs"import { randomUUID } from "node:crypto"-import { dirname, isAbsolute, join, relative, sep } from "node:path"+import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path"import { rm } from "node:fs/promises"import { Readable } from "node:stream"import { pipeline } from "node:stream/promises"@@ -148,6 +148,15 @@ export default class FileArea {}}+/** Native filesystem access resolved from one entry point without confinement. */+export class FileSystem extends FileArea {++ public override resolve(joins: string[]) {++ return resolve(this.path, ...joins)+ }+}+export type EntryStat = FileStat | DirectoryStat | OtherStatexport interface FileStat {diff --git a/source/server/core/application.ts b/source/server/core/application.tsindex 38dbcfe..e689a1c 100644--- a/source/server/core/application.ts+++ b/source/server/core/application.ts@@ -7,7 +7,7 @@ import DialogManager from "./dialog-manager"import AppearanceManager from "./appearance-manager"import openStore from "./open-store"import Keyv from "keyv"-import FileArea from "@libs/file-area"+import FileArea, { FileSystem } from "@libs/file-area"import { homedir } from "node:os"import System from "./system"@@ -24,7 +24,7 @@ export default class Application {public readonly storage: FileManager- /** Native operating-system home exposed as the Server Host's Storage root. */+ /** Native filesystem access entered from the operating-system user's home. */public readonly home: FileArea/** Internal application persistence, reached publicly through named methods. */@@ -80,7 +80,7 @@ export default class Application {const storage = new FileManager(homePath)- const home = new FileArea(homedir(), "the native home directory")+ const home = new FileSystem(homedir(), "the native filesystem")const store = openStore(storage.path)diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex 8a44152..d52bfc4 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -1953,8 +1953,8 @@ export default class ProcessManager extends TheLink {}// Native filesystem work remains local to the Server SDK. The System- // supplies only its authoritative home root; Storage confines every- // operation performed beneath it.+ // supplies the user's home as the relative entry point; the+ // SDK may resolve beyond it without turning the host into a file proxy.if (word === "host-storage") {if (rest[0] !== "path") throw new Error("A server half asks the host only for its Storage path")