Skip to content

Commit

Permalink
馃泜 Make sure customDomain can't be spoofed
Browse files Browse the repository at this point in the history
Closes #569
  • Loading branch information
baptisteArno committed Mar 15, 2024
1 parent 663653e commit a8a9259
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/builder/src/features/typebot/api/updateTypebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { z } from 'zod'
import {
isCustomDomainNotAvailable,
isPublicIdNotAvailable,
sanitizeCustomDomain,
sanitizeGroups,
sanitizeSettings,
} from '../helpers/sanitizers'
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions apps/builder/src/features/typebot/helpers/sanitizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a8a9259

Please sign in to comment.