Skip to content

Commit f5466dc

Browse files
fix(server): validate browser access for the running user
1 parent e7d7e05 commit f5466dc

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎apps/server/src/preview/PreviewBrowser.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,17 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("PreviewBrowser",
162162
...(hostPlatform === "win32"
163163
? []
164164
: [{ name: "a non-executable file", value: "not-executable", absolute: true }]),
165+
...(hostPlatform === "win32" || HostProcess.UserId.defaultValue() === 0
166+
? []
167+
: [{ name: "execution denied to its owner", value: "owner-denied", absolute: true }]),
165168
])("rejects $name without falling back to a download", (testCase) =>
166169
Effect.gen(function* () {
167170
const fs = yield* FileSystem.FileSystem;
168171
const path = yield* Path.Path;
169172
const directory = yield* fs.makeTempDirectoryScoped();
170173
yield* fs.makeDirectory(path.join(directory, "directory"));
171174
yield* fs.writeFileString(path.join(directory, "not-executable"), "", { mode: 0o644 });
175+
yield* fs.writeFileString(path.join(directory, "owner-denied"), "", { mode: 0o655 });
172176
const { browser, baseDir, requests } = yield* makeHarness({
173177
environment: {
174178
T3CODE_BROWSER_EXECUTABLE_PATH: testCase.absolute

‎apps/server/src/preview/PreviewBrowser.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @effect-diagnostics nodeBuiltinImport:off - Effect has no incremental digest.
1+
// @effect-diagnostics nodeBuiltinImport:off - Effect has no incremental digest or execute-access check.
22
import * as EffectNodeStream from "@effect/platform-node/NodeStream";
33
import * as HostProcess from "@t3tools/shared/HostProcess";
44
import * as Cause from "effect/Cause";
@@ -17,6 +17,7 @@ import * as Semaphore from "effect/Semaphore";
1717
import * as Stream from "effect/Stream";
1818
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
1919
import * as NodeCrypto from "node:crypto";
20+
import * as NodeFSP from "node:fs/promises";
2021

2122
import * as ServerConfig from "../config.ts";
2223
import { openZipArchive } from "../zipArchive.ts";
@@ -186,6 +187,10 @@ export const makePreviewBrowser = Effect.fn("PreviewBrowser.make")(function* (
186187
if (info.type !== "File" || (platform !== "win32" && (info.mode & 0o111) === 0)) {
187188
return yield* invalidPath;
188189
}
190+
yield* Effect.tryPromise({
191+
try: () => NodeFSP.access(configuredPath, NodeFSP.constants.X_OK),
192+
catch: () => invalidPath,
193+
});
189194
return configuredPath;
190195
}).pipe(Effect.withSpan("PreviewBrowser.executable"));
191196
return PreviewBrowser.of({

0 commit comments

Comments
 (0)