Skip to content

Commit 2d9d01c

Browse files
authored
fix(auth): Fix UserCredentials serialization clientSecret leak (#13465)
This PR fixes a critical security issue where the plaintext clientSecret of UserCredentials was being leaked and written to disk under the key quota_project, instead of the actual quotaProjectId under quota_project_id.
1 parent 99b9a6e commit 2d9d01c

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private InputStream getUserCredentialsStream() throws IOException {
328328
json.put("client_secret", clientSecret);
329329
}
330330
if (quotaProjectId != null) {
331-
json.put("quota_project", clientSecret);
331+
json.put("quota_project_id", quotaProjectId);
332332
}
333333
json.setFactory(JSON_FACTORY);
334334
String text = json.toPrettyString();

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ void saveAndRestoreUserCredential_saveAndRestored_doesNotThrow() throws IOExcept
635635
.setClientId(CLIENT_ID)
636636
.setClientSecret(CLIENT_SECRET)
637637
.setRefreshToken(REFRESH_TOKEN)
638+
.setQuotaProjectId(QUOTA_PROJECT)
638639
.build();
639640

640641
File file = File.createTempFile("GOOGLE_APPLICATION_CREDENTIALS", null, null);
@@ -649,6 +650,7 @@ void saveAndRestoreUserCredential_saveAndRestored_doesNotThrow() throws IOExcept
649650
assertEquals(userCredentials.getClientId(), restoredCredentials.getClientId());
650651
assertEquals(userCredentials.getClientSecret(), restoredCredentials.getClientSecret());
651652
assertEquals(userCredentials.getRefreshToken(), restoredCredentials.getRefreshToken());
653+
assertEquals(userCredentials.getQuotaProjectId(), restoredCredentials.getQuotaProjectId());
652654
}
653655
}
654656

0 commit comments

Comments
 (0)