Skip to content

Commit ebcabaa

Browse files
authored
fix(sessions): disable shared session access (#5122)
1 parent 60d2fd5 commit ebcabaa

4 files changed

Lines changed: 13 additions & 29 deletions

File tree

‎apps/web/src/app/s/[sessionId]/page.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import { OpenInCliButton } from '@/app/share/[shareId]/open-in-cli-button';
1010
import { OpenInEditorButton } from '@/app/share/[shareId]/open-in-editor-button';
1111
import { Card, CardContent, CardHeader } from '@/components/ui/card';
1212

13-
export const revalidate = 86400;
13+
export const dynamic = 'force-dynamic';
1414

1515
export default async function SharedSessionPage({
1616
params,
1717
}: {
1818
params: Promise<{ sessionId: string }>;
1919
}) {
20+
notFound();
21+
2022
const { sessionId } = await params;
2123

2224
// Validate sessionId is a valid UUID before querying the database

‎apps/web/src/app/share/[shareId]/page.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { cookies } from 'next/headers';
2727
import { getExtensionUrl } from '@/components/auth/getExtensionUrl';
2828
import { validate as isValidUUID } from 'uuid';
2929

30-
export const revalidate = 86400;
30+
export const dynamic = 'force-dynamic';
3131

3232
/**
3333
* Extracts text content from a blob message based on its type.
@@ -85,6 +85,8 @@ export default async function SharePage({
8585
params: Promise<{ shareId: string }>;
8686
searchParams: Promise<NextAppSearchParams>;
8787
}) {
88+
notFound();
89+
8890
const { shareId } = await params;
8991
const resolvedSearchParams = await searchParams;
9092
const cookieStore = await cookies();

‎services/session-ingest/src/app.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getSessionExport } from './services/session-export';
1616
import { withDORetry } from '@kilocode/worker-utils';
1717

1818
const sessionIdSchema = z.string().startsWith('ses_').length(30);
19+
const publicSessionAccessEnabled: boolean = false;
1920
const invalidateSessionAccessSchema = z.object({
2021
kiloUserId: z.string().min(1),
2122
organizationId: z.uuid(),
@@ -80,6 +81,10 @@ app.get('/session/:sessionId', async c => {
8081
);
8182
}
8283

84+
if (!publicSessionAccessEnabled) {
85+
return c.json({ success: false, error: 'session_not_found' }, 404);
86+
}
87+
8388
const db = getWorkerDb(c.env.HYPERDRIVE.connectionString);
8489
const rows = await db
8590
.select({

‎services/session-ingest/src/index.test.ts‎

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ vi.mock('./dos/SessionAccessCacheDO', () => ({
3232

3333
import { app } from './index';
3434
import { getWorkerDb } from '@kilocode/db/client';
35-
import { getSessionIngestDO } from './dos/SessionIngestDO';
3635
import { getSessionAccessCacheDO } from './dos/SessionAccessCacheDO';
3736

3837
type TestBindings = {
@@ -169,37 +168,13 @@ describe('public session route', () => {
169168
expect(res.status).toBe(400);
170169
});
171170

172-
it('returns 404 when public_id not found', async () => {
171+
it('returns 404 without looking up the public_id', async () => {
173172
const { db, selectResult } = makeDbFakes();
174173
vi.mocked(getWorkerDb).mockReturnValue(db as never);
175-
selectResult.mockResolvedValueOnce([]);
176174

177175
const res = await app.request('/session/11111111-1111-4111-8111-111111111111', {}, defaultEnv);
178176

179177
expect(res.status).toBe(404);
180-
});
181-
182-
it('returns DO snapshot json with content-type', async () => {
183-
const { db, selectResult } = makeDbFakes();
184-
vi.mocked(getWorkerDb).mockReturnValue(db as never);
185-
selectResult.mockResolvedValueOnce([
186-
{
187-
session_id: 'ses_12345678901234567890123456',
188-
kilo_user_id: 'usr_123',
189-
},
190-
]);
191-
192-
const stub = {
193-
getAllStream: vi.fn(async () => new Response('{"ok":true}').body!),
194-
};
195-
vi.mocked(getSessionIngestDO).mockReturnValue(
196-
stub as unknown as ReturnType<typeof getSessionIngestDO>
197-
);
198-
199-
const res = await app.request('/session/11111111-1111-4111-8111-111111111111', {}, defaultEnv);
200-
201-
expect(res.status).toBe(200);
202-
expect(res.headers.get('content-type')).toBe('application/json; charset=utf-8');
203-
expect(await res.text()).toBe('{"ok":true}');
178+
expect(selectResult).not.toHaveBeenCalled();
204179
});
205180
});

0 commit comments

Comments
 (0)