This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 79159adec058 [backport camel-4.18.x] CAMEL-26276: camel-clickup - do
not log the webhook signatures, and mask the credentials in toString() (#29860)
79159adec058 is described below
commit 79159adec0580840edd32fb58a1d0087b0e0ef4e
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 13 20:37:50 2026 +0100
[backport camel-4.18.x] CAMEL-26276: camel-clickup - do not log the webhook
signatures, and mask the credentials in toString() (#29860)
* camel-clickup: validate the webhook signature against the UTF-8 body
(#29696)
(cherry picked from commit cec2df58992f6c2e23a5af874c387f60e81d9e6a)
* [backport camel-4.18.x] CAMEL-26276: camel-clickup - do not log the
webhook signatures, and mask the credentials in toString() (#29809)
The webhook signature check no longer logs the received and the calculated
signatures, and InvalidMessageSignatureException no longer carries the
calculated signature. The toString() of the ClickUp configuration and of the
webhook masks the credentials.
(cherry picked from commit 644ff8dadb2825dfab9aeec5e76c53a5364e2b69)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---------
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: dhairya05 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../component/clickup/ClickUpConfiguration.java | 11 +-
.../clickup/InvalidMessageSignatureException.java | 15 +++
.../camel/component/clickup/model/Webhook.java | 9 +-
.../clickup/service/ClickUpWebhookService.java | 27 +++--
.../apache/camel/component/clickup/util/Utils.java | 20 +++-
.../component/clickup/ClickUpToStringTest.java | 60 ++++++++++
.../clickup/ClickUpWebhookSignatureLogTest.java | 127 +++++++++++++++++++++
.../camel/component/clickup/util/UtilsTest.java | 69 +++++++++++
8 files changed, 324 insertions(+), 14 deletions(-)
diff --git
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/ClickUpConfiguration.java
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/ClickUpConfiguration.java
index 29f17209bf9c..7ecbf04bc5c0 100644
---
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/ClickUpConfiguration.java
+++
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/ClickUpConfiguration.java
@@ -92,10 +92,17 @@ public class ClickUpConfiguration {
public String toString() {
return "ClickUpConfiguration{" +
"workspaceId=" + workspaceId +
- ", webhookSecret='" + webhookSecret + '\'' +
- ", authorizationToken='" + authorizationToken + '\'' +
+ ", webhookSecret='" + mask(webhookSecret) + '\'' +
+ ", authorizationToken='" + mask(authorizationToken) + '\'' +
", baseUrl='" + baseUrl + '\'' +
'}';
}
+ /**
+ * Masks a credential so that logging this configuration cannot leak it.
{@code xxxxxx} is the mask Camel uses when
+ * it sanitizes a URI, and whether the value was set at all is still
visible.
+ */
+ private static String mask(Object secret) {
+ return secret != null ? "xxxxxx" : "null";
+ }
}
diff --git
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/InvalidMessageSignatureException.java
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/InvalidMessageSignatureException.java
index 53e2ac4dcbd1..4cce11c56906 100644
---
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/InvalidMessageSignatureException.java
+++
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/InvalidMessageSignatureException.java
@@ -22,6 +22,17 @@ public class InvalidMessageSignatureException extends
RuntimeException {
private final String messageSignature;
private final String calculatedSignature;
+ public InvalidMessageSignatureException(String message, String
messageSignature) {
+ this.message = message;
+ this.messageSignature = messageSignature;
+ this.calculatedSignature = null;
+ }
+
+ /**
+ * @deprecated the calculated signature is the valid signature of the
message, so it should not travel with the
+ * exception; use {@link
#InvalidMessageSignatureException(String, String)}
+ */
+ @Deprecated(since = "4.18.6")
public InvalidMessageSignatureException(String message, String
messageSignature, String calculatedSignature) {
this.message = message;
this.messageSignature = messageSignature;
@@ -37,6 +48,10 @@ public class InvalidMessageSignatureException extends
RuntimeException {
return messageSignature;
}
+ /**
+ * @deprecated the webhook consumer no longer sets the calculated
signature, so this returns null for its exceptions
+ */
+ @Deprecated(since = "4.18.6")
public String getCalculatedSignature() {
return calculatedSignature;
}
diff --git
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/model/Webhook.java
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/model/Webhook.java
index 38303d085762..e22d15c06ae9 100644
---
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/model/Webhook.java
+++
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/model/Webhook.java
@@ -184,8 +184,15 @@ public class Webhook implements Serializable {
", folderId='" + folderId + '\'' +
", spaceId='" + spaceId + '\'' +
", health=" + health +
- ", secret='" + secret + '\'' +
+ ", secret='" + mask(secret) + '\'' +
'}';
}
+ /**
+ * Masks a credential so that logging a webhook cannot leak it. {@code
xxxxxx} is the mask Camel uses when it
+ * sanitizes a URI, and whether the value was set at all is still visible.
+ */
+ private static String mask(Object secret) {
+ return secret != null ? "xxxxxx" : "null";
+ }
}
diff --git
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/service/ClickUpWebhookService.java
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/service/ClickUpWebhookService.java
index ca0786a9cca5..4d7a12c174cb 100644
---
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/service/ClickUpWebhookService.java
+++
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/service/ClickUpWebhookService.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.clickup.service;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
import java.util.Optional;
import java.util.Set;
@@ -80,30 +82,39 @@ public class ClickUpWebhookService {
throw new RuntimeException("The webhook HTTP request doesn't
contain the 'x-signature' header.");
}
- String messageBody;
+ byte[] messageBytes;
try (InputStream body = message.getBody(InputStream.class)) {
- messageBody = new String(body.readAllBytes());
+ // the signature covers the bytes as they arrived: decoding and
re-encoding them first would turn a
+ // malformed sequence into U+FFFD and change what is hashed
+ messageBytes = body.readAllBytes();
- LOG.debug("Message body {} to be validated against the given
signature {}", messageBody, signature);
+ // the signature authenticates the event, so it stays out of the
log
+ LOG.debug("Message body {} to be validated against the given
signature",
+ new String(messageBytes, StandardCharsets.UTF_8));
body.reset();
} catch (IOException e) {
throw new RuntimeException(e);
}
- String calculatedSignature = Utils.computeMessageHMAC(messageBody,
sharedSecret);
+ String messageBody = new String(messageBytes, StandardCharsets.UTF_8);
+ String calculatedSignature = Utils.computeMessageHMAC(messageBytes,
sharedSecret);
signature = signature.toLowerCase();
calculatedSignature = calculatedSignature.toLowerCase();
- boolean signatureMatches = calculatedSignature.equals(signature);
+ // constant time, so that a wrong signature cannot be refined one
character at a time
+ boolean signatureMatches = MessageDigest.isEqual(
+ calculatedSignature.getBytes(StandardCharsets.US_ASCII),
+ signature.getBytes(StandardCharsets.US_ASCII));
if (!signatureMatches) {
- LOG.debug("The message signature {} does not match {}.",
signature, calculatedSignature);
+ LOG.debug("The message signature does not match.");
- throw new InvalidMessageSignatureException(messageBody, signature,
calculatedSignature);
+ // the calculated signature is the valid one for this body, so it
stays out of the exception too
+ throw new InvalidMessageSignatureException(messageBody, signature);
}
- LOG.debug("The message signature {} matches {}.", signature,
calculatedSignature);
+ LOG.debug("The message signature matches.");
}
}
diff --git
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/util/Utils.java
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/util/Utils.java
index d66accfe654d..5b6ce08e0705 100644
---
a/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/util/Utils.java
+++
b/components/camel-clickup/src/main/java/org/apache/camel/component/clickup/util/Utils.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.clickup.util;
+import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -35,11 +36,23 @@ public class Utils {
private static final String HMAC_HASHING_ALGORITHM = "HmacSHA256";
public static String computeMessageHMAC(String message, String key) {
+ // ClickUp signs the raw request body, so neither side of the HMAC may
depend on the platform default charset
+ return computeMessageHMAC(message.getBytes(StandardCharsets.UTF_8),
key);
+ }
+
+ /**
+ * Computes the HMAC of the message exactly as it arrived, without
decoding and re-encoding it first.
+ *
+ * @param message the raw message bytes, as they were received
+ * @param key the webhook's shared secret
+ * @return the HMAC as an upper-case hexadecimal string
+ */
+ public static String computeMessageHMAC(byte[] message, String key) {
try {
Mac mac = Mac.getInstance(HMAC_HASHING_ALGORITHM);
- mac.init(new SecretKeySpec(key.getBytes(),
HMAC_HASHING_ALGORITHM));
+ mac.init(new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8),
HMAC_HASHING_ALGORITHM));
- byte[] hash = mac.doFinal(message.getBytes());
+ byte[] hash = mac.doFinal(message);
return DatatypeConverter.printHexBinary(hash);
} catch (NoSuchAlgorithmException e) {
@@ -47,7 +60,8 @@ public class Utils {
throw new RuntimeCamelException(e);
} catch (InvalidKeyException e) {
- LOG.debug("This exception should never occur: the provided key is
not valid. {}", key);
+ // the key is the webhook's shared secret, so it must not be logged
+ LOG.debug("This exception should never occur: the provided key is
not valid.");
throw new RuntimeCamelException(e);
}
diff --git
a/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpToStringTest.java
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpToStringTest.java
new file mode 100644
index 000000000000..099528e69437
--- /dev/null
+++
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpToStringTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.clickup;
+
+import org.apache.camel.component.clickup.model.Webhook;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The configuration and the webhook model are printed when logged, so their
toString() masks the credentials.
+ */
+public class ClickUpToStringTest {
+
+ @Test
+ public void configurationMasksTheCredentials() {
+ ClickUpConfiguration configuration = new ClickUpConfiguration();
+ configuration.setWorkspaceId(42L);
+ configuration.setWebhookSecret("the-webhook-secret");
+ configuration.setAuthorizationToken("the-authorization-token");
+
+ assertThat(configuration.toString())
+ .contains("workspaceId=42")
+ .contains("webhookSecret='xxxxxx'")
+ .contains("authorizationToken='xxxxxx'")
+ .doesNotContain("the-webhook-secret")
+ .doesNotContain("the-authorization-token");
+ }
+
+ @Test
+ public void configurationShowsACredentialThatIsNotSet() {
+ assertThat(new ClickUpConfiguration().toString())
+ .contains("webhookSecret='null'")
+ .contains("authorizationToken='null'");
+ }
+
+ @Test
+ public void webhookMasksTheSecret() {
+ Webhook webhook = new Webhook();
+ webhook.setSecret("the-webhook-secret");
+
+ assertThat(webhook.toString())
+ .contains("secret='xxxxxx'")
+ .doesNotContain("the-webhook-secret");
+ }
+}
diff --git
a/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpWebhookSignatureLogTest.java
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpWebhookSignatureLogTest.java
new file mode 100644
index 000000000000..242fb04087bd
--- /dev/null
+++
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/ClickUpWebhookSignatureLogTest.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.clickup;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Message;
+import org.apache.camel.component.clickup.service.ClickUpWebhookService;
+import org.apache.camel.component.clickup.util.Utils;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultMessage;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * The webhook signature check logs at DEBUG what it validates, but never a
signature: the valid signature of an event
+ * stays out of the log and out of the exception of a failed check.
+ */
+public class ClickUpWebhookSignatureLogTest {
+
+ private static final String SECRET = "secret";
+ private static final String BODY =
"{\"event\":\"taskTimeTrackedUpdated\"}";
+
+ private final CamelContext context = new DefaultCamelContext();
+ private final ClickUpWebhookService service = new
ClickUpWebhookService(null);
+ private final LogEventCaptor captor = new LogEventCaptor();
+ private Logger logger;
+ private Level level;
+
+ @BeforeEach
+ public void captureDebugLog() {
+ logger = (Logger) LogManager.getLogger(ClickUpWebhookService.class);
+ level = logger.getLevel();
+ Configurator.setLevel(logger.getName(), Level.DEBUG);
+ logger.addAppender(captor);
+ }
+
+ @AfterEach
+ public void restoreLog() {
+ logger.removeAppender(captor);
+ Configurator.setLevel(logger.getName(), level);
+ }
+
+ @Test
+ public void validSignatureIsNotLogged() {
+ String signature = Utils.computeMessageHMAC(BODY, SECRET);
+
+ service.validateMessageSignature(message(signature), SECRET);
+
+ assertThat(debugMessages()).anyMatch(m -> m.contains("matches"));
+ assertThat(debugMessages()).anyMatch(m -> m.contains(BODY));
+ assertThat(debugMessages()).noneMatch(m ->
m.toLowerCase().contains(signature.toLowerCase()));
+ }
+
+ @Test
+ public void
calculatedSignatureIsNotLoggedNorInTheExceptionOfAFailedCheck() {
+ String validSignature = Utils.computeMessageHMAC(BODY, SECRET);
+ String wrongSignature = Utils.computeMessageHMAC(BODY,
"another-secret");
+
+ assertThatThrownBy(() ->
service.validateMessageSignature(message(wrongSignature), SECRET))
+
.isInstanceOfSatisfying(InvalidMessageSignatureException.class, e -> {
+
assertThat(e.getMessageSignature()).isEqualToIgnoringCase(wrongSignature);
+ assertThat(e.getCalculatedSignature()).isNull();
+ });
+
+ assertThat(debugMessages()).anyMatch(m -> m.contains("does not
match"));
+ assertThat(debugMessages()).noneMatch(m ->
m.toLowerCase().contains(validSignature.toLowerCase()));
+ assertThat(debugMessages()).noneMatch(m ->
m.toLowerCase().contains(wrongSignature.toLowerCase()));
+ }
+
+ private Message message(String signature) {
+ Message message = new DefaultMessage(context);
+ message.setBody(new
ByteArrayInputStream(BODY.getBytes(StandardCharsets.UTF_8)));
+ message.setHeader("x-signature", signature);
+ return message;
+ }
+
+ private List<String> debugMessages() {
+ return captor.events.stream()
+ .filter(event -> event.getLevel() == Level.DEBUG)
+ .map(event -> event.getMessage().getFormattedMessage())
+ .toList();
+ }
+
+ private static final class LogEventCaptor extends AbstractAppender {
+ private final List<LogEvent> events = new CopyOnWriteArrayList<>();
+
+ LogEventCaptor() {
+ super("ClickUpWebhookSignatureLogCaptor", null, null, false,
Property.EMPTY_ARRAY);
+ start();
+ }
+
+ @Override
+ public void append(LogEvent event) {
+ events.add(event.toImmutable());
+ }
+ }
+}
diff --git
a/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/util/UtilsTest.java
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/util/UtilsTest.java
new file mode 100644
index 000000000000..4d0c7db5742c
--- /dev/null
+++
b/components/camel-clickup/src/test/java/org/apache/camel/component/clickup/util/UtilsTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.clickup.util;
+
+import java.nio.charset.StandardCharsets;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The webhook signature has to be reproducible on any JVM: ClickUp computes
it over the raw request body, so the
+ * expected values below are HMAC-SHA256 over UTF-8 bytes.
+ */
+public class UtilsTest {
+
+ @Test
+ public void shouldComputeTheHmacOfAnAsciiMessage() {
+ assertThat(Utils.computeMessageHMAC("payload", "secret"))
+
.isEqualTo("B82FCB791ACEC57859B989B430A826488CE2E479FDF92326BD0A2E8375A42BA4");
+ }
+
+ @Test
+ public void shouldComputeTheHmacOverUtf8Bytes() {
+ // "secret" and "payload" with a diaeresis and a tilde: neither is
representable in US-ASCII, and both
+ // encode differently in ISO-8859-1
+ final String key = "s\u00ebcret";
+ final String message = "p\u00e3yload";
+
+ assertThat(Utils.computeMessageHMAC(message, key))
+
.isEqualTo("3F449438582E13522059F2FD70C99DDF4BEB084815B88E184F487E3F0F627656");
+ }
+
+ @Test
+ public void shouldHashTheRawBytesAsGiven() {
+ final String key = "s\u00ebcret";
+ final String message = "p\u00e3yload";
+
+ // the byte[] overload is what the webhook check uses, so for valid
UTF-8 it has to agree with the String one
+
assertThat(Utils.computeMessageHMAC(message.getBytes(StandardCharsets.UTF_8),
key))
+ .isEqualTo(Utils.computeMessageHMAC(message, key));
+ }
+
+ @Test
+ public void shouldHashABodyThatIsNotValidUtf8() {
+ final String key = "secret";
+ // a lone 0x80 continuation byte: decoding the body to a String first
turns it into U+FFFD and changes the
+ // hash, which is why the check has to work on the bytes as they
arrived
+ final byte[] message = { 'a', (byte) 0x80, 'b' };
+
+ assertThat(Utils.computeMessageHMAC(message, key))
+ .isNotEqualTo(Utils.computeMessageHMAC(new String(message,
StandardCharsets.UTF_8), key));
+ }
+
+}