Implement URL validation on default videos links (#7087)

This commit is contained in:
sean-brydon authored and GitHub committed 2023-02-14 13:19:45 +00:00
1 parent 77600f8168
commit 1c97e549eb
6 files changed
+47 -6

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ export type DefaultEventLocationType = {
category: string;
iconUrl: string;
urlRegExp?: string;
// HACK: `variable` and `defaultValueVariable` are required due to legacy reason where different locations were stored in different places.
variable: "locationType" | "locationAddress" | "address" | "locationLink" | "locationPhoneNumber" | "phone";
defaultValueVariable: "address" | "attendeeAddress" | "link" | "hostPhoneNumber" | "phone";
@@ -1,7 +1,9 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { Dispatch, SetStateAction } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { EventLocationType } from "@calcom/app-store/locations";
import { EventLocationType, getEventLocationType } from "@calcom/app-store/locations";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import {
@@ -31,13 +33,22 @@ export function AppSetDefaultLinkDailog({
const utils = trpc.useContext();
const { t } = useLocale();
const form = useForm<LocationTypeSetLinkDialogFormProps>({});
const eventLocationTypeOptions = getEventLocationType(locationType.type);
const form = useForm<LocationTypeSetLinkDialogFormProps>({
resolver: zodResolver(
z.object({ link: z.string().regex(new RegExp(eventLocationTypeOptions?.urlRegExp ?? "")) })
),
});
const updateDefaultAppMutation = trpc.viewer.updateUserDefaultConferencingApp.useMutation({
onSuccess: () => {
showToast("Default app updated successfully", "success");
utils.viewer.getUsersDefaultConferencingApp.invalidate();
},
onError: () => {
showToast(`Invalid App Link Format`, "error");
},
});
return (
+20
View File
@@ -1192,6 +1192,26 @@ const loggedInViewerRouter = router({
)
.mutation(async ({ ctx, input }) => {
const currentMetadata = userMetadata.parse(ctx.user.metadata);
const credentials = ctx.user.credentials;
const foundApp = getApps(credentials).filter((app) => app.slug === input.appSlug)[0];
const appLocation = foundApp?.appData?.location;
if (!foundApp || !appLocation)
throw new TRPCError({ code: "BAD_REQUEST", message: "App not installed" });
if (appLocation.linkType === "static" && !input.appLink) {
throw new TRPCError({ code: "BAD_REQUEST", message: "App link is required" });
}
if (appLocation.linkType === "static" && appLocation.urlRegExp) {
const validLink = z
.string()
.regex(new RegExp(appLocation.urlRegExp), "Invalid App Link")
.parse(input.appLink);
if (!validLink) {
throw new TRPCError({ code: "BAD_REQUEST", message: "Invalid app link" });
}
}
await ctx.prisma.user.update({
where: {