From aec85f993a6768c151c799e9e00327cad3daff1e Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 19 May 2026 02:55:15 +0100 Subject: [PATCH] fix(sqs): skip JSON null tag/attribute values instead of storing literal "null" (#905) * fix(sqs): skip JSON null values in TagQueue tags and attribute maps JsonNode.asText() returns the literal string "null" for explicit JSON null values. This caused TagQueue with {"Tags":{"NullTag":null}} to store the four-character string "null" as the tag value, surfacing on the wire as null when read back via ListQueueTags. Same path is used for CreateQueue / SetQueueAttributes attribute maps, where a null-valued attribute would have stored the same literal. Skip null/missing JsonNode values in jsonNodeToMap so the absent key round-trips as absent rather than as the string "null". * fix(sqs): reject JSON null tag/attribute values with InvalidParameterValue Match real AWS behavior: return HTTP 400 InvalidParameterValue with 'the parameter "value" may not be null' when a JSON 1.0 TagQueue, CreateQueue, or SetQueueAttributes request contains a null map value, rather than silently skipping the entry. Adds regression coverage for TagQueue, CreateQueue (tags + attributes), and SetQueueAttributes. --- .../floci/services/sqs/SqsJsonHandler.java | 9 +- .../services/sqs/SqsJsonProtocolTest.java | 85 +++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java index 1a127929bf..4c9c2469b5 100644 --- a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsJsonHandler.java @@ -516,7 +516,14 @@ public class SqsJsonHandler { private Map jsonNodeToMap(JsonNode node) { Map map = new HashMap<>(); if (node != null && node.isObject()) { - node.fields().forEachRemaining(entry -> map.put(entry.getKey(), entry.getValue().asText())); + node.fields().forEachRemaining(entry -> { + JsonNode value = entry.getValue(); + if (value == null || value.isNull() || value.isMissingNode()) { + throw new AwsException("InvalidParameterValue", + "the parameter 'value' may not be null", 400); + } + map.put(entry.getKey(), value.asText()); + }); } return map; } diff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java index 526e498e5f..4e895f7cc4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsJsonProtocolTest.java @@ -289,6 +289,91 @@ class SqsJsonProtocolTest { .body("Messages[0].Attributes.ApproximateFirstReceiveTimestamp", notNullValue()); } + @Test + @Order(7) + void tagQueueWithJsonNullValueIsRejected() { + String tagBody = "{\"QueueUrl\":\"" + queueUrl + "\"," + + "\"Tags\":{\"NullTag\":null,\"RealTag\":\"value\"}}"; + + given() + .contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AmazonSQS.TagQueue") + .body(tagBody) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("InvalidParameterValue")) + .body("message", equalTo("the parameter 'value' may not be null")); + + String listBody = "{\"QueueUrl\":\"" + queueUrl + "\"}"; + + given() + .contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AmazonSQS.ListQueueTags") + .body(listBody) + .when() + .post("/") + .then() + .statusCode(200) + .body("Tags.NullTag", nullValue()) + .body("Tags.RealTag", nullValue()); + } + + @Test + @Order(7) + void createQueueWithJsonNullTagValueIsRejected() { + String body = "{\"QueueName\":\"" + QUEUE_NAME + "-null-tag\"," + + "\"tags\":{\"NullTag\":null}}"; + + given() + .contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AmazonSQS.CreateQueue") + .body(body) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("InvalidParameterValue")) + .body("message", equalTo("the parameter 'value' may not be null")); + } + + @Test + @Order(7) + void createQueueWithJsonNullAttributeValueIsRejected() { + String body = "{\"QueueName\":\"" + QUEUE_NAME + "-null-attr\"," + + "\"Attributes\":{\"DelaySeconds\":null}}"; + + given() + .contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AmazonSQS.CreateQueue") + .body(body) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("InvalidParameterValue")) + .body("message", equalTo("the parameter 'value' may not be null")); + } + + @Test + @Order(7) + void setQueueAttributesWithJsonNullValueIsRejected() { + String body = "{\"QueueUrl\":\"" + queueUrl + "\"," + + "\"Attributes\":{\"DelaySeconds\":null}}"; + + given() + .contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AmazonSQS.SetQueueAttributes") + .body(body) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("InvalidParameterValue")) + .body("message", equalTo("the parameter 'value' may not be null")); + } + @Test @Order(8) void deleteQueueViaQueueUrlPath() {