Skip to content

fix(storage): apply empty transform check to download and getPublicUrl - #2219

Merged
mandarini merged 3 commits into
supabase:masterfrom
oniani1:fix/storage-empty-transform-routing
Apr 15, 2026
Merged

mandarini merged 3 commits into
supabase:masterfrom
oniani1:fix/storage-empty-transform-routing

Conversation

@oniani1

@oniani1 oniani1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #2218

PR #2162 fixed createSignedUrl() to reject empty transform objects, but download() and getPublicUrl() still use the old typeof options?.transform !== 'undefined' check. Since typeof {} !== 'undefined' is true, passing an empty transform object routes requests through /render/image/ instead of /object/, causing 422 errors for non-image files.

This applies the same Object.keys check from createSignedUrl to both methods.

@oniani1
oniani1 requested review from a team as code owners April 5, 2026 20:31
@pkg-pr-new

pkg-pr-new Bot commented Apr 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2219

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2219

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2219

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2219

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2219

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2219

commit: f139868

@mandarini mandarini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @oniani1, thank you so much for contributing to Supabase! 💚

This is a clean, correct fix. The Object.keys guard is exactly the right pattern, and it's consistent with what was done in createSignedUrl in #2162. The diff is minimal and easy to verify.

One small thing before I can merge: could you add two tests alongside this fix, similar to the one added in #2162 for createSignedUrl? The existing test at line 124 of storageFileApi.test.ts is a good template -- we'd just need the same shape for download() and getPublicUrl(). Something like:

  • download() with empty transform object does not use render endpoint
  • getPublicUrl() with empty transform object does not use render endpoint

Once those are in, this is good to merge. Thanks again for the thorough write-up in the issue and for following through with the fix!

@mandarini mandarini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more change @oniani1 ! The getPublicUrl test looks great. The download test needs one small adjustment. Because the test uploads sadcat.jpg (a real JPEG), hitting /render/image/authenticated/ with an empty query string would still return the image successfully, so res.error being null does not actually prove the correct endpoint was used. Could you swap the uploaded file for the file.txt fixture that's already in the test fixtures? A non-image file will 422 if it accidentally routes through the render endpoint, making res.error === null a meaningful assertion:

it('download with empty transform object does not use render endpoint', async () => {
  const txtFile = await fsp.readFile(uploadFilePath('file.txt'))
  const txtPath = `testpath/file-${Date.now()}.txt`                                                                                                                                                                                                                    
  await storage.from(bucketName).upload(txtPath, txtFile)
                                                                                                                                                                                                                                                                       
  const res = await storage.from(bucketName).download(txtPath, {                                                                                                                                                                                                       
    transform: {},
  })                                                                                                                                                                                                                                                                   
                                                       
  expect(res.error).toBeNull()
  expect(res.data?.size).toBeGreaterThan(0)
})

Once that's updated, this is good to merge. Thanks for the quick turnaround!

Use file.txt instead of sadcat.jpg so a non-image file would 422 if
it accidentally routes through the render endpoint, making the
assertion meaningful.
@oniani1

oniani1 commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Hey @mandarini, the file.txt swap is in f139868 -- should be good to go now. Let me know if anything else needs changing!

@mandarini
mandarini merged commit 993bb5f into supabase:master Apr 15, 2026
21 checks passed
mandarini pushed a commit to supabase/supabase that referenced this pull request Apr 16, 2026
This PR updates @supabase/*-js libraries to version 2.103.2.

**Source**: supabase-js-stable-release

**Changes**:
- Updated @supabase/supabase-js to 2.103.2
- Updated @supabase/auth-js to 2.103.2
- Updated @supabase/realtime-js to 2.103.2
- Updated @supabase/postgest-js to 2.103.2
- Refreshed pnpm-lock.yaml

---

## Release Notes

## v2.103.2

## 2.103.2 (2026-04-15)

### 🩹 Fixes

- **auth:** include Cloudflare error codes in NETWORK_ERROR_CODES
([#2239](supabase/supabase-js#2239))
- **auth:** remove Prettify wrapper from exported types for TypeDoc
expansion ([#2250](supabase/supabase-js#2250))
- **misc:** add explicit return types to toJSON methods for JSR compat
([#2252](supabase/supabase-js#2252))
- **storage:** remove client-side signed URL render endpoint
normalization
([#2249](supabase/supabase-js#2249))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
- Vansh Sharma @Vansh1811
## v2.103.1

## 2.103.1 (2026-04-15)

### 🩹 Fixes

- **auth:** add toJSON to AuthError for correct JSON serialization
([#2238](supabase/supabase-js#2238))
- **postgrest:** handle bigint rpc
([#2245](supabase/supabase-js#2245))
- **storage:** add toJSON to StorageError for correct JSON serialization
([#2246](supabase/supabase-js#2246))
- **storage:** apply empty transform check to download and getPublicUrl
([#2219](supabase/supabase-js#2219))

### ❤️ Thank You

- oniani1
- Vaibhav @7ttp

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
spydon added a commit to supabase/supabase-flutter that referenced this pull request Jul 9, 2026
…dpoint (#1551)

## Summary

An empty or default `TransformOptions()` was routing `download()` and
`getPublicUrl()` through the `/render/image/` endpoint unnecessarily.
Previously the decision was based on `transform != null`, so any
`TransformOptions` instance, even one with all-null fields, switched to
the render path. Now routing only switches to the render endpoint when
the transform options actually produce query parameters.

**Outcome:** implemented (bug fix)

## Behavior

- `download(path)` without transform uses `/object/` endpoint
- `download(path, transform: TransformOptions())` with empty transform
uses `/object/` endpoint
- `download(path, transform: TransformOptions(width: 200))` uses
`/render/image/authenticated/` endpoint
- Same logic for `getPublicUrl()`

## Tests

Added unit tests in `packages/storage_client/test/basic_test.dart`
covering empty vs actual transform routing for both `download()` and
`getPublicUrl()`. All storage_client unit tests pass.

## Reference

- Linear: SDK-878
- supabase-js PR: supabase/supabase-js#2219
(commit `993bb5fc`)

## Compliance matrix

`storage.file_buckets.download_with_transform` and
`storage.file_buckets.get_public_url` remain `implemented`; this fix
brings their routing behavior in line with supabase-js, so no status
change was required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty transform object routes to wrong endpoint in download() and getPublicUrl()

2 participants