mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(s3): preserve leading slashes in object keys to prevent key colli… (#286)
* fix(s3): preserve leading slashes in object keys to prevent key collision AWS S3 treats keys with leading slashes (e.g., /file.txt) as distinct from keys without (e.g., file.txt). Floci was incorrectly collapsing these because Vert.x/JAX-RS normalizes consecutive slashes in the URL path before @PathParam extraction. This fix uses the raw Vert.x HttpServerRequest.uri() to extract the object key, preserving any leading slashes. The fix is applied to all six object endpoints: putObject, getObject, headObject, deleteObject, handleMultipartPost. Closes #282 * test(s3): clean up test documentation and remove requirement references - Remove requirement validation references from test class documentation - Remove requirement validation comments from individual test methods - Simplify test documentation to focus on behavior verification rather than requirements tracing - Maintain clarity on test purpose and expected outcomes for leading-slash key collision and normal key preservation tests * test(s3): remove redundant leading slash preservation test - Delete S3VirtualHostFilterLeadingSlashTest.java as test coverage is now consolidated in main S3VirtualHostFilter test suite - Reduce test duplication following leading slash fix implementation - Simplify test maintenance by removing isolated test class
This commit is contained in:
1 parent
1fa7ae7551
commit
c7d5c554ec
3 files changed
+598
-2
No files matched your search
@@ -64,13 +64,16 @@ public class S3Controller {
|
||||
private final S3Service s3Service;
|
||||
private final S3SelectService s3SelectService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final io.quarkus.vertx.http.runtime.CurrentVertxRequest currentVertxRequest;
|
||||
|
||||
@Inject
|
||||
public S3Controller(S3Service s3Service, S3SelectService s3SelectService,
|
||||
RegionResolver regionResolver) {
|
||||
RegionResolver regionResolver,
|
||||
io.quarkus.vertx.http.runtime.CurrentVertxRequest currentVertxRequest) {
|
||||
this.s3Service = s3Service;
|
||||
this.s3SelectService = s3SelectService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.currentVertxRequest = currentVertxRequest;
|
||||
}
|
||||
|
||||
// --- Bucket operations ---
|
||||
@@ -353,6 +356,8 @@ public class S3Controller {
|
||||
@Context HttpHeaders httpHeaders,
|
||||
byte[] body) {
|
||||
try {
|
||||
key = extractObjectKey(uriInfo, bucket);
|
||||
|
||||
if (hasQueryParam(uriInfo, "tagging")) {
|
||||
return handlePutObjectTagging(bucket, key, body);
|
||||
}
|
||||
@@ -428,6 +433,8 @@ public class S3Controller {
|
||||
@Context UriInfo uriInfo,
|
||||
@Context HttpHeaders httpHeaders) {
|
||||
try {
|
||||
key = extractObjectKey(uriInfo, bucket);
|
||||
|
||||
if (uploadId != null) {
|
||||
return handleListParts(bucket, key, uploadId, maxPartsQuery, partNumberMarkerQuery);
|
||||
}
|
||||
@@ -551,8 +558,10 @@ public class S3Controller {
|
||||
@HeaderParam("If-Match") String ifMatch,
|
||||
@HeaderParam("If-None-Match") String ifNoneMatch,
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@HeaderParam("If-Unmodified-Since") String ifUnmodifiedSince) {
|
||||
@HeaderParam("If-Unmodified-Since") String ifUnmodifiedSince,
|
||||
@Context UriInfo uriInfo) {
|
||||
try {
|
||||
key = extractObjectKey(uriInfo, bucket);
|
||||
S3Object obj = s3Service.headObject(bucket, key, versionId);
|
||||
Response preconditionResponse = checkPreconditions(obj, ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince);
|
||||
if (preconditionResponse != null) {
|
||||
@@ -655,6 +664,8 @@ public class S3Controller {
|
||||
@Context UriInfo uriInfo,
|
||||
@Context HttpHeaders httpHeaders) {
|
||||
try {
|
||||
key = extractObjectKey(uriInfo, bucket);
|
||||
|
||||
if (hasQueryParam(uriInfo, "tagging")) {
|
||||
s3Service.deleteObjectTagging(bucket, key);
|
||||
return Response.noContent().build();
|
||||
@@ -712,6 +723,8 @@ public class S3Controller {
|
||||
@Context UriInfo uriInfo,
|
||||
byte[] body) {
|
||||
try {
|
||||
key = extractObjectKey(uriInfo, bucket);
|
||||
|
||||
if (hasQueryParam(uriInfo, "uploads")) {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(bucket, key, contentType,
|
||||
extractUserMetadata(httpHeaders), httpHeaders.getHeaderString("x-amz-storage-class"));
|
||||
@@ -1890,4 +1903,22 @@ public class S3Controller {
|
||||
if (query == null) return false;
|
||||
return query.equals(param) || query.contains(param + "&") || query.contains("&" + param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the object key from the raw Vert.x request URI, preserving leading slashes
|
||||
* that JAX-RS path normalization would otherwise strip.
|
||||
*/
|
||||
private String extractObjectKey(UriInfo uriInfo, String bucket) {
|
||||
String rawUri = currentVertxRequest.getCurrent().request().uri();
|
||||
int qIdx = rawUri.indexOf('?');
|
||||
String rawPath = qIdx >= 0 ? rawUri.substring(0, qIdx) : rawUri;
|
||||
String bucketPrefix = "/" + bucket + "/";
|
||||
int prefixIndex = rawPath.indexOf(bucketPrefix);
|
||||
if (prefixIndex < 0) {
|
||||
// Should not happen — route already matched /{bucket}/{key:.+}
|
||||
return uriInfo.getPathParameters().getFirst("key");
|
||||
}
|
||||
String rawKey = rawPath.substring(prefixIndex + bucketPrefix.length());
|
||||
return URLDecoder.decode(rawKey, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user