Skip to content

feat(sqs): validate message attributes against their documented rules (#472) - #482

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/472-sqs-attribute-rules
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/472-sqs-attribute-rules

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #472

The gap

Substrate stored and returned every user-defined message attribute exactly as sent. So all of these were accepted and delivered:

  • an eleventh attribute, past AWS's documented maximum of ten;
  • a name real SQS reserves — AWS.trace, .trace, trace., trace..id, trace id;
  • a DataType that is not prefixed String, Number or Binary;
  • a String attribute with no value;
  • a Number attribute holding "abc".

That last one is the shape this tracker exists to close. A consumer whose handler parses a Number attribute had no way to reach its parse-failure branch: substrate accepted the send, the attribute came back verbatim, and a test asserting the rejection passed while the same code broke against AWS.

What now happens

SendMessage and each SendMessageBatch entry enforce the rules below, all as InvalidParameterValue / HTTP 400.

Rule Rejected
count more than 10 attributes on one message
name length 256 bytes or more
name characters anything outside A-Z, a-z, 0-9, _, -, .
reserved prefix starting with AWS. or Amazon., any casing
periods a leading or trailing ., or two in sequence
type a DataType not prefixed String, Number or Binary; an absent one
type length 256 bytes or more
empty value a String attribute with no value
Number value not a decimal number, or outside −10^128 … 10^126

A rejected send enqueues nothing. On a FIFO queue the check runs before the deduplication ID is recorded, so a corrected retry reusing the same MessageDeduplicationId is delivered rather than swallowed as a duplicate — the same ordering #454's size check established, asserted rather than assumed to have survived.

Both length bounds are exclusive: 255 bytes is legal, 256 is not. The developer guide says "up to 256 characters" while the error text says "must be shorter than 256 Bytes"; the error is the more specific evidence, and the conflict is recorded in the code rather than quietly resolved.

Three findings worth flagging

1. The prefix check is case-INsensitive — the opposite of #468's aws: tag rule. The guide says a name "can't start with AWS. or Amazon. (or any casing variations)", and LocalStack matches its regex against name.lower(). EC2's aws: tag prefix is case-sensitive, so AWS:foo remains a legal tag key (ec2CheckReservedTagKeys, #452/#468). Both findings are correct — the two services document different rules — and unifying the checks would break one of them. This is called out in the code, the CHANGELOG and docs/services.md, because a reader arriving from one will assume the other.

2. Batch failures are per entry, at HTTP 200. Substrate had no BatchResultErrorEntry type at all — both batch paths emitted an empty Failed placeholder — so a consumer's per-entry error handling had nothing to exercise, while the reference warns you "should check for batch errors even when the call returns an HTTP status code of 200". An attribute violation now produces a Failed entry with SenderFault: true, does not enqueue, and leaves its siblings delivered. Failed is always present, empty rather than absent on full success. The XML element name comes from the query-protocol model, which declares BatchResultErrorEntryList flattened with locationName: "BatchResultErrorEntry" under resultWrapper: "SendMessageBatchResult".

This is deliberately unlike the batch size checks ten lines away, which still fail the whole request with BatchRequestTooLong: the payload cap is a documented property of the aggregate the caller transmitted, while a malformed attribute is a defect in one entry. A test pins that the size behaviour did not become per-entry by accident.

3. The provenance is better than planned, and the plan was wrong on one point. The plan recorded that the 10-attribute rejection has "no capture anywhere". It does: opentelemetry-java-instrumentation#13799 records live SQS returning SqsException: Number of message attributes [11] exceeds the allowed maximum [10]. (Service: Sqs, Status Code: 400, Request ID: f5704601-…) — an AWS Request ID and a 400. Likewise the Number cast failure turned out to be a real boto3 capture carrying both code and message, not substrate's own text.

Tiers, recorded per message in the file:

  • Real-AWS captures — the count message; the Number cast failure (code and message); the empty-String-value message, captured twice independently.
  • Snapshot-tested reimplementation — the name and type messages, from LocalStack. The character-class string is reproduced verbatim including its "upper and lower score characters" phrasing and its trailing space; a tidied string is no longer the one a consumer sees.
  • One reimplementation, the weakest claim here and labeled as such in the code — the Number range message, which only elasticmq supplies.

The count rejection's code is absent from its capture and comes from agreement across five reimplementations. Neither moto nor LocalStack enforces the count at all, which is why substrate accepting an eleventh attribute went unnoticed until #461 made attributes observable.

Scope decisions, stated rather than silent

  • Uniqueness is structural, not checked: attributes arrive as a Go map keyed by name, so a duplicate cannot survive parsing to be rejected.
  • The empty-value rule is String-only, following the one source that specifies a message for it. An empty Binary value is still accepted — which is what keeps TestSQS_MessageAttributes_BinaryIsIdentifiedByDataType's transport-byte case reachable through the public API. Scoping this to the exact type rather than the base type was load-bearing; a mutation confirms the broader form breaks that test.
  • Scientific notation is accepted (1e5) as the permissive reading of a detail no source settles, stated in the code rather than implied.
  • The character class follows the developer guide, not LocalStack's wider regex admitting U+00C0..U+017F, which is unattributed.
  • The rules apply on send, not on receive. A message written into state before they existed — replayed from an older event log — is returned as stored, because withholding it would make a recorded run unreplayable. A test writes an illegal name directly into state and asserts it is still delivered. Tracked separately.

Attributes are visited in sorted name order so a message breaking two rules always reports the same one; a walk over the Go map would report one error on some runs and the other on others, which is the precise nondeterminism this emulator exists to remove.

Verification

  • gofmt -l ., go build ./..., go vet ./... clean; golangci-lint run ./... → 0 issues; make test (race) → exit 0; make docs-reference docs-reference-check docs-versions → exit 0; go test -C test/e2e ./... → ok; VitePress build → clean, so the new anchors resolve.
  • SQS: message attributes are measured but not stored or returned #461's 10-attribute boundary test still passes — run, not assumed. Its doc comment said the count was unenforced and that enforcing it was "tracked separately"; that is now false, so it is reworded to describe the guard it has become.
  • New file coverage: 100% on every function except the deliberately-unreachable scanner/parser divergence guard in sqsCheckNumberAttribute, which is documented as such.
  • 24 mutations, all caught. Highest-value ones: making the prefix check case-sensitive (18 tests fail); failing the whole batch instead of the entry, in each protocol branch; dropping the count check; an off-by-one rejecting at ten; hardcoding the count in its own message (the mistake one reimplementation actually made); dropping the sequential-period check; accepting anything as a Number; comparing the range through float64, where 10^126 is inexact; rejecting an empty Binary value too; reporting SenderFault: false; omitting Failed when empty; and moving the send check after the FIFO dedup record.

Docs: docs/services.md §"Message attributes" gains "Attribute rules", "Batch failures are per entry" and "Provenance" subsections, replacing the "Two limits are not enforced" paragraph; the SQS operation table rows for SendMessage/SendMessageBatch link to them.

…#472)

Every user-defined attribute was stored and returned as sent, so an eleventh
attribute, a name real SQS reserves, a DataType that is not one of the three,
and a Number attribute holding "abc" were all accepted and delivered. That
last one is the silent-success shape the tracker exists to close: a consumer
whose handler parses a Number attribute had no way to reach its parse-failure
branch, and a test of that branch passed against substrate while the same code
broke against AWS.

SendMessage and each SendMessageBatch entry now enforce the count, name, type,
empty-value and Number-range rules, all as InvalidParameterValue / HTTP 400. A
rejected send enqueues nothing, and on a FIFO queue the check runs before the
deduplication ID is recorded so a corrected retry reusing the same
MessageDeduplicationId is delivered rather than swallowed.

The reserved-prefix check is case-INsensitive, per the guide's "or any casing
variations" - the opposite of #468's aws: tag-key rule, where AWS:foo remains
legal. Both are correct and the checks are deliberately not shared.

SendMessageBatch now reports a violation per entry: a BatchResultErrorEntry in
Failed with SenderFault true at HTTP 200, the offending entry not enqueued and
its siblings delivered. Substrate had no such type - both batch paths emitted
an empty Failed placeholder - so a consumer's per-entry error handling had
nothing to exercise. This stays deliberately unlike the batch size checks a
few lines away, which fail the whole request with BatchRequestTooLong.

Provenance is recorded per message, strongest first: the count rejection's
message, the Number cast failure (code and message) and the empty-String-value
message are real-AWS captures; the name and type messages come from
LocalStack's snapshot-tested provider, reproduced verbatim including the
character-class string's odd phrasing and trailing space; the Number range
message is one reimplementation's own wording and is labeled the weakest claim
in the file.

24 mutations of the new rules and their wiring were each confirmed to fail at
least one new test.

Closes #472
@scttfrdmn scttfrdmn added type: feature New feature or improvement area: sqs fidelity labels Aug 2, 2026
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.49624% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/sqs_messageattrrules.go 98.23% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 5f78e3c into main Aug 2, 2026
16 checks passed
@scttfrdmn scttfrdmn mentioned this pull request Aug 2, 2026
@scttfrdmn
scttfrdmn deleted the feat/472-sqs-attribute-rules branch August 2, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sqs fidelity type: feature New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQS: the 10-attribute maximum and the attribute-name character rules are unenforced

1 participant