Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/server/src/workspace/WorkspaceFileSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,11 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
}),
);

it.effect("does not read server state files", () =>
it.effect("does not read or write server state files", () =>
Effect.gen(function* () {
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
const config = yield* ServerConfig.ServerConfig;
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const cwd = yield* makeTempDir;
yield* writeTextFile(config.secretsDir, "example.bin", "example\n");
Expand All @@ -385,6 +386,24 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
const error = yield* workspaceFileSystem.readFile(input).pipe(Effect.flip);
expect(error).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
}
const secrets = path.relative(config.stateDir, config.secretsDir);
for (const relativePath of [
"statev2.sqlite",
path.join(secrets, "example.bin"),
path.join(secrets, "new.bin"),
]) {
const error = yield* workspaceFileSystem
.writeFile({ cwd: config.stateDir, relativePath, contents: "overwritten\n" })
.pipe(Effect.flip);
expect(error).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
}
expect(yield* fileSystem.readFileString(path.join(config.stateDir, "statev2.sqlite"))).toBe(
"example\n",
);
expect(yield* fileSystem.readFileString(path.join(config.secretsDir, "example.bin"))).toBe(
"example\n",
);
expect(yield* fileSystem.exists(path.join(config.secretsDir, "new.bin"))).toBe(false);
const metadata = yield* workspaceFileSystem.getMetadata({
paths: [
path.join(config.secretsDir, "example.bin"),
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/workspace/WorkspaceFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ export const make = Effect.gen(function* () {
yield* knownWorkspaces.assertContains(input.cwd);
const target = yield* resolveWriteTarget(input);
const realTargetPath = target.realTargetPath;
if (yield* isServerInternalPath(realTargetPath)) {
return yield* new WorkspacePaths.WorkspacePathOutsideRootError({
workspaceRoot: input.cwd,
relativePath: input.relativePath,
});
}
const replacesFile = yield* fileSystem
.exists(realTargetPath)
.pipe(Effect.orElseSucceed(() => false));
Expand Down
Loading