gnodet-bot commented on code in PR #30894:
URL: https://github.com/apache/camel/pull/30894#discussion_r4714105690


##########
core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java:
##########
@@ -61,6 +61,62 @@ void testContainsSensitive() {
         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();
+        // Google
+        
assertThat(SensitiveUtils.isSensitiveHeader("X-Goog-Api-Key")).isTrue();
+        
assertThat(SensitiveUtils.isSensitiveHeader("X-Goog-Encryption-Key")).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();
+        // 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("Proxy-Authorization")).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();

Review Comment:
   💡 Add a test case for `Access-Control-Allow-Credentials` (a CORS header, not 
a credential) alongside `Idempotency-Key`:
   
   ```suggestion
           // well-known headers that end in a credential suffix but carry no 
secret
           
assertThat(SensitiveUtils.isSensitiveHeader("Idempotency-Key")).isFalse();
           
assertThat(SensitiveUtils.isSensitiveHeader("Access-Control-Allow-Credentials")).isFalse();
   ```



##########
core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java:
##########
@@ -310,6 +310,24 @@ 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",
+            "proxyauthorization",
+            "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(
+            "idempotencykey");

Review Comment:
   ⚠️ **Missing exclusion — false positive on 
`Access-Control-Allow-Credentials`**
   
   `Access-Control-Allow-Credentials` is a standard CORS response header 
carrying only `true`/`false`, not a credential. After dash-stripping, 
`accesscontrolallowcredentials` ends in `credentials`, so it would be 
incorrectly masked. Add it to the exclusion list.
   
   ```suggestion
       private static final Set<String> NOT_SENSITIVE_HEADERS = Set.of(
               "accesscontrolallowcredentials",
               "idempotencykey");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to