fix(storage): avoid double-encoding download filename in signed URLs#2468
Open
i-anubhav-anand wants to merge 1 commit into
Open
fix(storage): avoid double-encoding download filename in signed URLs#2468i-anubhav-anand wants to merge 1 commit into
i-anubhav-anand wants to merge 1 commit into
Conversation
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.
🔍 Description
What changed?
createSignedUrlandcreateSignedUrlsbuild thedownload/cacheNoncequery withURLSearchParams(which already percent-encodes), then wrapped the entire URL — including that query — inencodeURI(...).encodeURIdoes not skip an existing%, so every%XXproduced byURLSearchParamswas re-encoded to%25XX, double-encoding thedownloadfilename.This PR
encodeURIs only the path/token portion and appends the already-encoded query string raw — matching the correct sibling methodsgetPublicUrlanddownload.(and the analogous change in
createSignedUrls).Why was this change needed?
The double-encoding corrupts any
downloadfilename containing characters thatURLSearchParamspercent-encodes —&, non-ASCII,+,#,,, etc.downloadvaluea&b.pngdownload=a%2526b.pnga%26b.png❌download=a%26b.pnga&b.png✅The storage server route
src/http/routes/object/getSignedObject.tsURL-decodes thedownloadquery value once (Fastify) and uses it verbatim as theContent-Dispositionfilename, so the client must send exactly one encoding layer — whichURLSearchParamsalready provides. The siblinggetPublicUrl(anddownload) already do this correctly;createSignedUrl/createSignedUrlswere the inconsistent ones.🔄 Breaking changes
📋 Checklist
pnpm nx format📝 Additional notes
Fail-before / pass-after — added
signed-url-download-encoding.test.ts(Docker-free, custom-fetch capture) covering both signed-url methods, plus a contrast assertion thatgetPublicUrlalready single-encodes the same filename:Expected substring "download=a%26b.png", Received "...&download=a%2526b.png"(bothcreateSignedUrlandcreateSignedUrls)