mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(apigateway): verify AWS_IAM signatures against the custom-domain path (#4092)
* fix(apigateway): verify AWS_IAM signatures against the custom-domain path The custom domain filter rewrites a request onto /execute-api/... before dispatch but, unlike the execute-api host filter, never recorded the path the caller actually signed. SigV4 verification then rebuilt the canonical request from the rewritten path, so every AWS_IAM method invoked through a custom domain was rejected with InvalidSignatureException. Record the original raw path on ApiGatewayExecuteRouteContext, matching ApiGatewayExecuteApiHostFilter, and give the filter an explicit ApplicationScoped scope so the request-scoped context injects through a client proxy. Covers both REST and HTTP API custom domains, since v2 API mappings are stored as base path mappings and routed by the same filter. * test(apigateway): cover AWS_IAM through an HTTP API custom domain A v2 API mapping is stored as a base path mapping and routed by the same custom domain filter as REST APIs, so the fix applies to HTTP APIs too. Prove it rather than assert it: a signed request through the domain reaches the integration, and unsigned, rewritten-path and other-path signatures are rejected with v2's flat 403 Forbidden.
This commit is contained in:
1 parent
7b29fdcf83
commit
c083aad12b
5 files changed
+515
-2
No files matched your search
+9
-1
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.RequestHost;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.BasePathMapping;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.CustomDomain;
|
||||
import jakarta.annotation.Priority;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
@@ -28,16 +29,20 @@ import java.net.URI;
|
||||
@Provider
|
||||
@PreMatching
|
||||
@Priority(10) // Run after Lambda URL filter (5) but before general processing
|
||||
@ApplicationScoped
|
||||
public class ApiGatewayCustomDomainFilter implements ContainerRequestFilter {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ApiGatewayCustomDomainFilter.class);
|
||||
private static final String REGIONAL_SUFFIX = ".regional.local";
|
||||
|
||||
private final ApiGatewayService apiGatewayService;
|
||||
private final ApiGatewayExecuteRouteContext routeContext;
|
||||
|
||||
@Inject
|
||||
public ApiGatewayCustomDomainFilter(ApiGatewayService apiGatewayService) {
|
||||
public ApiGatewayCustomDomainFilter(ApiGatewayService apiGatewayService,
|
||||
ApiGatewayExecuteRouteContext routeContext) {
|
||||
this.apiGatewayService = apiGatewayService;
|
||||
this.routeContext = routeContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +105,9 @@ public class ApiGatewayCustomDomainFilter implements ContainerRequestFilter {
|
||||
.build();
|
||||
|
||||
LOG.debugv("Custom domain routing: {0}{1} -> {2}", host, path, newUri.getPath());
|
||||
// AWS_IAM dispatch rebuilds the caller's canonical request, which covers the path they
|
||||
// signed: the custom-domain path, not the /execute-api/... form this rewrite produces.
|
||||
routeContext.recordSignedRequestPath(path);
|
||||
requestContext.setRequestUri(newUri);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user