Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(s3): handle absolute-form request targets in _parse_bucket_key (#624)
Mark Braycbebf495ff02
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be2b4551..9b040888 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,11 @@ Versioning follows [Semantic Versioning](https://semver.org/).---+## [Unreleased]++### Fixed+- **S3 `_parse_bucket_key` absolute-form request targets** — AWS SDK for .NET v4 sends HTTP/1.1 requests with absolute-form targets (e.g. `PUT http://ministack:4566/bucket/key`). hypercorn passes the raw target as `scope["path"]`, causing `_parse_bucket_key` to parse `http:` as the bucket name. The function now strips the scheme and authority before parsing, matching the behaviour of LocalStack.+## [1.3.36] — 2026-05-11### Addeddiff --git a/ministack/services/s3.py b/ministack/services/s3.pyindex 4b21e4e7..3b9c1212 100644--- a/ministack/services/s3.py+++ b/ministack/services/s3.py@@ -35,6 +35,7 @@ import timefrom urllib.parse import parse_qs as _parse_qsfrom urllib.parse import quote as url_quotefrom urllib.parse import unquote as url_unquote+from urllib.parse import urlparse as _urlparsefrom xml.etree.ElementTree import Element, SubElement, tostringfrom xml.sax.saxutils import escape as _esc@@ -262,6 +263,8 @@ def _parse_bucket_key(path: str, headers: dict):# Vhost extraction lives in app.py:_extract_s3_vhost_bucket, which# rewrites the path to /{bucket}{key} before this handler runs. By the# time we get here, every request is path-style.+ if path.startswith(("http://", "https://")):+ path = _urlparse(path).pathparts = path.lstrip("/").split("/", 1)bucket = parts[0] if parts else ""key = parts[1] if len(parts) > 1 else ""diff --git a/tests/test_s3.py b/tests/test_s3.pyindex 3bb0be6c..a1178c13 100644--- a/tests/test_s3.py+++ b/tests/test_s3.py@@ -504,6 +504,27 @@ class TestS3VhostGetPutObject:assert resp["Body"].read() == b"vhost content"+class TestParseAbsoluteFormRequestTarget:+ """_parse_bucket_key must strip scheme+authority when hypercorn passes an+ absolute-form request target (e.g. AWS SDK for .NET v4 over HTTP/1.1)."""++ def _parse(self, path):+ from ministack.services.s3 import _parse_bucket_key+ return _parse_bucket_key(path, {})++ def test_http_absolute_form(self):+ assert self._parse("http://ministack:4566/mybucket/mykey") == ("mybucket", "mykey")++ def test_https_absolute_form(self):+ assert self._parse("https://ministack:4566/mybucket/mykey") == ("mybucket", "mykey")++ def test_absolute_form_bucket_only(self):+ assert self._parse("http://ministack:4566/mybucket") == ("mybucket", "")++ def test_path_style_unaffected(self):+ assert self._parse("/mybucket/mykey") == ("mybucket", "mykey")++def test_s3_bucket_policy(s3):bkt = "intg-s3-policy"s3.create_bucket(Bucket=bkt)