Repository navigation
Serve game share links through /play/<threadId> instead of the raw bucket URL - #1
Merged
Merged
Conversation
…e raw bucket URL The Copy link / Open URL was the game's physical R2 path, games/<clerkUserId>/<threadId>/current/index.html — every shared link carried the owner's Clerk user id to whole classrooms. A new public /play/[threadId] route resolves the owner from the lessonplay_game_version index and streams current/index.html through, so the bucket layout (and the user id) stays server-side. The tRPC router now hands the UI a same-origin sharePath, the header builds the absolute URL from the page's own origin at copy time, and the agent's publishedUrl — what the model pastes into chat after a publish — points at /play too, derived from the request origin so dev and preview deploys hand out links on their own host. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Copy link / Open button in the chat header handed out the game's physical R2 location:
That path deliberately embeds the owner's Clerk user id (the bucket is public-by-key, so the random prefix is the access control) — which means every link a teacher shares with a classroom leaks their user id. The agent also pasted this same raw URL into chat after every publish.
Fix
Put a clean, public app route in front of the bucket. Share links are now:
The bucket layout is unchanged — the user id just never leaves the server.
Changes
src/app/play/[threadId]/route.ts(new) — public route: validates the thread id, resolves the owner from thelessonplay_game_versionindex (no bucket listing, no sandbox boot), fetchescurrent/index.htmlfrom R2 server-side, and streams it through. CDN-cached for 60s (s-maxage=60) so a class opening the link at once hits cache while a republish shows up within a minute;X-Robots-Tag: noindexkeeps share links out of search.src/server/db/games.ts— newlatestGameVersionByThread(threadId)read with no user filter, for the public route. The unguessable thread UUID is the capability, the same model the bucket already used, and the row is only used to locate the built game.src/middleware.ts—/play(.*)added to the public routes; students opening a share link hold no Clerk session.src/server/api/routers/games.ts—games.latestreturnssharePath: /play/<threadId>instead of the bucketshareUrl. A path rather than an absolute URL so localhost and preview deploys hand out links on their own origin.src/components/chat/chat-header.tsx— builds the absolute URL fromwindow.location.originat copy time; the Open button uses the relative path directly.src/app/api/chat/route.ts— the agent'spublishedUrl(what the model shares in chat afterpublish) is now the/playURL, derived from the request origin.The preview pane still uses the direct versioned bucket URLs — those render only inside the owner's authenticated session, so nothing leaks there.
Notes
/playform where it matters.pnpm typecheckandpnpm test(52 passed).🤖 Generated with Claude Code