fix(iam): refuse SNS requests with AuthorizationError (#6621)

Under IAM enforcement a refused SNS request answered `AccessDenied`, the
code Floci gives every Query service. SNS models no such error. Every
one of its 42 operations lists `AuthorizationError`, HTTP 403, a sender
fault ("Indicates that the user has been denied access to the requested
resource"), which SDKs raise as `AuthorizationErrorException`; the SNS
Developer Guide's own sample reads that code as an IAM permission
failure ("Authorization error listing topics - check IAM permissions").
An SDK caller catching `AuthorizationErrorException` therefore missed
Floci's refusal, which surfaced as a bare `SnsException`.

A Query denial now takes its code from the service that serves the
request: `AuthorizationError` for SNS, whichever action is denied (a
role it is passed as much as its own action), and `AccessDenied` for
every other Query service, as before. The status, the `Sender` type and
the message are unchanged.

Not in this change: Floci's SNS JSON surface (`SNS_20100331.*`
targets), which botocore does not model, keeps `AccessDeniedException`.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-26 19:16:56 -05:00
1 parent 0a47ddd5e4
commit 7c0ee92480
6 files changed
+86 -37

No files matched your search

@@ -1709,7 +1709,8 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
* <ul>
* <li>S3 → S3-flavored XML {@code <Error>...</Error>}</li>
* <li>{@code application/x-www-form-urlencoded} body → AWS Query
* {@code <ErrorResponse>...</ErrorResponse>} (IAM/STS/EC2/SQS/SNS/...)</li>
* {@code <ErrorResponse>...</ErrorResponse>} (IAM/STS/EC2/SQS/SNS/...), with the code
* {@link #queryAccessDeniedCode} gives the service that serves the request</li>
* <li>JSON 1.x: JSON with HTTP 400; REST-JSON: JSON with HTTP 403</li>
* <li>CBOR: the request's own encoding with HTTP 403, from {@link #accessDeniedForRequest},
* which has the request to read it from</li>
@@ -1750,12 +1751,22 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
return s3XmlAccessDenied(message, resourcePath);
}
if (protocol == WireProtocol.AWS_QUERY || isFormEncoded(requestMediaType)) {
return queryXmlAccessDenied(message);
return queryXmlError(queryAccessDeniedCode(credentialScope), message);
}
int status = protocol == WireProtocol.AWS_JSON_1_0 || protocol == WireProtocol.AWS_JSON_1_1 ? 400 : 403;
return jsonAccessDenied(message, status);
}
/**
* The code a Query service refuses a request it does not authorize with, whichever action was denied:
* SNS's {@code AuthorizationError}, a 403 every SNS operation lists ("Indicates that the user has been
* denied access to the requested resource") and the one SDKs raise as {@code AuthorizationErrorException},
* and {@code AccessDenied} for every other service.
*/
private static String queryAccessDeniedCode(String credentialScope) {
return "sns".equals(credentialScope) ? "AuthorizationError" : "AccessDenied";
}
private static String formatS3ResourcePath(String resourceArn) {
String tail = AwsArnUtils.resourceIfArnFor(resourceArn, "s3").orElse(null);
if (tail == null || tail.isEmpty() || "*".equals(tail)) {