mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(appconfig): stop AppConfig route hijacking S3 bucket named "configuration" (#1317)
* fix(appconfig): stop AppConfig route hijacking S3 bucket named configuration
A path-style S3 request to a bucket named exactly "configuration" (e.g.
GET /configuration?list-type=2) matched AppConfigData's literal
GET /configuration route ahead of S3's /{bucket} template, so routine
list/read calls returned HTTP 500 (NullPointerException on a null
configuration_token).
Move AppConfigData GetLatestConfiguration to an internal path and add a
@PreMatching AppConfigConfigurationRouteFilter that rewrites genuine
requests (those carrying a configuration_token) onto it. Requests without
a token keep the bare /configuration path and fall through to S3's
/{bucket} route. This mirrors the existing SqsQueueUrlRouterFilter and
LambdaUrlRoutingFilter path-rewrite pattern and avoids one controller
depending on another.
Closes #1294
* fix(appconfig): drop unreachable configuration_token guard
The route is bound to the internal path and the @PreMatching filter only
rewrites onto it when a configuration_token is present, so the guard could
never fire. Remove it and the now-unused AwsException import.
This commit is contained in:
1 parent
8ba258c37a
commit
c9e4f931b7
3 files changed
+152
-1
No files matched your search
+57
@@ -0,0 +1,57 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.container.PreMatching;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* Pre-matching filter that disambiguates {@code GET /configuration} between the
|
||||
* AppConfigData runtime API (GetLatestConfiguration) and an S3 bucket literally
|
||||
* named {@code configuration} (issue #1294).
|
||||
*
|
||||
* <p>A genuine AppConfigData GetLatestConfiguration request always carries a
|
||||
* {@code configuration_token} query parameter, while a path-style S3
|
||||
* ListObjectsV2 request does not. When the token is present the request is
|
||||
* rewritten onto the internal AppConfigData path so {@link AppConfigDataController}
|
||||
* handles it; otherwise the bare {@code /configuration} path is left untouched
|
||||
* and falls through to S3's {@code /{bucket}} route.
|
||||
*
|
||||
* <p>The internal path contains an underscore, which S3 bucket names forbid, so
|
||||
* it can never collide with a real bucket. This mirrors the existing routing
|
||||
* filters ({@code SqsQueueUrlRouterFilter}, {@code LambdaUrlRoutingFilter}) that
|
||||
* resolve path collisions before JAX-RS resource matching.
|
||||
*/
|
||||
@Provider
|
||||
@PreMatching
|
||||
public class AppConfigConfigurationRouteFilter implements ContainerRequestFilter {
|
||||
|
||||
/** Internal-only path that {@link AppConfigDataController} binds for GetLatestConfiguration. */
|
||||
static final String INTERNAL_PATH = "/_appconfigdata_configuration";
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext ctx) {
|
||||
if (!"GET".equals(ctx.getMethod())) {
|
||||
return;
|
||||
}
|
||||
UriInfo uriInfo = ctx.getUriInfo();
|
||||
String path = uriInfo.getPath();
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
if (!"configuration".equals(path)) {
|
||||
return;
|
||||
}
|
||||
String token = uriInfo.getQueryParameters().getFirst("configuration_token");
|
||||
if (token == null || token.isBlank()) {
|
||||
// No token: this is an S3 path-style request to a bucket named
|
||||
// "configuration". Leave the path so it matches S3's /{bucket} route.
|
||||
return;
|
||||
}
|
||||
URI rewritten = uriInfo.getRequestUriBuilder().replacePath(INTERNAL_PATH).build();
|
||||
ctx.setRequestUri(rewritten);
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -35,8 +35,13 @@ public class AppConfigDataController {
|
||||
return Response.status(201).entity(Map.of("InitialConfigurationToken", token)).build();
|
||||
}
|
||||
|
||||
// Bound to an internal path rather than the public "/configuration" so that
|
||||
// an S3 bucket named "configuration" is not shadowed by this route (issue
|
||||
// #1294). AppConfigConfigurationRouteFilter rewrites genuine GetLatestConfiguration
|
||||
// requests (those carrying a configuration_token) onto this path; requests
|
||||
// without a token fall through to S3's /{bucket} handler.
|
||||
@GET
|
||||
@Path("/configuration")
|
||||
@Path(AppConfigConfigurationRouteFilter.INTERNAL_PATH)
|
||||
public Response getLatestConfiguration(@QueryParam("configuration_token") String token) {
|
||||
ConfigurationData data = service.getLatestConfiguration(token);
|
||||
return Response.ok(data.content())
|
||||
|
||||
Reference in new issue
Block a user