Repository navigation
feat(sqs): validate message attributes against their documented rules (#472) - #482
Merged
Merged
Conversation
…#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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #472
The gap
Substrate stored and returned every user-defined message attribute exactly as sent. So all of these were accepted and delivered:
AWS.trace,.trace,trace.,trace..id,trace id;DataTypethat is not prefixedString,NumberorBinary;Stringattribute with no value;Numberattribute holding"abc".That last one is the shape this tracker exists to close. A consumer whose handler parses a
Numberattribute 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
SendMessageand eachSendMessageBatchentry enforce the rules below, all asInvalidParameterValue/ HTTP 400.A-Z,a-z,0-9,_,-,.AWS.orAmazon., any casing., or two in sequenceDataTypenot prefixedString,NumberorBinary; an absent oneStringattribute with no valueNumbervalueA rejected send enqueues nothing. On a FIFO queue the check runs before the deduplication ID is recorded, so a corrected retry reusing the same
MessageDeduplicationIdis 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 withAWS.orAmazon.(or any casing variations)", and LocalStack matches its regex againstname.lower(). EC2'saws:tag prefix is case-sensitive, soAWS:fooremains 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 anddocs/services.md, because a reader arriving from one will assume the other.2. Batch failures are per entry, at HTTP 200. Substrate had no
BatchResultErrorEntrytype at all — both batch paths emitted an emptyFailedplaceholder — 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 of200". An attribute violation now produces aFailedentry withSenderFault: true, does not enqueue, and leaves its siblings delivered.Failedis always present, empty rather than absent on full success. The XML element name comes from the query-protocol model, which declaresBatchResultErrorEntryListflattened withlocationName: "BatchResultErrorEntry"underresultWrapper: "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 theNumbercast 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:
Numbercast failure (code and message); the empty-String-value message, captured twice independently.Numberrange 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
String-only, following the one source that specifies a message for it. An emptyBinaryvalue is still accepted — which is what keepsTestSQS_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.1e5) as the permissive reading of a detail no source settles, stated in the code rather than implied.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.sqsCheckNumberAttribute, which is documented as such.Number; comparing the range throughfloat64, where 10^126 is inexact; rejecting an emptyBinaryvalue too; reportingSenderFault: false; omittingFailedwhen 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 forSendMessage/SendMessageBatchlink to them.