From 076f62fa1be36f6903ed0dd15fcf0348d016238c Mon Sep 17 00:00:00 2001 From: Codeman maintainer Date: Tue, 13 Oct 2026 18:08:38 +0200 Subject: [PATCH] fix(preview): refuse a bare `~` folder in a Docker case too (#604 merge-time fix) The Docker refusal on POST /api/sessions/:id/folders tested only `~/`, but listFolder also expands a bare `~` to this host's home, so a Docker case could list and serve the host home through it (the preview's "Show folder" for a `~/x.png` link reached it with no typing). A bare `~` now gets the same 400. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/web/routes/file-routes.ts | 3 ++- test/routes/folder-grid-routes.test.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/web/routes/file-routes.ts b/src/web/routes/file-routes.ts index 4e7a886e..ba521cd0 100644 --- a/src/web/routes/file-routes.ts +++ b/src/web/routes/file-routes.ts @@ -2404,7 +2404,8 @@ export function registerFileRoutes(app: FastifyInstance, ctx: SessionPort & Even reply.code(400).send(createErrorResponse(ApiErrorCode.INVALID_INPUT, 'Missing folder path')); return; } - if (scope.docker && body.path.startsWith('~/')) { + // A bare `~` expands to this host's home too, not the container's. + if (scope.docker && (body.path === '~' || body.path.startsWith('~/'))) { reply.code(400).send(createErrorResponse(ApiErrorCode.INVALID_INPUT, DOCKER_HOME_PATH_ERROR)); return; } diff --git a/test/routes/folder-grid-routes.test.ts b/test/routes/folder-grid-routes.test.ts index e2575f5c..fee03639 100644 --- a/test/routes/folder-grid-routes.test.ts +++ b/test/routes/folder-grid-routes.test.ts @@ -341,6 +341,8 @@ describe('folder grid routes — local folder', () => { const home = await grant('~/renders'); expect(home.statusCode).toBe(400); expect(JSON.parse(home.body).error).toMatch(/docker/i); + // A bare `~` is this host's home as much as `~/` is. + expect((await grant('~')).statusCode).toBe(400); expect((await grant(dir)).statusCode).toBe(200); });