This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fdff80463df2 CAMEL-27577: Add SensitiveUtils.isSensitiveHeader for
credential HTTP headers (#30894)
fdff80463df2 is described below
commit fdff80463df2477a6410479ada11ba505ca8016b
Author: Pratik <[email protected]>
AuthorDate: Fri Nov 27 06:55:36 2026 -0800
CAMEL-27577: Add SensitiveUtils.isSensitiveHeader for credential HTTP
headers (#30894)
Adds SensitiveUtils.isSensitiveHeader(String) to camel-util, a reusable
rule that
decides whether an HTTP header carries a credential: the name matches a
sensitive
configuration key, or its normalized form ends in token, key, secret,
password, auth,
authorization, credential or credentials, or it is one of a few well-known
credential
headers (Cookie, Set-Cookie, X-Google-IAP-JWT-Assertion, X-Honeycomb-Team).
Idempotency-Key, Sec-WebSocket-Key and Access-Control-Allow-Credentials are
excluded
as they carry no secret.
LoggingHttpActivityListener of camel-http uses this rule instead of the
fixed list of
CAMEL-27429 to mask header values in the activity log; its protected
isSensitiveHeader method is kept for subclasses. The http component page
and the
CAMEL-27429 entry of the 4.24 upgrade guide describe the rule.
---
.../apache/camel/catalog/docs/http-component.adoc | 12 +++--
.../camel-http/src/main/docs/http-component.adoc | 12 +++--
.../http/LoggingHttpActivityListener.java | 12 +----
.../http/HttpLoggingActivityMaskHeadersTest.java | 8 +++
.../java/org/apache/camel/util/SensitiveUtils.java | 54 +++++++++++++++++++
.../org/apache/camel/util/SensitiveUtilsTest.java | 61 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 7 +++
7 files changed, 147 insertions(+), 19 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
index 0c630a06760c..539021c12d35 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
@@ -986,10 +986,14 @@ With `logHttpActivity=true` (on the component or the
endpoint), the HTTP request
responses that are received are logged, with their headers and body. To
control what is logged, configure a
`LoggingHttpActivityListener` bean with the options you need and set it as
`httpActivityListener`.
-The value of a header that carries a credential is always masked, also when
`logMask` is not enabled. These are the
-headers whose name is a sensitive key of Camel (such as `Authorization`,
`Api-Key` or `Token`), and the
-`Proxy-Authorization`, `Cookie`, `Set-Cookie`, `X-Api-Key` and `X-Auth-Token`
headers, and any header that the
-HTTP client flags as sensitive. The header name is kept, so the log shows
`Authorization: xxxxx`.
+The value of a header that carries a credential is always masked, also when
`logMask` is not enabled. Which headers
+those are is decided by `SensitiveUtils.isSensitiveHeader` in camel-util: a
header whose name matches a sensitive key
+(such as `Authorization`), whose name ends in `token`, `key`, `secret`,
`password`, `auth`, `authorization`,
+`credential` or
+`credentials` (such as `X-Amz-Security-Token` or `Ocp-Apim-Subscription-Key`),
or that is a well-known credential
+header such as `Proxy-Authorization`, `Cookie` or `Set-Cookie`, and any header
that the HTTP client flags as
+sensitive. A header such as `Idempotency-Key`, whose name ends in `key` but
that carries no secret, is not masked.
+The header name is kept, so the log shows `Authorization: xxxxx`.
With `logMask=true`, the values of the other headers and the body are also
masked with the masking formatter of
Camel, which masks values of sensitive keys such as `password=secret`.
diff --git a/components/camel-http/src/main/docs/http-component.adoc
b/components/camel-http/src/main/docs/http-component.adoc
index 0c630a06760c..539021c12d35 100644
--- a/components/camel-http/src/main/docs/http-component.adoc
+++ b/components/camel-http/src/main/docs/http-component.adoc
@@ -986,10 +986,14 @@ With `logHttpActivity=true` (on the component or the
endpoint), the HTTP request
responses that are received are logged, with their headers and body. To
control what is logged, configure a
`LoggingHttpActivityListener` bean with the options you need and set it as
`httpActivityListener`.
-The value of a header that carries a credential is always masked, also when
`logMask` is not enabled. These are the
-headers whose name is a sensitive key of Camel (such as `Authorization`,
`Api-Key` or `Token`), and the
-`Proxy-Authorization`, `Cookie`, `Set-Cookie`, `X-Api-Key` and `X-Auth-Token`
headers, and any header that the
-HTTP client flags as sensitive. The header name is kept, so the log shows
`Authorization: xxxxx`.
+The value of a header that carries a credential is always masked, also when
`logMask` is not enabled. Which headers
+those are is decided by `SensitiveUtils.isSensitiveHeader` in camel-util: a
header whose name matches a sensitive key
+(such as `Authorization`), whose name ends in `token`, `key`, `secret`,
`password`, `auth`, `authorization`,
+`credential` or
+`credentials` (such as `X-Amz-Security-Token` or `Ocp-Apim-Subscription-Key`),
or that is a well-known credential
+header such as `Proxy-Authorization`, `Cookie` or `Set-Cookie`, and any header
that the HTTP client flags as
+sensitive. A header such as `Idempotency-Key`, whose name ends in `key` but
that carries no secret, is not masked.
+The header name is kept, so the log shows `Authorization: xxxxx`.
With `logMask=true`, the values of the other headers and the body are also
masked with the masking formatter of
Camel, which masks values of sensitive keys such as `password=secret`.
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
index 01e2be0772eb..fea29a2509cc 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
@@ -21,8 +21,6 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
-import java.util.Set;
import java.util.StringJoiner;
import org.apache.camel.CamelContext;
@@ -57,13 +55,6 @@ import static
org.apache.camel.support.LoggerHelper.getLineNumberLoggerName;
@Configurer(metadataOnly = true)
public class LoggingHttpActivityListener extends ServiceSupport implements
CamelContextAware, HttpActivityListener {
- /**
- * HTTP headers that carry a credential, but whose name is not a sensitive
key known by {@link SensitiveUtils} (such
- * as Authorization), in lower case.
- */
- private static final Set<String> SENSITIVE_HEADERS
- = Set.of("proxy-authorization", "cookie", "set-cookie",
"x-api-key", "x-auth-token");
-
private static final String DEFAULT_MASK = "xxxxx";
private CamelContext camelContext;
@@ -285,8 +276,7 @@ public class LoggingHttpActivityListener extends
ServiceSupport implements Camel
* key), which is never logged
*/
protected boolean isSensitiveHeader(String name) {
- return name != null
- &&
(SENSITIVE_HEADERS.contains(name.toLowerCase(Locale.ENGLISH)) ||
SensitiveUtils.containsSensitive(name));
+ return SensitiveUtils.isSensitiveHeader(name);
}
private String getMaskString() {
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityMaskHeadersTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityMaskHeadersTest.java
index 56c9d612948f..5417f04e5dc2 100644
---
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityMaskHeadersTest.java
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityMaskHeadersTest.java
@@ -91,6 +91,9 @@ public class HttpLoggingActivityMaskHeadersTest extends
BaseHttpTest {
e.getIn().setHeader("Proxy-Authorization", "Basic
proxy-secret");
e.getIn().setHeader("Cookie",
"SESSIONID=request-session-secret");
e.getIn().setHeader("X-Api-Key", "api-key-secret");
+ e.getIn().setHeader("X-Amz-Security-Token",
"amz-security-token-secret");
+ e.getIn().setHeader("Ocp-Apim-Subscription-Key",
"ocp-subscription-secret");
+ e.getIn().setHeader("Idempotency-Key", "idem-12345");
e.getIn().setHeader("X-Trace", "trace-123");
});
@@ -108,15 +111,20 @@ public class HttpLoggingActivityMaskHeadersTest extends
BaseHttpTest {
assertTrue(lines.contains("Proxy-Authorization: xxxxx"), log);
assertTrue(lines.contains("Cookie: xxxxx"), log);
assertTrue(lines.contains("X-Api-Key: xxxxx"), log);
+ assertTrue(lines.contains("X-Amz-Security-Token: xxxxx"), log);
+ assertTrue(lines.contains("Ocp-Apim-Subscription-Key: xxxxx"), log);
assertTrue(lines.contains("Set-Cookie: xxxxx"), log);
assertFalse(log.contains("secret-token"), log);
assertFalse(log.contains("proxy-secret"), log);
assertFalse(log.contains("request-session-secret"), log);
assertFalse(log.contains("api-key-secret"), log);
+ assertFalse(log.contains("amz-security-token-secret"), log);
+ assertFalse(log.contains("ocp-subscription-secret"), log);
assertFalse(log.contains("response-session-secret"), log);
// other headers are logged as is
assertTrue(lines.contains("X-Trace: trace-123"), log);
+ assertTrue(lines.contains("Idempotency-Key: idem-12345"), log);
}
@Test
diff --git
a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
index 69977fb27530..a660d261848d 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
@@ -310,6 +310,25 @@ public final class SensitiveUtils {
// SENSITIVE-PATTERN: END
;
+ // credential HTTP headers that neither match a sensitive key nor end in a
word that marks a credential,
+ // in lower case without dashes
+ private static final Set<String> SENSITIVE_HEADERS = Set.of(
+ "cookie",
+ "setcookie",
+ "xgoogiapjwtassertion",
+ "xhoneycombteam");
+
+ // well-known HTTP headers whose name ends in a word that marks a
credential but that carry no secret,
+ // in lower case without dashes
+ private static final Set<String> NOT_SENSITIVE_HEADERS = Set.of(
+ "accesscontrolallowcredentials",
+ "idempotencykey",
+ "secwebsocketkey");
+
+ // the words that mark a credential when they end the name of an HTTP
header, in lower case
+ private static final String[] SENSITIVE_HEADER_SUFFIXES = {
+ "token", "key", "secret", "password", "auth", "authorization",
"credential", "credentials" };
+
private SensitiveUtils() {
}
@@ -349,6 +368,41 @@ public final class SensitiveUtils {
return SENSITIVE_KEYS.contains(text);
}
+ /**
+ * Whether the given HTTP header carries a credential, such as an API key,
a session token or a cookie, so that its
+ * value should be masked when the header is logged.
+ * <p>
+ * HTTP headers do not follow the naming of configuration options: most
credential headers carry a vendor prefix
+ * (such as {@code X-Amz-Security-Token}), so they do not match a
sensitive key as a whole. A header is therefore
+ * also sensitive when its name, in lower case without dashes, ends in
{@code token}, {@code key}, {@code secret},
+ * {@code password}, {@code auth}, {@code authorization}, {@code
credential} or {@code credentials}, or when it is a
+ * well-known credential header that the rule misses (such as {@code
Cookie} and {@code Set-Cookie}). A few
+ * well-known headers end in such a word but carry no secret (such as
{@code Idempotency-Key}) and are not
+ * sensitive.
+ *
+ * @param name the name of the HTTP header
+ * @return true if the header carries a credential, false otherwise
+ * @since 4.24
+ */
+ public static boolean isSensitiveHeader(String name) {
+ if (name == null || name.isEmpty()) {
+ return false;
+ }
+ String key = name.toLowerCase(Locale.ENGLISH).replace("-", "");
+ if (NOT_SENSITIVE_HEADERS.contains(key)) {
+ return false;
+ }
+ if (containsSensitive(name) || SENSITIVE_HEADERS.contains(key)) {
+ return true;
+ }
+ for (String suffix : SENSITIVE_HEADER_SUFFIXES) {
+ if (key.endsWith(suffix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Masks passwords embedded in URI userinfo ({@code
scheme://user:password@host}) within free text. Complements
* name-based secret detection: the password has no {@code password=} key,
so key/value maskers never see it.
diff --git
a/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
index 3271f1c1f6a9..dd0c030c89ac 100644
---
a/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
+++
b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
@@ -61,6 +61,67 @@ class SensitiveUtilsTest {
assertThat(SensitiveUtils.containsSensitive("bar")).isFalse();
}
+ @Test
+ void testIsSensitiveHeader() {
+ // matches a sensitive configuration key as a whole
+ assertThat(SensitiveUtils.isSensitiveHeader("Authorization")).isTrue();
+
+ // vendor headers whose name ends in a word that marks a credential
+ // AWS
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Api-Key")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Auth-Token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Amz-Security-Token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Amz-Server-Side-Encryption-Customer-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key")).isTrue();
+ // Azure
+
assertThat(SensitiveUtils.isSensitiveHeader("Ocp-Apim-Subscription-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Functions-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Ms-Encryption-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Ms-Copy-Source-Authorization")).isTrue();
+ // Google
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Goog-Api-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Goog-Encryption-Key")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Serverless-Authorization")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Forwarded-Authorization")).isTrue();
+ // HashiCorp
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Vault-Token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Consul-Token")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Nomad-Token")).isTrue();
+ // others
+ assertThat(SensitiveUtils.isSensitiveHeader("Private-Token")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("Job-Token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Shopify-Access-Token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-RapidAPI-Key")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("DD-API-KEY")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("DD-APPLICATION-KEY")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Sentry-Auth")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Registry-Auth")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("Proxy-Authorization")).isTrue();
+ // case does not matter
+
assertThat(SensitiveUtils.isSensitiveHeader("x-amz-security-token")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-AMZ-SECURITY-TOKEN")).isTrue();
+
+ // credential headers that the rule misses are listed explicitly
+ assertThat(SensitiveUtils.isSensitiveHeader("Cookie")).isTrue();
+ assertThat(SensitiveUtils.isSensitiveHeader("Set-Cookie")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Goog-Iap-Jwt-Assertion")).isTrue();
+
assertThat(SensitiveUtils.isSensitiveHeader("X-Honeycomb-Team")).isTrue();
+
+ // a well-known header that ends in such a word but carries no secret
+
assertThat(SensitiveUtils.isSensitiveHeader("Idempotency-Key")).isFalse();
+
assertThat(SensitiveUtils.isSensitiveHeader("Access-Control-Allow-Credentials")).isFalse();
+
assertThat(SensitiveUtils.isSensitiveHeader("Sec-WebSocket-Key")).isFalse();
+
+ // ordinary headers
+ assertThat(SensitiveUtils.isSensitiveHeader("Content-Type")).isFalse();
+ assertThat(SensitiveUtils.isSensitiveHeader("X-Trace")).isFalse();
+ assertThat(SensitiveUtils.isSensitiveHeader("Accept")).isFalse();
+ assertThat(SensitiveUtils.isSensitiveHeader("User-Agent")).isFalse();
+
assertThat(SensitiveUtils.isSensitiveHeader("WWW-Authenticate")).isFalse();
+ assertThat(SensitiveUtils.isSensitiveHeader(null)).isFalse();
+ assertThat(SensitiveUtils.isSensitiveHeader("")).isFalse();
+ }
+
@Test
void serverAndVaultSecretOptionsAreSensitive() {
assertThat(SensitiveUtils.containsSensitive("camel.server.jwtKeystorePassword")).isTrue();
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 8e061358ea16..23e47aa196bc 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -1756,6 +1756,13 @@ values were logged in clear text, even with
`logMask=true`, as the masking forma
JSON shapes. The other headers and the
body are masked as before, only when `logMask=true`.
+Which headers count as credential headers is decided by
`SensitiveUtils.isSensitiveHeader` in camel-util: a header is
+masked when its name matches a sensitive key (such as `Authorization`), when
its name ends in `token`, `key`,
+`secret`, `password`, `auth`, `authorization`, `credential` or `credentials` —
which covers vendor headers such as
+`X-Amz-Security-Token`, `Ocp-Apim-Subscription-Key` and `X-Vault-Token` — or
when it is a well-known credential
+header such as `Cookie`, `Set-Cookie` or `Proxy-Authorization`. A well-known
header whose name ends in such a word
+but that carries no secret, such as `Idempotency-Key`, is not masked.
+
=== camel-platform-http-main, camel-netty-http, camel-undertow - the
Authorization header is removed after the login is checked
When Camel checks the credential of an incoming request, the `Authorization`
header of the request is now removed from