Skip to content

fix(storage): keep colons in the first segment of object paths - #1985

Closed
hsusul wants to merge 2 commits into
supabase:v2from
hsusul:fix/storage-path-first-segment-colon
Closed

hsusul wants to merge 2 commits into
supabase:v2from
hsusul:fix/storage-path-first-segment-colon

Conversation

@hsusul

@hsusul hsusul commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #1984.

On v2, an object key whose first segment contains a colon, such as backup-2024-01-01T10:00:00.sql, is sent as 00:00.sql. relative_path_to_parts() parses the path with yarl.URL, and the leading backup-2024-01-01t10 is read as a URL scheme and dropped. upload(), update(), download(), info(), exists(), the signed URL methods and get_public_url() then use a different key. Two timestamped uploads with upsert overwrite each other, and a download returns the other file's bytes.

This is a critical fix because it causes silent data loss and returns the wrong data on normal use. A colon is valid in a URL path segment and in a Storage object key, and storage-js sends these keys unchanged.

The fix re-parses the path with a leading / when it parses with a scheme but no host. Full URLs, leading slashes, percent-decoding and ?/# behave as before.

Before (v2, 3276585), from the repro in #1984:

stored keys: ['00:00.sql']
download day one -> b'day two'

After:

stored keys: ['backup-2024-01-01T10:00:00.sql', 'backup-2024-01-02T10:00:00.sql']
download day one -> b'day one'

The regression test (tests/test_object_paths.py, sync and async) is in its own commit ahead of the fix. On v2 it fails 4 of 8 cases (00:00.sql and 42/avatar.png sent). With the fix, it passes.

Checks run locally from src/storage:

  • uv run --frozen --package storage3 pytest -o addopts="" tests/test_object_paths.py tests/test_upload_headers.py tests/test_utils.py tests/test_client.py gave 94 passed.
  • uv run --frozen --package storage3 --group mypy mypy src/storage3 tests reported no issues.
  • ruff check and ruff format --check passed.
  • make storage.build-sync regenerated _sync/file_api.py.

I did not run the infra-backed storage suite. The local Docker image store returned containerd I/O errors during make start-infra.

relative_path_to_parts() parsed the object path as a URL reference, so a
first segment containing a colon, such as backup-2024-01-01T10:00:00.sql,
was read as a URL scheme and dropped. upload(), download() and the other
path-based methods then used a different key than the one requested.
@hsusul
hsusul requested a review from spydon as a code owner November 5, 2026 07:33
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@spydon

spydon commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the bug report, since this PR doesn't solve the core issue it has been superseded by #1986

@spydon spydon closed this Nov 5, 2026
spydon added a commit that referenced this pull request Nov 5, 2026
Fixes #1984. Alternative to #1985.

## Problem

`relative_path_to_parts()` parsed every object key with `yarl.URL`. A
key is not a URL, so parts of it were read as URL syntax and dropped:

| Key                              | Sent as         |
| -------------------------------- | --------------- |
| `backup-2024-01-01T10:00:00.sql` | `00:00.sql`     |
| `user:42/avatar.png`             | `42/avatar.png` |
| `what?.txt`                      | `what`          |
| `report#1.pdf`                   | `report`        |
| `//folder/file.png`              | `file.png`      |

Every method that takes a path used the wrong key, so different keys
could overwrite each other and downloads could return another object's
bytes. This came in with #1249. Before that, the key was formatted into
the request path as a plain string.

## Fix

Split the key on `/` after stripping leading slashes, and percent-decode
each part as before. `joinpath()` already encodes each part when the
request URL is built, so `:` is kept and `?` and `#` are sent as `%3F`
and `%23`.

Percent-decoding is kept so that a pre-encoded key such as `a%20b.png`
still resolves to `a b.png`, as it did on earlier v2 releases. The only
input that behaves differently is a full URL passed as a key, such as
`https://host/a/b`, which used to be reduced to `a/b`.

## Tests

`tests/test_object_paths.py` checks the request path sent by `upload()`
and the URL returned by `get_public_url()` for both clients. Against the
old function, 15 of 33 cases fail.

From `src/storage`:

- `uv run --frozen --package storage3 pytest -o addopts=""
tests/test_object_paths.py tests/test_upload_headers.py
tests/test_utils.py tests/test_client.py`: 119 passed.
- `uv run --frozen --package storage3 --group mypy mypy src/storage3
tests`: no issues.
- `ruff format --check` and `ruff check`: passed.

The infra-backed storage suite was not run locally.
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.

2 participants