You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by rs...@apache.org on 2023/01/26 09:40:47 UTC

[kafka] branch 3.4 updated: KAFKA-14623: OAuth's HttpAccessTokenRetriever potentially leaks secrets in logging (#13119) (#13166)

This is an automated email from the ASF dual-hosted git repository.

rsivaram pushed a commit to branch 3.4
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.4 by this push:
     new 9089a4ddb9c KAFKA-14623: OAuth's HttpAccessTokenRetriever potentially leaks secrets in logging (#13119) (#13166)
9089a4ddb9c is described below

commit 9089a4ddb9cbde195862514f027ced594883b2d9
Author: Kirk True <ki...@kirktrue.pro>
AuthorDate: Thu Jan 26 01:40:22 2023 -0800

    KAFKA-14623: OAuth's HttpAccessTokenRetriever potentially leaks secrets in logging (#13119) (#13166)
    
    Removes logging of the HTTP response directly in all known cases to prevent potentially logging access tokens.
    
    Reviewers:  Sushant Mahajan <su...@gmail.com>, Rajini Sivaram <ra...@googlemail.com>
---
 .../internals/secured/HttpAccessTokenRetriever.java     | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpAccessTokenRetriever.java b/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpAccessTokenRetriever.java
index 2e61449304d..f0362f00f29 100644
--- a/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpAccessTokenRetriever.java
+++ b/clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpAccessTokenRetriever.java
@@ -240,7 +240,13 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
         int responseCode = con.getResponseCode();
         log.debug("handleOutput - responseCode: {}", responseCode);
 
+        // NOTE: the contents of the response should not be logged so that we don't leak any
+        // sensitive data.
         String responseBody = null;
+
+        // NOTE: It is OK to log the error response body and/or its formatted version as
+        // per the OAuth spec, it doesn't include sensitive information.
+        // See https://www.ietf.org/rfc/rfc6749.txt, section 5.2
         String errorResponseBody = null;
 
         try (InputStream is = con.getInputStream()) {
@@ -262,7 +268,7 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
         }
 
         if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) {
-            log.debug("handleOutput - responseCode: {}, response: {}, error response: {}", responseCode, responseBody,
+            log.debug("handleOutput - responseCode: {}, error response: {}", responseCode,
                 errorResponseBody);
 
             if (responseBody == null || responseBody.isEmpty())
@@ -271,8 +277,8 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
 
             return responseBody;
         } else {
-            log.warn("handleOutput - error response code: {}, response body: {}, error response body: {}", responseCode,
-                responseBody, errorResponseBody);
+            log.warn("handleOutput - error response code: {}, error response body: {}", responseCode,
+                formatErrorMessage(errorResponseBody));
 
             if (UNRETRYABLE_HTTP_CODES.contains(responseCode)) {
                 // We know that this is a non-transient error, so let's not keep retrying the
@@ -297,6 +303,8 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
     }
 
     static String formatErrorMessage(String errorResponseBody) {
+        // See https://www.ietf.org/rfc/rfc6749.txt, section 5.2 for the format
+        // of this error message.
         if (errorResponseBody == null || errorResponseBody.trim().equals("")) {
             return "{}";
         }
@@ -317,7 +325,6 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
     }
 
     static String parseAccessToken(String responseBody) throws IOException {
-        log.debug("parseAccessToken - responseBody: {}", responseBody);
         ObjectMapper mapper = new ObjectMapper();
         JsonNode rootNode = mapper.readTree(responseBody);
         JsonNode accessTokenNode = rootNode.at("/access_token");
@@ -382,4 +389,4 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
         return value;
     }
 
-}
\ No newline at end of file
+}