Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(threads): recheck thread visibility after reading the file request body

ARAYN7011213ccc236c53
diff --git a/server/routes/threads.ts b/server/routes/threads.ts
index ac22d6f244..7e6cdc4eb5 100644
--- a/server/routes/threads.ts
+++ b/server/routes/threads.ts
@@ -215,6 +215,8 @@ export function createThreadRoutes(deps: ThreadRouteDeps): RouteHandler {
const mediaGrant = mediaId ? mediaLinks.use(mediaId, threadId, message.id, auth) : null;
if (mediaId && !mediaGrant) return json(res, 404, { error: "that video link has expired", code: "media_link_expired" });
const body = method === "POST" ? await readBody(req) : null;
+ // Access may have been revoked while the body was in flight; ask again before any file is opened.
+ if (body && !visibleTo(viewerFor(auth)).thread(threadId)) return json(res, 404, { error: "no such conversation" });
const asksMediaLink = body?.media === true;
const rawReference = streamsMessageImage ? url.searchParams.get("ref") : null;
if (streamsMessageImage && (!rawReference || !/^\d+$/.test(rawReference))) {