fix(s3): keep a percent sign in a virtual-hosted object key (#6000)

* fix(s3): keep a percent sign in a virtual-hosted object key

A virtual-hosted request for a key such as a%/b failed with 400 or 500.
The same request in path style worked. S3 stores the key as sent in
both styles.

RESTEasy keeps the decoded path of a rewritten request URI and later
decodes it again. S3VirtualHostFilter now escapes the raw path once more,
so routing sees the same path as a path-style request. The request URI
then decodes to /<bucket> plus the raw path, so the virtual-hosted key
check compares against the decoded path.

Fixes #5997

* test(s3): keep only the percent-key cases that guard the fix
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-19 10:57:03 -04:00
1 parent ca47df9ec5
commit 2bb69a030b
6 files changed
+57 -10

No files matched your search

@@ -473,4 +473,33 @@ class S3VirtualHostIntegrationTest {
.then()
.statusCode(404);
}
@Test
@Order(91)
void keyWithPercentSignIsStoredLiterally() {
String percentBucket = "vhost-percent-key";
String percentHost = percentBucket + ".localhost";
given().header("Host", percentHost).when().put("/").then().statusCode(200);
for (String wirePath : new String[] {"/a%25/b", "/archive/" + percentBucket + "/a%25b"}) {
given()
.urlEncodingEnabled(false)
.header("Host", percentHost)
.contentType("text/plain")
.body("x")
.when()
.put(wirePath)
.then()
.statusCode(200);
}
given()
.header("Host", percentHost)
.queryParam("list-type", "2")
.when()
.get("/")
.then()
.statusCode(200)
.body("ListBucketResult.Contents.Key", containsInAnyOrder("a%/b", "archive/" + percentBucket + "/a%b"));
}
}