From 4bd37bfd74ce448bfdab9477b6f9dfa687e77ddd Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Tue, 22 Nov 2022 05:00:57 +1300 Subject: [PATCH] Adds input check for getUserBySshKey --- services/api/src/resources/user/resolvers.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/api/src/resources/user/resolvers.ts b/services/api/src/resources/user/resolvers.ts index 419e5278c9..b5c960a3d9 100644 --- a/services/api/src/resources/user/resolvers.ts +++ b/services/api/src/resources/user/resolvers.ts @@ -8,6 +8,14 @@ export const getMe: ResolverFn = async (_root, args, { models, keycloakGrant: gr return models.UserModel.loadUserById(currentUserId); } +class SearchInputError extends Error { + constructor(message: string) { + super(message); + this.name = 'SearchInputError'; + } +} + + export const getUserBySshKey: ResolverFn = async ( _root, { sshKey }, @@ -21,6 +29,10 @@ export const getUserBySshKey: ResolverFn = async ( // @ts-ignore )(sshKey); + if(!keyType || !keyValue) { + throw new SearchInputError("Malformed ssh key provided. Should begin with key-type (eg. ssh-rsa|ssh-ed25519|etc.), then a space, then the key's value"); + } + const rows = await query( sqlClientPool, Sql.selectUserIdBySshKey({ keyType, keyValue }),