fix(scheduler): do not base64-decode BinaryValue in universal sqs target (#5314)

Real EventBridge Scheduler uses the UTF-8 bytes of a universal SQS
target's MessageAttributes.*.BinaryValue string as the attribute value and
never base64-decodes it. Floci required base64 and rejected anything else,
so schedules that deliver on AWS failed with "not valid base64".
This commit is contained in:
Mathieu Charpenel authored and GitHub committed 2026-10-09 19:05:45 -04:00
1 parent f413a667d0
commit d0c2774564
2 files changed
+32 -13

No files matched your search

@@ -31,7 +31,6 @@ import org.jboss.logging.Logger;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -531,19 +530,15 @@ public class ScheduleInvoker {
JsonNode valueNode = entry.getValue();
String dataType = valueNode.path("DataType").asText(null);
String stringValue = valueNode.path("StringValue").asText(null);
String binaryValueBase64 = valueNode.path("BinaryValue").asText(null);
String binaryValueText = valueNode.path("BinaryValue").asText(null);
if (dataType == null) {
return;
}
if (binaryValueBase64 != null) {
byte[] binaryValue;
try {
binaryValue = Base64.getDecoder().decode(binaryValueBase64);
} catch (IllegalArgumentException e) {
throw new AwsException("InvalidParameterValue",
"Invalid binary value for message attribute '" + entry.getKey()
+ "': not valid base64.", 400);
}
if (binaryValueText != null) {
// Unlike the SQS JSON protocol, AWS does not base64-decode BinaryValue in a universal
// target Input: the attribute bytes are the UTF-8 encoding of the JSON string, and a
// base64 string is delivered as its own text.
byte[] binaryValue = binaryValueText.getBytes(StandardCharsets.UTF_8);
attributes.put(entry.getKey(), new MessageAttributeValue(binaryValue, dataType));
} else if (stringValue != null) {
attributes.put(entry.getKey(), new MessageAttributeValue(
@@ -336,8 +336,9 @@ class ScheduleInvokerTest {
}
@Test
void universalSqsSendMessageForwardsStringAndBase64BinaryMessageAttributes() {
void universalSqsSendMessageForwardsStringAndBinaryMessageAttributesWithoutBase64Decoding() {
String queueUrl = "http://localhost:4566/000000000000/q.fifo";
// AWS delivers a base64-looking BinaryValue as its own text, it does not decode it
String binaryValueBase64 = "aGVsbG8=";
Target target = new Target();
target.setArn("arn:aws:scheduler:::aws-sdk:sqs:sendMessage");
@@ -369,7 +370,7 @@ class ScheduleInvokerTest {
MessageAttributeValue binaryAttribute = attributes.get("BinaryAttr");
assertNotNull(binaryAttribute);
assertEquals("Binary.Custom", binaryAttribute.getDataType());
assertArrayEquals("hello".getBytes(StandardCharsets.UTF_8), binaryAttribute.getBinaryValue());
assertArrayEquals(binaryValueBase64.getBytes(StandardCharsets.UTF_8), binaryAttribute.getBinaryValue());
assertNull(binaryAttribute.getStringValue());
}
@@ -504,6 +505,29 @@ class ScheduleInvokerTest {
verifyNoInteractions(redshiftDataService);
}
@Test
void universalSqsSendMessageUsesUtf8BytesOfRawBinaryValue() {
String queueUrl = "http://localhost:4566/000000000000/q";
Target target = new Target();
target.setArn("arn:aws:scheduler:::aws-sdk:sqs:sendMessage");
target.setRoleArn("arn:aws:iam::000000000000:role/x");
// Protobuf-like payload with control characters plus U+0080 and U+00FF, as JSON escapes
target.setInput("{\"QueueUrl\":\"" + queueUrl + "\","
+ "\"MessageBody\":\"hi\","
+ "\"MessageAttributes\":{"
+ "\"BinaryAttr\":{\"DataType\":\"Binary\",\"BinaryValue\":\"\\nA\\u0080\\u0001\\u00ff\\u0000B\"}}}");
invoke(target, "us-east-1");
ArgumentCaptor<Map<String, MessageAttributeValue>> attributesCaptor = ArgumentCaptor.captor();
verify(sqsService).sendMessage(eq(queueUrl), eq("hi"), eq(0), isNull(), isNull(),
attributesCaptor.capture(), eq("us-east-1"));
// Same bytes real AWS delivers for this Input: the UTF-8 encoding of the decoded JSON string
byte[] expected = {0x0a, 0x41, (byte) 0xc2, (byte) 0x80, 0x01, (byte) 0xc3, (byte) 0xbf, 0x00, 0x42};
assertArrayEquals(expected, attributesCaptor.getValue().get("BinaryAttr").getBinaryValue());
}
@Test
void universalSqsSendMessageSkipsAttributesWithoutDataType() {
String queueUrl = "http://localhost:4566/000000000000/q.fifo";