Skip to content

Commit cae596b

Browse files
authored
feat: add console warnings for mitigating file based credential load … (#2143)
* feat: add console warnings for mitigating file based credential load related auth methods, options, and types * fix npm run lint trailing commas
1 parent c2c4469 commit cae596b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/auth/externalclient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export class ExternalAccountClient {
7373
static fromJSON(
7474
options: ExternalAccountClientOptions,
7575
): BaseExternalAccountClient | null {
76+
console.warn(
77+
'The `fromJSON` method does not validate the credential configuration. A security risk occurs when a credential configuration configured with malicious URLs is used. When the credential configuration is accepted from an untrusted source, you should validate it before using it with this method. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
78+
);
7679
if (options && options.type === EXTERNAL_ACCOUNT_TYPE) {
7780
if ((options as AwsClientOptions).credential_source?.environment_id) {
7881
return new AwsClient(options as AwsClientOptions);

src/auth/googleauth.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,19 @@ export class GoogleAuth<T extends AuthClient = AuthClient> {
275275
this._cachedProjectId = opts.projectId || null;
276276
this.cachedCredential = opts.authClient || null;
277277
this.keyFilename = opts.keyFilename || opts.keyFile;
278+
if (this.keyFilename) {
279+
console.warn(
280+
'The `keyFilename` option is deprecated. Please use the `credentials` option instead. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
281+
);
282+
}
278283
this.scopes = opts.scopes;
279284
this.clientOptions = opts.clientOptions || {};
280285
this.jsonContent = opts.credentials || null;
286+
if (this.jsonContent) {
287+
console.warn(
288+
'The `credentials` option is deprecated. Please use the `auth` object constructor instead. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
289+
);
290+
}
281291
this.apiKey = opts.apiKey || this.clientOptions.apiKey || null;
282292

283293
// Cannot use both API Key + Credentials
@@ -766,6 +776,9 @@ export class GoogleAuth<T extends AuthClient = AuthClient> {
766776
json: JWTInput | ImpersonatedJWTInput,
767777
options: AuthClientOptions = {},
768778
): JSONClient {
779+
console.warn(
780+
'The `fromJSON` method is deprecated. Please use the `JWT` constructor instead. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
781+
);
769782
let client: JSONClient;
770783

771784
// user's preferred universe domain
@@ -882,6 +895,9 @@ export class GoogleAuth<T extends AuthClient = AuthClient> {
882895
optionsOrCallback: AuthClientOptions | CredentialCallback = {},
883896
callback?: CredentialCallback,
884897
): Promise<JSONClient> | void {
898+
console.warn(
899+
'The `fromStream` method is deprecated. Please use the `JWT` constructor with a parsed stream instead. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
900+
);
885901
let options: AuthClientOptions = {};
886902
if (typeof optionsOrCallback === 'function') {
887903
callback = optionsOrCallback;

src/auth/impersonated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export class Impersonated extends OAuth2Client implements IdTokenProvider {
121121
*/
122122
constructor(options: ImpersonatedOptions = {}) {
123123
super(options);
124+
console.warn(
125+
'The `Impersonated` constructor does not validate the credential configuration. A security risk occurs when a credential configuration configured with malicious URLs is used. When the credential configuration is accepted from an untrusted source, you should validate it before using it with this method. For more details, see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials.',
126+
);
124127
// Start with an expired refresh token, which will automatically be
125128
// refreshed before the first API call is made.
126129
this.credentials = {

0 commit comments

Comments
 (0)