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

+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: {