Skip to content

Commit 8a9ccdf

Browse files
committed
fix(auth): Fix UserCredentials serialization clientSecret leak and key mismatch
1 parent cd57169 commit 8a9ccdf

3 files changed

Lines changed: 4 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/DefaultCredentialsProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ void getDefaultCredentials_GdchServiceAccount() throws IOException {
387387
assertNotNull(((GdchCredentials) defaultCredentials).getApiAudience());
388388
}
389389

390+
@Test
390391
void getDefaultCredentials_quota_project() throws IOException {
391392
InputStream userStream =
392393
UserCredentialsTest.writeUserStream(

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)