Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js: Don't propagate non-numeric errors from auth plugins #1690

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.2.7",
"version": "1.2.8",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
12 changes: 11 additions & 1 deletion packages/grpc-js/src/call-credentials-filter.ts
Expand Up @@ -21,6 +21,7 @@ import { BaseFilter, Filter, FilterFactory } from './filter';
import { Metadata } from './metadata';
import { Status } from './constants';
import { splitHostPort } from './uri-parser';
import { ServiceError } from './call';

export class CallCredentialsFilter extends BaseFilter implements Filter {
private serviceUrl: string;
Expand Down Expand Up @@ -51,12 +52,21 @@ export class CallCredentialsFilter extends BaseFilter implements Filter {
service_url: this.serviceUrl,
});
const resultMetadata = await metadata;
resultMetadata.merge(await credsMetadata);
try {
resultMetadata.merge(await credsMetadata);
} catch (error) {
this.stream.cancelWithStatus(
Status.UNAUTHENTICATED,
`Failed to retrieve auth metadata with error: ${error.message}`
);
return Promise.reject<Metadata>('Failed to retrieve auth metadata');
}
if (resultMetadata.get('authorization').length > 1) {
this.stream.cancelWithStatus(
Status.INTERNAL,
'"authorization" metadata cannot have multiple values'
);
return Promise.reject<Metadata>('"authorization" metadata cannot have multiple values');
}
return resultMetadata;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/channel.ts
Expand Up @@ -384,7 +384,7 @@ export class ChannelImplementation implements Channel {
(error: Error & { code: number }) => {
// We assume the error code isn't 0 (Status.OK)
callStream.cancelWithStatus(
error.code || Status.UNKNOWN,
(typeof error.code === 'number') ? error.code : Status.UNKNOWN,
`Getting metadata from plugin failed with error: ${error.message}`
);
}
Expand Down