mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(s3): unblock .well-known/* object keys hijacked by Cognito routes (#1003)
S3 object keys under .well-known/ (e.g. bucket/.well-known/jwks.json) were
being routed to CognitoWellKnownController instead of S3Controller. The
controller threw ResourceNotFoundException ("User pool not found"), masking
the S3 object even though list-objects-v2 and head-object returned it.
Real Cognito UserPool IDs always contain an underscore (region prefix +
underscore + random suffix, e.g. us-east-1_xxx); AWS S3 bucket names forbid
underscores. Constraining the {poolId} path parameter to "[^/_]+_[^/]+"
ensures that any first path segment without an underscore falls through to
S3Controller, restoring the documented S3 behaviour without affecting
existing Cognito tests.
Adds S3WellKnownKeyIntegrationTest covering both jwks.json and
openid-configuration object keys; verified failing on main and passing with
this fix.
This commit is contained in:
1 parent
27d72f119c
commit
71d00613db
2 files changed
+131
-2
No files matched your search
+12
-2
@@ -16,11 +16,21 @@ import java.util.Base64;
|
||||
* Exposes Cognito well-known endpoints.
|
||||
* The JWKS endpoint allows downstream services to verify JWTs issued by Floci Cognito pools.
|
||||
* Path mirrors real AWS: /{userPoolId}/.well-known/jwks.json
|
||||
*
|
||||
* <p>The {@code poolId} path parameter is constrained to {@link #POOL_ID_PATTERN}
|
||||
* so that S3 object keys like {@code /<bucket>/.well-known/jwks.json} do not
|
||||
* collide with this route. Real Cognito UserPool IDs always contain an
|
||||
* underscore (region prefix + {@code _} + random suffix, e.g.
|
||||
* {@code us-east-1_AbC123XyZ}), while AWS S3 bucket names forbid underscores
|
||||
* — using {@code _} as the discriminator routes S3 traffic correctly without
|
||||
* needing a wider request filter.
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class CognitoWellKnownController {
|
||||
|
||||
private static final String POOL_ID_PATTERN = "[^/_]+_[^/]+";
|
||||
|
||||
private final CognitoService cognitoService;
|
||||
|
||||
@Inject
|
||||
@@ -29,7 +39,7 @@ public class CognitoWellKnownController {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{poolId}/.well-known/jwks.json")
|
||||
@Path("/{poolId:" + POOL_ID_PATTERN + "}/.well-known/jwks.json")
|
||||
public Response getJwks(@PathParam("poolId") String poolId) {
|
||||
UserPool pool = cognitoService.describeUserPool(poolId);
|
||||
String kid = cognitoService.getSigningKeyId(pool);
|
||||
@@ -44,7 +54,7 @@ public class CognitoWellKnownController {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{poolId}/.well-known/openid-configuration")
|
||||
@Path("/{poolId:" + POOL_ID_PATTERN + "}/.well-known/openid-configuration")
|
||||
public Response getOpenIdConfiguration(@PathParam("poolId") String poolId) {
|
||||
UserPool pool = cognitoService.describeUserPool(poolId);
|
||||
String issuer = cognitoService.getIssuer(pool.getId());
|
||||
|
||||
Reference in new issue
Block a user