From 3d7a88a0d81ac8e4565652f17b15e862ec5ffbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Fri, 27 Nov 2026 07:47:56 +0900 Subject: [PATCH] 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. --- .../WebhookEventsConfigurations.java | 8 ++--- ...entBridgeV2EventSourceIntegrationTest.java | 11 +++++++ .../WebhookEventsConfigurationsTest.java | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurations.java b/src/main/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurations.java index 30f8b9ff28..be6406f1ee 100644 --- a/src/main/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurations.java +++ b/src/main/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurations.java @@ -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); diff --git a/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2EventSourceIntegrationTest.java b/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2EventSourceIntegrationTest.java index 2f2157cefd..b09319cac7 100644 --- a/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2EventSourceIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/eventbridgev2/EventBridgeV2EventSourceIntegrationTest.java @@ -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))); diff --git a/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java b/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java index 48188d35cf..d9f3d7dd63 100644 --- a/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java +++ b/src/test/java/io/floci/aws/services/eventbridgev2/WebhookEventsConfigurationsTest.java @@ -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(