Skip to content

Commit 61093d7

Browse files
authored
chore: Add additional warnings for sensitive tokens (#1905)
* chore: Add additional warnings for sensitive tokens * chore: Fix lint issues * chore: Document the test rationale * chore: Move these file changes to a new PR
1 parent cc333fe commit 61093d7

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/AccessToken.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public int hashCode() {
114114
return Objects.hash(tokenValue, expirationTimeMillis, scopes);
115115
}
116116

117+
/**
118+
* Returns a string representation of this access token, including the raw token value.
119+
*
120+
* <p><b>Security Warning:</b> The output of this method includes the raw, unmasked access token
121+
* value. Do not log this output in production environments as it may expose sensitive
122+
* credentials.
123+
*/
117124
@Override
118125
public String toString() {
119126
return MoreObjects.toStringHelper(this)

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ public int hashCode() {
284284
quotaProjectId);
285285
}
286286

287+
/**
288+
* Returns a string representation of this credential.
289+
*
290+
* <p><b>Security Warning:</b> The output of this method includes sensitive fields such as the
291+
* client secret, refresh token, and request metadata containing the raw Bearer access token. Do
292+
* not log this output in production environments as it may expose sensitive credentials.
293+
*/
287294
@Override
288295
public String toString() {
289296
return MoreObjects.toStringHelper(this)

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,13 @@ public int hashCode() {
710710
iamEndpointOverride);
711711
}
712712

713+
/**
714+
* Returns a string representation of this credential.
715+
*
716+
* <p><b>Security Warning:</b> The output of this method includes the source credentials which may
717+
* recursively contain sensitive fields such as access tokens. Do not log this output in
718+
* production environments as it may expose sensitive credentials.
719+
*/
713720
@Override
714721
public String toString() {
715722
return MoreObjects.toStringHelper(this)

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/LoggingUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static void logResponsePayload(
7979
/**
8080
* Generic log method to use when not logging standard request, response and payload.
8181
*
82-
* <p>Note: This does not mask the data. Log carefully if the data contains sensitive tokens.
82+
* <p>Any key in the provided {@code contextMap} that matches the sensitive keys set (e.g.
83+
* access_token, refresh_token) will have its value masked via SHA-256 hash before being logged.
8384
*/
8485
static void log(
8586
LoggerProvider loggerProvider, Level level, Map<String, Object> contextMap, String message) {

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ protected Map<String, List<String>> getRequestMetadataInternal() {
446446
return null;
447447
}
448448

449+
/**
450+
* Returns a string representation of this credential, including request metadata and access
451+
* token.
452+
*
453+
* <p><b>Security Warning:</b> The output of this method includes the request metadata which
454+
* contains the raw Bearer access token, and the raw access token value. Do not log this output in
455+
* production environments as it may expose sensitive credentials.
456+
*/
449457
@Override
450458
public String toString() {
451459
OAuthValue localValue = value;

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ public int hashCode() {
361361
quotaProjectId);
362362
}
363363

364+
/**
365+
* Returns a string representation of this credential.
366+
*
367+
* <p><b>Security Warning:</b> The output of this method includes sensitive fields such as the
368+
* refresh token and request metadata containing the raw Bearer access token. Do not log this
369+
* output in production environments as it may expose sensitive credentials.
370+
*/
364371
@Override
365372
public String toString() {
366373
return MoreObjects.toStringHelper(this)

0 commit comments

Comments
 (0)