Skip to content

Commit f2e0793

Browse files
fix(server): hide a linked voice model's path without filesystem access
Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 593ec1f commit f2e0793

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

‎apps/server/src/speech/http.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,31 @@ effectIt.effect(
165165
HttpApiBuilder.layer(HttpApi.make("environment").add(EnvironmentVoiceHttpApi)).pipe(
166166
Layer.provide(speechHttpApiLayer),
167167
Layer.provide(principal(AuthOrchestrationOperateScope, AuthSettingsWriteScope)),
168-
Layer.provide(Layer.mock(SpeechService.SpeechService)({})),
168+
Layer.provide(
169+
Layer.mock(SpeechService.SpeechService)({
170+
models: () =>
171+
Effect.succeed({
172+
models: [
173+
{
174+
id: "fixture/model",
175+
name: "Fixture",
176+
description: "",
177+
size: 1,
178+
languages: ["en"],
179+
accuracy: 0,
180+
speed: 0,
181+
recommended: false,
182+
supportsStreaming: false,
183+
supportsLanguageDetection: false,
184+
supportsTranslation: false,
185+
active: true,
186+
state: "installed",
187+
linkedFrom: "/home/someone/models/fixture.gguf",
188+
},
189+
],
190+
}),
191+
}),
192+
),
169193
Layer.provide(cloud),
170194
Layer.provide(dependencies),
171195
Layer.provide(HttpServer.layerServices),
@@ -241,6 +265,10 @@ effectIt.effect(
241265
),
242266
);
243267
expect(link.status).toBe(403);
268+
const listed = yield* Effect.promise(() =>
269+
handler(new Request("http://localhost/api/voice/models"), context),
270+
);
271+
expect(yield* Effect.promise(() => listed.text())).not.toContain("/home/someone");
244272
}).pipe(Effect.scoped),
245273
);
246274

‎apps/server/src/speech/http.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
AuthOrchestrationOperateScope,
55
AuthSettingsWriteScope,
66
type AuthEnvironmentScope,
7+
EnvironmentAuthenticatedPrincipal,
78
EnvironmentHttpApi,
9+
type EnvironmentSpeechModels,
810
EnvironmentVoiceBodyLimit,
911
SPEECH_MAX_OPTIONS_BYTES,
1012
} from "@t3tools/contracts";
@@ -54,6 +56,14 @@ const mapSpeechError = <A, R>(effect: Effect.Effect<A, SpeechService.SpeechError
5456
}),
5557
);
5658

59+
// A linked model's origin is a path on this machine; only filesystem readers may see it.
60+
// Untraced: it runs inside each handler's own span.
61+
const withoutHostPaths = Effect.fnUntraced(function* (result: EnvironmentSpeechModels) {
62+
const session = yield* EnvironmentAuthenticatedPrincipal;
63+
if (session.scopes.has(AuthFilesystemReadScope)) return result;
64+
return { models: result.models.map(({ linkedFrom: _, ...model }) => model) };
65+
});
66+
5767
export const speechHttpApiLayer = HttpApiBuilder.group(
5868
EnvironmentHttpApi,
5969
"voice",
@@ -134,35 +144,45 @@ export const speechHttpApiLayer = HttpApiBuilder.group(
134144
"models",
135145
Effect.fn("environment.voice.models")(function* (args) {
136146
yield* guard(args.endpoint.name);
137-
return yield* speech.models(args.query.benchmarks === "1").pipe(mapSpeechError);
147+
return yield* speech
148+
.models(args.query.benchmarks === "1")
149+
.pipe(mapSpeechError, Effect.flatMap(withoutHostPaths));
138150
}),
139151
)
140152
.handle(
141153
"downloadModel",
142154
Effect.fn("environment.voice.downloadModel")(function* (args) {
143155
yield* guard(args.endpoint.name, AuthSettingsWriteScope);
144-
return yield* speech.downloadModel(args.payload.modelId).pipe(mapSpeechError);
156+
return yield* speech
157+
.downloadModel(args.payload.modelId)
158+
.pipe(mapSpeechError, Effect.flatMap(withoutHostPaths));
145159
}),
146160
)
147161
.handle(
148162
"selectModel",
149163
Effect.fn("environment.voice.selectModel")(function* (args) {
150164
yield* guard(args.endpoint.name, AuthSettingsWriteScope);
151-
return yield* speech.selectModel(args.payload.modelId).pipe(mapSpeechError);
165+
return yield* speech
166+
.selectModel(args.payload.modelId)
167+
.pipe(mapSpeechError, Effect.flatMap(withoutHostPaths));
152168
}),
153169
)
154170
.handle(
155171
"cancelModelDownload",
156172
Effect.fn("environment.voice.cancelModelDownload")(function* (args) {
157173
yield* guard(args.endpoint.name, AuthSettingsWriteScope);
158-
return yield* speech.cancelDownload(args.payload.modelId).pipe(mapSpeechError);
174+
return yield* speech
175+
.cancelDownload(args.payload.modelId)
176+
.pipe(mapSpeechError, Effect.flatMap(withoutHostPaths));
159177
}),
160178
)
161179
.handle(
162180
"removeModel",
163181
Effect.fn("environment.voice.removeModel")(function* (args) {
164182
yield* guard(args.endpoint.name, AuthSettingsWriteScope);
165-
return yield* speech.removeModel(args.payload.modelId).pipe(mapSpeechError);
183+
return yield* speech
184+
.removeModel(args.payload.modelId)
185+
.pipe(mapSpeechError, Effect.flatMap(withoutHostPaths));
166186
}),
167187
)
168188
.handle(

0 commit comments

Comments
 (0)