fix(iam): read a REST request's path and query members under a form too (#7527)

A member the table locates in a REST request's path or query was laid
over a JSON body alone: a request sending a form skipped the overlay,
so a form's DomainName was read in place of the path's. OpenSearch
answers a form with 415, so no such request reaches its handlers
today, but the next REST namespace the table reads whose handler does
not refuse a form would be checked on the form's name while it acts on
the path's.

RequestResources now lays the located members over a form as it lays
them over a JSON body, for the resources a request names and for those
it creates: each is dropped from the form and read from the path or
the query alone.

RequestResourceMembersTest checks every resource of the table from a
form as from a JSON body, each located member given in the path or the
query and another value in the body and in the form; RequestResourcesTest
sends OpenSearch requests as forms naming another domain than the path
or the query does. iam.md says so.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-04 17:09:37 -06:00
1 parent c149ef7166
commit 26cd74e6f8
4 files changed
+95 -28

No files matched your search

@@ -283,7 +283,7 @@ class RequestResourceMembersTest {
* always names, such as a create's new resource (Cloud Map's {@code CreateService}), and those filled from the ARN
* it is read from (a permission set made in an instance); one named through another resource of its service's
* own, the ARN its service gives for that. A member the table locates in a REST request's path or query is given
* there, a body giving it naming nothing, and such a request is not checked as a form.
* there, and a body or a form giving it another value names nothing.
*/
@TestFactory
Stream<DynamicTest> everyResourceOfTheTableIsReadFromAJsonBodyAndAForm() {
@@ -313,20 +313,20 @@ class RequestResourceMembersTest {
}
});
// A member the table locates in a REST request's path or query goes there, where the reader takes it
// from; a REST request has no form, so the form is checked for an operation locating none.
// from, and the body and the form give it another value, which names nothing.
Map<String, String> located = table.located().getOrDefault(operation.getKey(), Map.of());
Map<String, String> labels = new LinkedHashMap<>();
MultivaluedMap<String, String> query = new MultivaluedHashMap<>();
given.forEach((member, value) -> {
String where = member.field() == null && !member.list() ? located.get(member.name()) : null;
if (where == null) {
put(body, member, value);
} else if (where.startsWith("{")) {
if (where != null && where.startsWith("{")) {
labels.put(where.substring(1, where.length() - 1), value);
} else {
} else if (where != null) {
query.add(where.substring(1), value);
}
form.append('&').append(parameter(member)).append('=').append(encoded(value));
String sent = where == null ? value : "other";
put(body, member, sent);
form.append('&').append(parameter(member)).append('=').append(encoded(sent));
});
List<String> named = operation.getValue().stream()
.filter(other -> (other == resource || named(other) || fillsFromTheArn(other, resource)
@@ -339,17 +339,12 @@ class RequestResourceMembersTest {
"000000000000"))
.distinct().toList();
StoredResourceArns stored = runningOn(namespace, arn);
ContainerRequestContext request = servedBy(json(body.toString()), resource.endpoint());
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getQueryParameters()).thenReturn(query);
when(request.getUriInfo()).thenReturn(uriInfo);
assertEquals(named, RequestResources.of(operation.getKey(), request, "aws", "us-east-1",
assertEquals(named, RequestResources.of(operation.getKey(),
sentWith(servedBy(json(body.toString()), resource.endpoint()), query), "aws", "us-east-1",
"000000000000", stored, labels), body + " " + labels + " " + query);
if (given.keySet().stream().noneMatch(member -> located.containsKey(member.name()))) {
assertEquals(named, RequestResources.of(operation.getKey(),
servedBy(form(form.toString()), resource.endpoint()), "aws", "us-east-1",
"000000000000", stored), form.toString());
}
assertEquals(named, RequestResources.of(operation.getKey(),
sentWith(servedBy(form(form.toString()), resource.endpoint()), query), "aws", "us-east-1",
"000000000000", stored, labels), form + " " + labels + " " + query);
})));
}
@@ -490,6 +485,15 @@ class RequestResourceMembersTest {
return request;
}
/** The request with the query it is sent with. */
private static ContainerRequestContext sentWith(ContainerRequestContext request,
MultivaluedMap<String, String> query) {
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getQueryParameters()).thenReturn(query);
when(request.getUriInfo()).thenReturn(uriInfo);
return request;
}
private static ContainerRequestContext json(String body) {
return request("application/x-amz-json-1.1", body);
}
@@ -860,9 +860,39 @@ class RequestResourcesTest {
Map.of("DomainName", "logs")));
}
/**
* A REST request sent as a form, which a handler that does not refuse one still routes by its path, has the members
* the table locates read from its path and its query, as a JSON body has: {@code UpdateDomainConfig} names the
* domain its path gives, not the form's, and with no label given names nothing, a form giving nothing else naming
* nothing either; {@code GetCompatibleVersions} and {@code ListTags} name the one their query gives, not the form's.
*/
@Test
void aRestRequestSentAsAFormIsReadWhereTheTableLocatesItsMembers() {
String domain = "arn:aws:es:us-east-1:111111111111:domain/logs";
String form = "application/x-www-form-urlencoded";
assertEquals(List.of(domain), RequestResources.of("es:UpdateDomainConfig",
rest("POST", form, "DomainName=other&EngineVersion=OpenSearch_2.11", Map.of()), "aws", "us-east-1",
"111111111111", null, Map.of("DomainName", "logs")));
assertEquals(List.of(), RequestResources.of("es:UpdateDomainConfig",
rest("POST", form, "DomainName=other&EngineVersion=OpenSearch_2.11", Map.of()), "aws", "us-east-1",
"111111111111", null, Map.of()));
assertEquals(List.of(), RequestResources.of("es:UpdateDomainConfig", rest("POST", form, "DomainName=other",
Map.of()), "aws", "us-east-1", "111111111111", null, Map.of()));
assertEquals(List.of(domain), RequestResources.of("es:GetCompatibleVersions",
rest("POST", form, "DomainName=other", Map.of("domainName", "logs")), "aws", "us-east-1",
"111111111111", null, Map.of()));
assertEquals(List.of(domain), RequestResources.of("es:ListTags",
rest("POST", form, "ARN=arn:aws:es:us-east-1:111111111111:domain/other", Map.of("arn", domain)),
"aws", "us-east-1", "111111111111", null, Map.of()));
}
private static ContainerRequestContext rest(String method, String body, Map<String, String> query) {
ContainerRequestContext request = body == null ? mock(ContainerRequestContext.class)
: request("application/json", body);
return rest(method, "application/json", body, query);
}
private static ContainerRequestContext rest(String method, String mediaType, String body,
Map<String, String> query) {
ContainerRequestContext request = body == null ? mock(ContainerRequestContext.class) : request(mediaType, body);
when(request.getMethod()).thenReturn(method);
UriInfo uriInfo = mock(UriInfo.class);
MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();