Skip to content

Commit

Permalink
Fix apikey not URL safe (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish authored Jun 14, 2024
1 parent c34eb8e commit 371e632
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/controllers/chatflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const getChatflowByApiKey = async (req: Request, res: Response, next: NextFuncti
if (!apikey) {
return res.status(401).send('Unauthorized')
}
const apiResponse = await chatflowsService.getChatflowByApiKey(apikey.id)
const apiResponse = await chatflowsService.getChatflowByApiKey(apikey.id, req.query.keyonly)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand Down
13 changes: 7 additions & 6 deletions packages/server/src/services/chatflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ const getAllChatflows = async (type?: ChatflowType): Promise<IChatFlow[]> => {
}
}

const getChatflowByApiKey = async (apiKeyId: string): Promise<any> => {
const getChatflowByApiKey = async (apiKeyId: string, keyonly?: unknown): Promise<any> => {
try {
// Here we only get chatflows that are bounded by the apikeyid and chatflows that are not bounded by any apikey
const appServer = getRunningExpressApp()
const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow)
let query = appServer.AppDataSource.getRepository(ChatFlow)
.createQueryBuilder('cf')
.where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId })
.orWhere('cf.apikeyid IS NULL')
.orWhere('cf.apikeyid = ""')
.orderBy('cf.name', 'ASC')
.getMany()
if (keyonly === undefined) {
query = query.orWhere('cf.apikeyid IS NULL').orWhere('cf.apikeyid = ""')
}

const dbResponse = await query.orderBy('cf.name', 'ASC').getMany()
if (dbResponse.length < 1) {
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow not found in the database!`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/utils/apiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getAPIKeyPath = (): string => {
*/
export const generateAPIKey = (): string => {
const buffer = randomBytes(32)
return buffer.toString('base64')
return buffer.toString('base64url')
}

/**
Expand Down

0 comments on commit 371e632

Please sign in to comment.