Repository navigation
fix(storage): stop parsing object keys as URLs - #1986
Merged
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
This was referenced Nov 5, 2026
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>
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.
Fixes #1984. Alternative to #1985.
Problem
relative_path_to_parts()parsed every object key withyarl.URL. A key is not a URL, so parts of it were read as URL syntax and dropped:backup-2024-01-01T10:00:00.sql00:00.sqluser:42/avatar.png42/avatar.pngwhat?.txtwhatreport#1.pdfreport//folder/file.pngfile.pngEvery 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%3Fand%23.Percent-decoding is kept so that a pre-encoded key such as
a%20b.pngstill resolves toa b.png, as it did on earlier v2 releases. The only input that behaves differently is a full URL passed as a key, such ashttps://host/a/b, which used to be reduced toa/b.Tests
tests/test_object_paths.pychecks the request path sent byupload()and the URL returned byget_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 --checkandruff check: passed.The infra-backed storage suite was not run locally.