Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(sqs): compute MD5OfMessageAttributes over the returned attributes (#2329)

Xevos1172f12950051ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ee4a163..92352422 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
- **Route 53 — private hosted zones keep their VPC** — `CreateHostedZone` with a `VPC` made a public zone and dropped the VPC, so Terraform's `aws_route53_zone` with a `vpc` block planned to add it again on every run; the zone is now private, the response carries the `VPC` instead of a delegation set, also on a `CallerReference` replay, and `GetHostedZone` returns its `VPCs`. Contributed by @kharabasz.
- **ELBv2 — listener `SslPolicy` and certificate** — `CreateListener` and `ModifyListener` dropped `SslPolicy` and `Certificates`, so `DescribeListeners` returned neither and Terraform re-planned `ssl_policy` on every HTTPS listener; HTTPS and TLS listeners now keep and return both, the policy defaults to `ELBSecurityPolicy-2016-08`, a listener moved to HTTP or TCP drops them, and more than one default certificate answers `ValidationError`. Contributed by @kharabasz.
+- **SQS — `MD5OfMessageAttributes` of filtered attributes** — `ReceiveMessage` with `MessageAttributeNames` selecting some of a message's attributes returned only those attributes but the digest of all of them, so SDKs that validate `MD5OfMessageAttributes` rejected the response; the digest is now computed over the attributes returned. Contributed by @Xevos117.
## [1.5.30] — 2026-10-20
diff --git a/ministack/services/sqs.py b/ministack/services/sqs.py
index 169e25a0..42ebe3e2 100644
--- a/ministack/services/sqs.py
+++ b/ministack/services/sqs.py
@@ -788,8 +788,7 @@ async def _act_receive_message(data: dict, qurl: str) -> dict:
fa = _filter_msg_attrs(m["message_attributes"], msg_attr_names)
if fa:
entry["MessageAttributes"] = fa
- if m["md5_attrs"]:
- entry["MD5OfMessageAttributes"] = m["md5_attrs"]
+ entry["MD5OfMessageAttributes"] = _md5_msg_attrs(fa)
out.append(entry)
return {"Messages": out} if out else {}
diff --git a/tests/test_sqs.py b/tests/test_sqs.py
index c8df8615..0dca83c2 100644
--- a/tests/test_sqs.py
+++ b/tests/test_sqs.py
@@ -337,6 +337,44 @@ def test_sqs_message_attributes(sqs):
assert attrs["color"]["StringValue"] == "blue"
assert attrs["count"]["StringValue"] == "42"
+def test_sqs_receive_md5_of_filtered_message_attributes(sqs):
+ """MD5OfMessageAttributes on ReceiveMessage must be the digest of the
+ attributes actually returned, not of every attribute sent. SDKs that
+ validate it recompute it from the attributes in the response."""
+ url = sqs.create_queue(QueueName="intg-sqs-md5-filtered")["QueueUrl"]
+ sqs.send_message(
+ QueueUrl=url,
+ MessageBody="md5-filtered",
+ MessageAttributes={
+ "item.color": {"DataType": "String", "StringValue": "red"},
+ "size": {"DataType": "String", "StringValue": "large"},
+ },
+ )
+ # Digests of the SQS binary encoding of the returned attributes.
+ md5_color = "577bde534466fcc0f833e000d746308b"
+ md5_size = "293ff4145d6b9021065be848a611037b"
+ md5_all = "9906f4cd4d08bdd5cf9f22829f9e07f7"
+
+ def receive(**kwargs):
+ resp = sqs.receive_message(QueueUrl=url, VisibilityTimeout=0, **kwargs)
+ return resp["Messages"][0]
+
+ for names, returned, md5 in (
+ (["item.color"], ["item.color"], md5_color),
+ (["item.*"], ["item.color"], md5_color),
+ (["size"], ["size"], md5_size),
+ (["All"], ["item.color", "size"], md5_all),
+ ):
+ msg = receive(MessageAttributeNames=names)
+ assert sorted(msg["MessageAttributes"]) == returned, names
+ assert msg["MD5OfMessageAttributes"] == md5, names
+
+ for kwargs in ({}, {"MessageAttributeNames": ["missing"]}):
+ msg = receive(**kwargs)
+ assert "MessageAttributes" not in msg
+ assert "MD5OfMessageAttributes" not in msg
+ sqs.delete_queue(QueueUrl=url)
+
def test_sqs_batch_send(sqs):
url = sqs.create_queue(QueueName="intg-sqs-batchsend")["QueueUrl"]
resp = sqs.send_message_batch(