Skip to content

fix(storage): stop parsing object keys as URLs - #1986

Merged
spydon merged 1 commit into
v2from
fix/storage-object-key-parsing
Nov 5, 2026
Merged

spydon merged 1 commit into
v2from
fix/storage-object-key-parsing

Conversation

@spydon

@spydon spydon commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

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.

@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 merged commit 49de162 into v2 Nov 5, 2026
38 checks passed
@spydon
spydon deleted the fix/storage-object-key-parsing branch November 5, 2026 09:17
spydon added a commit that referenced this pull request Nov 5, 2026
Fixes #1984 on `main`. The `v2` fix is #1986, with the follow-up #1988.

## 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.

## Fix

An object key is now treated as a literal string. It is split on `/`
after stripping leading slashes, and `joinpath()` encodes each part when
the request URL is built. `:` is kept, and `?`, `#` and `%` are sent as
`%3F`, `%23` and `%25`.

A key with a `.` or `..` segment raises `ValueError`. Dot segments are
removed while a URL path is built or sent: by `joinpath()`, by httpx,
and by the WHATWG URL parser that storage-js uses. So
`folder?/../report.txt` would target `report.txt`, and `../../auth`
would leave the storage path entirely. Such keys cannot be addressed
reliably over HTTP, so they are rejected instead of being sent to a
different key.

## Breaking change

Keys are no longer percent-decoded. A pre-encoded key such as
`a%20b.png` used to be sent as `a b.png`. It is now sent as the literal
`a%20b.png`, which Storage should reject because `%` is not a valid key
character. Pass the decoded key, `a b.png`, instead.

A full URL passed as a key, such as `https://host/a/b`, is no longer
reduced to `a/b`.

## Tests

`tests/test_file_api.py` checks the request path sent by `upload()` for
both clients and the URL returned by `get_public_url()`, and that dot
segments raise in both. Against the original function, 24 of the 39 key
cases fail.

From `src/storage`:

- `uv run --frozen --package storage3 pytest -o addopts=""
tests/test_file_api.py tests/test_exceptions.py tests/test_analytics.py
tests/test_optional_iceberg.py tests/test_vector_index.py
tests/test_vector_metadata.py`: 91 passed.
- `uv run --frozen --package storage3 --group typecheck pyrefly check`:
0 errors.
- `ruff format` and `ruff check`: passed.

The infra-backed storage suite was not run locally.
spydon added a commit that referenced this pull request Nov 5, 2026
…1988)

Follow-up to #1986. The same change for `main` is in #1987.

## Problem

#1986 percent-decodes each segment of an object key with
`urllib.parse.unquote()`. Its default `errors="replace"` turns an
invalid UTF-8 escape into U+FFFD, so `report%FF.txt` and `report%FE.txt`
both become `report�.txt`. Two different names are then sent as the same
key, and with `upsert` one upload can overwrite the other object. The
`yarl` parsing used before #1986 kept such escapes as they were, so this
collision is new in #1986.

A segment that decodes to `.` or `..` is also a problem. `joinpath()`
normalizes dot segments, so `folder?/../report.txt` targets
`report.txt`, and `../../auth` leaves the storage path entirely. The
`yarl` parsing before #1986 normalized `folder/../report.txt` the same
way, and #1986 now keeps keys such as `folder?/../report.txt` intact
past the `?`, so they reach the same normalization.

## Fix

Decode the whole key before splitting it on `/`, so the parts match the
segments `joinpath()` actually sends, including ones behind an encoded
slash such as `..%2Freport.txt`. Raise `ValueError` for any segment that
is `.` or `..`, including escaped ones like `%2E%2E`. Decode with
`errors="strict"`. A key with an invalid escape now raises
`UnicodeDecodeError` before any request is sent. Valid escapes such as
`a%20b.png` decode as before.

## Tests

`tests/test_object_paths.py` checks that uploads with an invalid escape
or a dot segment raise for both clients, and that `get_public_url()`
rejects dot segments.

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`: 142 passed.
- `uv run --frozen --package storage3 --group mypy mypy src/storage3
tests`: no issues.
- `ruff format` and `ruff check`: passed.
spydon pushed a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.34.1](v2.34.0...v2.34.1)
(2026-11-05)


### Bug Fixes

* **storage:** reject invalid escapes and dot segments in object keys
([#1988](#1988))
([a308cde](a308cde))
* **storage:** stop parsing object keys as URLs
([#1986](#1986))
([49de162](49de162))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-py-releaser[bot] <254608689+supabase-py-releaser[bot]@users.noreply.github.com>
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.

1 participant