Repository navigation
Conversation
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.
|
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
|
Contributor
|
Thanks for the bug report, since this PR doesn't solve the core issue it has been superseded by #1986 |
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.
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.
On v2, an object key whose first segment contains a colon, such as
backup-2024-01-01T10:00:00.sql, is sent as00:00.sql.relative_path_to_parts()parses the path withyarl.URL, and the leadingbackup-2024-01-01t10is read as a URL scheme and dropped.upload(),update(),download(),info(),exists(), the signed URL methods andget_public_url()then use a different key. Two timestamped uploads withupsertoverwrite 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:
After:
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.sqland42/avatar.pngsent). 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.pygave 94 passed.uv run --frozen --package storage3 --group mypy mypy src/storage3 testsreported no issues.ruff checkandruff format --checkpassed.make storage.build-syncregenerated_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.