Repository navigation
Sign upload URLs instead of putting the file token in them (GRYT-1549) - #724
Merged
Merged
Conversation
Upload URLs are signed per file with a key the server hands over after its identity proof, and the key is only held in memory. A refused server loses it. An older server's file token still works, but it's only read from disk once that server has proved itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
GRYT-1549, the desktop half.
getUploadsFileUrlput the file token in?t=. Those<img>loads can't wait for the identity proof (#708), and the token was good for every upload you can read, for 12 hours. The findings and the options are written up in Gryt-chat/server#251.What changes
common/src/utils/fileUrlAuth.tsholds each server's signing key in memory only and signs URLs with@noble/hashes(HMAC-SHA256).getUploadsFileUrlkeeps its signature, so no caller changed. It addsu,k,eandsin place oft.server:joined,token:refreshedand the newfile:key, which a restored session gets. All three come after the proof, because the socket holds every emit until then. Before that, a URL carries nothing and gets a 401.markRefusednow says whether the host counts as refused). A kick, removing a server, or signing out does too. An ordinary drop keeps it, since every reconnect gets a new key after its own proof.freshUploadsFileUrlin the download, Copy Image and avatar sync paths, and in the sidebar and profile settings, which keep your avatar's URL from the join. Attachments already re-sign on a load error throughuseStableFileUrl. Now it also signs a URL that was built before the key arrived.fileTokenstill works through?t=. That token is still kept on disk, but it's only read after that server proves itself (restoreServerFileTokenin the guard'srelease). As soon as a server sends a key, its stored token is deleted. Signing out now clearsfileToken_*too, which it never did.What changes behaviour
file:key.Checked
yarn lintand the comment check pass, and so does everyyarn test:*step in CI.scripts/check-signed-file-urls.mjs: the server's vector, nothing before any key, 5 to 10 minutes, one file each, stable within a step, the server's clock rather than ours, the?t=fallback, the stored token only afterrestoreServerFileToken, and sign-out.check-http-proof-gate.mjsnow runs the realfileUrlAuthandtokenStoragebehind the real guard. A refused server loses its key, and a drop alone doesn't. A stored old-server token isn't used before the proof, and never for a server that fails it. Mutation-checked: withoutforgetServerFileAccessinrefuse, or with the restore moved ahead of the proof, the check fails.check-stable-attachment-urls.mjs: an attachment built with nothing gets signed once the key arrives, and a later key refresh doesn't reload it.t=, no 401 and nofileToken_left in storage.Review-required: none. Nothing under
src/packages/common/src/auth/**changed.fileUrlAuth.tsdoes hold a signing key, so I.d read it anyway.The e2e job runs against
server:latest, which sends no key yet, so it covers the?t=fallback. Phone: Gryt-chat/mobile#281. Follow-up: GRYT-1586 drops the fallback.🤖 Generated with Claude Code