fix(eventbridgev2): refuse a webhook HMAC secret over 512 bytes (#9527)

CreateEventSource refuses a webhook HMAC SecretValue over 512 bytes, checked right after the 16-byte minimum, as RotateWebhookCredentials already does. A static token and a Basic password over 512 bytes stay accepted.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-26 18:47:56 -04:00
1 parent c24cb12811
commit 3d7a88a0d8
3 files changed
+45 -4

No files matched your search

@@ -175,6 +175,9 @@ final class WebhookEventsConfigurations {
if (secret != null && secretBytes < MIN_HMAC_SECRET_BYTES) {
throw hmacInvalid("SecretValue must be at least 16 bytes (for BASE64, after decoding)");
}
if (secret != null && secretBytes > MAX_HMAC_SECRET_BYTES) {
throw hmacInvalid("SecretValue must be at most 512 bytes (for BASE64, after decoding)");
}
if (hmac.hasNonNull("TimestampToleranceInSeconds") && timestamp == null) {
throw hmacInvalid("TimestampToleranceInSeconds requires TimestampHttpHeader to be set");
}
@@ -264,10 +267,7 @@ final class WebhookEventsConfigurations {
return base64 ? Base64.getDecoder().decode(stored).length : stored.getBytes(StandardCharsets.UTF_8).length;
}
/**
* The HMAC secret a rotation stores for {@code value}, judged against the source's configuration. A rotation
* has an upper bound that create does not.
*/
/** The HMAC secret a rotation stores for {@code value}, judged against the source's configuration. */
static String rotatedHmacSecret(String value, JsonNode hmac) {
boolean base64 = isBase64(hmac);
String stored = storedHmacSecret(value, base64);
@@ -179,6 +179,17 @@ class EventBridgeV2EventSourceIntegrationTest {
+ "must satisfy regular expression pattern: (?!aws\\.)[A-Za-z0-9][\\.\\-_A-Za-z0-9]*",
constraint.awsErrorDetails().errorMessage());
EventSourceConfiguration oversized = EventSourceConfiguration.fromWebhookEventsConfiguration(
webhook -> webhook.roleArn(ROLE).authConfiguration(auth -> auth.hmacAuthConfiguration(
signing -> signing.algorithm("SHA256").encoding("HEX").signatureHttpHeader("X-Signature")
.signedMessageComposition("BODY").secretValue("é".repeat(257)))));
InvalidInputException tooLong = assertThrows(InvalidInputException.class, () -> events
.createEventSource(request -> request.name("big-" + suffix).eventBusArn(bus)
.configuration(oversized)));
assertEquals("WebhookEventsConfiguration.AuthConfiguration.HmacAuthConfiguration is invalid: "
+ "SecretValue must be at most 512 bytes (for BASE64, after decoding)",
tooLong.awsErrorDetails().errorMessage());
String missingBus = bus.replace("v2-err-" + suffix, "v2-none-" + suffix);
ResourceNotFoundException noBus = assertThrows(ResourceNotFoundException.class,
() -> events.listEventSources(request -> request.eventBusArn(missingBus)));
@@ -287,6 +287,36 @@ class WebhookEventsConfigurationsTest {
+ "\"Delimiter\":\",\",\"SignaturePrefix\":\"v1=\""));
}
@Test
void hmacSecretIsBoundedAbove512Bytes() {
String tooLong = SIGNED_MESSAGE_ID_ERROR + "SecretValue must be at most 512 bytes (for BASE64, after decoding)";
String toleranceWithoutHeader = SIGNED_MESSAGE_ID_ERROR
+ "TimestampToleranceInSeconds requires TimestampHttpHeader to be set";
String tolerance = ",\"TimestampToleranceInSeconds\":5";
assertEquals(tooLong, hmacRefusal("\"SecretValue\":\"" + "é".repeat(256) + "k\"" + tolerance));
assertEquals(tooLong, hmacRefusal("\"SecretValue\":\"" + "é".repeat(257) + "\""));
assertEquals(toleranceWithoutHeader, hmacRefusal("\"SecretValue\":\"" + "é".repeat(256) + "\"" + tolerance));
assertEquals(tooLong, hmacRefusal("\"SecretValue\":\"" + "😀".repeat(129) + "\"" + tolerance));
assertEquals(toleranceWithoutHeader,
hmacRefusal("\"SecretValue\":\"" + "😀".repeat(128) + "\"" + tolerance));
}
@Test
void hmacSecretBoundCountsWhsecPrefixForRawOnly() {
String tooLong = SIGNED_MESSAGE_ID_ERROR + "SecretValue must be at most 512 bytes (for BASE64, after decoding)";
String toleranceWithoutHeader = SIGNED_MESSAGE_ID_ERROR
+ "TimestampToleranceInSeconds requires TimestampHttpHeader to be set";
String tolerance = ",\"TimestampToleranceInSeconds\":5";
assertEquals(toleranceWithoutHeader,
hmacRefusal("\"SecretValue\":\"whsec_" + "é".repeat(253) + "\"" + tolerance));
assertEquals(tooLong, hmacRefusal("\"SecretValue\":\"whsec_" + "é".repeat(254) + "\"" + tolerance));
assertEquals("WebhookEventsConfiguration.AuthConfiguration.HmacAuthConfiguration.SecretValue must be "
+ "standard Base64 when SecretEncoding is BASE64",
hmacRefusal("\"SecretEncoding\":\"BASE64\",\"SecretValue\":\"" + "é".repeat(257) + "\""));
}
@Test
void hmacAcceptsTheCombinationsAwsAccepts() {
for (String extra : List.of(