2
0

🛂 Make sure customDomain can't be spoofed

Closes #569
This commit is contained in:
Baptiste Arnaud
2024-03-15 15:05:54 +01:00
parent 663653ec9a
commit a8a92594f3
2 changed files with 22 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import { z } from 'zod'
import {
isCustomDomainNotAvailable,
isPublicIdNotAvailable,
sanitizeCustomDomain,
sanitizeGroups,
sanitizeSettings,
} from '../helpers/sanitizers'
@ -201,8 +202,10 @@ export const updateTypebot = authenticatedProcedure
: typebot.publicId && isPublicIdValid(typebot.publicId)
? typebot.publicId
: undefined,
customDomain:
typebot.customDomain === null ? null : typebot.customDomain,
customDomain: await sanitizeCustomDomain({
customDomain: typebot.customDomain,
workspaceId: existingTypebot.workspace.id,
}),
isClosed: typebot.isClosed,
whatsAppCredentialsId: typebot.whatsAppCredentialsId ?? undefined,
updatedAt: typebot.updatedAt,

View File

@ -163,3 +163,20 @@ export const sanitizeFolderId = async ({
})
return folderCount !== 0 ? folderId : undefined
}
export const sanitizeCustomDomain = async ({
customDomain,
workspaceId,
}: {
customDomain?: string | null
workspaceId: string
}) => {
if (!customDomain) return customDomain
const domainCount = await prisma.customDomain.count({
where: {
name: customDomain?.split('/')[0],
workspaceId,
},
})
return domainCount === 0 ? null : customDomain
}