Skip to content

Commit d4c0a33

Browse files
fix(sec): warn users of unsafe credential generation methods (#2604)
* fix(sec): warn users of unsafe credential generation methods * chore: repeat class level deprecation message * docs: match deprecated message with guidance * chore: remove unnecessary comment section * chore: suggest new credentials class with link
1 parent 665acbe commit d4c0a33

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleCredential.java

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,42 +197,64 @@ public static GoogleCredential getApplicationDefault(
197197

198198
/**
199199
* {@link Beta} <br>
200-
* Return a credential defined by a Json file.
201200
*
202-
* <p>Important: If you accept a credential configuration (credential JSON/File/Stream) from an
203-
* external source for authentication to Google Cloud Platform, you must validate it before
204-
* providing it to any Google API or library. Providing an unvalidated credential configuration to
205-
* Google APIs can compromise the security of your systems and data. For more information, refer
206-
* to {@link <a
207-
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}.
201+
* <p>Important: This method does not validate the credential configuration. A security risk holds
202+
* when a credential configuration is accepted from a source that is not under your control and
203+
* used without validation on your side.
204+
*
205+
* <p>If you are loading your credential configuration from an untrusted source and have not
206+
* mitigated the risks (e.g. by validating the configuration yourself), make these changes as soon
207+
* as possible to prevent security risks to your environment.
208+
*
209+
* <p>Regardless of the method used, it is always your responsibility to validate configurations
210+
* received from external sources.
211+
*
212+
* <p>See the {@link <a
213+
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}
214+
* for more details.
215+
*
216+
* <p>Returns a credential defined by a Json file.
208217
*
209218
* @param credentialStream the stream with the credential definition.
210219
* @return the credential defined by the credentialStream.
211220
* @throws IOException if the credential cannot be created from the stream.
221+
* @deprecated This method is being deprecated because of a potential security risk.
222+
* Please use {@link <a href="https://javadoc.io/doc/com.google.auth/google-auth-library-oauth2-http/latest/com/google/auth/oauth2/GoogleCredentials.html">GoogleCredentials</a> instead.
212223
*/
213224
@Beta
225+
@Deprecated
214226
public static GoogleCredential fromStream(InputStream credentialStream) throws IOException {
215227
return fromStream(credentialStream, Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
216228
}
217229

218230
/**
219231
* {@link Beta} <br>
220-
* Return a credential defined by a Json file.
221232
*
222-
* <p>Important: If you accept a credential configuration (credential JSON/File/Stream) from an
223-
* external source for authentication to Google Cloud Platform, you must validate it before
224-
* providing it to any Google API or library. Providing an unvalidated credential configuration to
225-
* Google APIs can compromise the security of your systems and data. For more information, refer
226-
* to {@link <a
227-
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}.
233+
* <p>Important: This method does not validate the credential configuration. A security risk holds
234+
* when a credential configuration is accepted from a source that is not under your control and
235+
* used without validation on your side.
236+
*
237+
* <p>If you are loading your credential configuration from an untrusted source and have not
238+
* mitigated the risks (e.g. by validating the configuration yourself), make these changes as soon
239+
* as possible to prevent security risks to your environment.
240+
*
241+
* <p>Regardless of the method used, it is always your responsibility to validate configurations
242+
* received from external sources.
243+
*
244+
* <p>See the {@link <a
245+
* href="https://cloud.google.com/docs/authentication/external/externally-sourced-credentials">documentation</a>}
246+
* for more details.
247+
*
248+
* <p>Returns a credential defined by a Json file.
228249
*
229250
* @param credentialStream the stream with the credential definition.
230-
* @param transport the transport for Http calls.
231-
* @param jsonFactory the factory for Json parsing and formatting.
232251
* @return the credential defined by the credentialStream.
233252
* @throws IOException if the credential cannot be created from the stream.
253+
* @deprecated This method is being deprecated because of a potential security risk.
254+
* Please use {@link <a href="https://javadoc.io/doc/com.google.auth/google-auth-library-oauth2-http/latest/com/google/auth/oauth2/GoogleCredentials.html">GoogleCredentials</a> instead.
234255
*/
235256
@Beta
257+
@Deprecated
236258
public static GoogleCredential fromStream(
237259
InputStream credentialStream, HttpTransport transport, JsonFactory jsonFactory)
238260
throws IOException {

0 commit comments

Comments
 (0)