fix(s3): allow presigned CORS preflight (#3675)

Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
XuJianandxujiantop-crypto authored and GitHub committed 2026-09-15 13:51:44 -04:00
1 parent 2f2a9bed0d
commit 0962adaf23
2 files changed
+121

No files matched your search

@@ -44,6 +44,13 @@ public class PreSignedUrlFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
// A browser preflight reuses the target request's presigned URL, so its OPTIONS method
// must not be verified against a signature created for the follow-up PUT/GET request.
// The dedicated S3 OPTIONS resource performs the bucket CORS evaluation instead.
if (isCorsPreflight(requestContext)) {
return;
}
var queryParams = requestContext.getUriInfo().getQueryParameters();
// Only process if this is a pre-signed URL request
@@ -144,6 +151,16 @@ public class PreSignedUrlFilter implements ContainerRequestFilter {
}
}
private static boolean isCorsPreflight(ContainerRequestContext requestContext) {
return "OPTIONS".equalsIgnoreCase(requestContext.getMethod())
&& hasText(requestContext.getHeaderString("Origin"))
&& hasText(requestContext.getHeaderString("Access-Control-Request-Method"));
}
private static boolean hasText(String value) {
return value != null && !value.isBlank();
}
private boolean verifySigV4Signature(ContainerRequestContext requestContext,
String signature, String secretKey) {
try {