fix: prevent sending raw errors in responses (#24282)
* fix: prevent sending raw errors in responses * correct already existing typo * style: fix import ordering per biome lint Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
14 files changed
+54
-70
No files matched your search
@@ -5,6 +5,7 @@ import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwI
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { deriveAppDictKeyFromType } from "@calcom/lib/deriveAppDictKeyFromType";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { AppDeclarativeHandler, AppHandler } from "@calcom/types/AppHandler";
|
||||
|
||||
@@ -80,13 +81,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error instanceof HttpError) {
|
||||
return res.status(error.statusCode).json({ message: error.message });
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return res.status(400).json({ message: error.message });
|
||||
}
|
||||
return res.status(404).json({ message: `API handler not found` });
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import config from "../config.json";
|
||||
@@ -32,10 +33,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for Alby");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
|
||||
return res.status(200).json({ url: "/apps/alby/setup" });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -44,10 +45,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for giphy");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "other", slug: "giphy" }) });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { z, ZodError } from "zod";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
|
||||
import { GiphyManager } from "../lib";
|
||||
|
||||
const giphyUrlRegexp = new RegExp(
|
||||
@@ -35,11 +37,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const gifImageUrl = await GiphyManager.getGiphyById(giphyId);
|
||||
return res.status(200).json({ image: gifImageUrl });
|
||||
} catch (error: unknown) {
|
||||
console.error({ error });
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { z, ZodError } from "zod";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { GiphyManager } from "../lib";
|
||||
@@ -39,10 +40,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
nextOffset: total === offset + 1 ? 0 : offset + 1,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -32,10 +33,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for google_video");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import config from "../config.json";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -37,13 +36,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
});
|
||||
|
||||
if (!installation) {
|
||||
throw new Error("Unable to create user credential for HitPay");
|
||||
throw new Error("Unable to create user credential for hitpay");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error);
|
||||
|
||||
return res.status(500).json({ message });
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
|
||||
return res.status(200).json({ url: `/apps/hitpay/setup${teamIdNumber ? `?teamId=${teamIdNumber}` : ""}` });
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -16,7 +17,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
const { teamId, returnTo } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
await throwIfNotHaveAdminAccessToTeam({
|
||||
teamId: teamId ? Number(teamId) : null,
|
||||
userId: req.session.user.id,
|
||||
});
|
||||
|
||||
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
|
||||
const appType = "jitsi_video";
|
||||
@@ -42,10 +46,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for jitsivideo");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import config from "../config.json";
|
||||
@@ -12,7 +13,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const { teamId } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
await throwIfNotHaveAdminAccessToTeam({
|
||||
teamId: teamId ? Number(teamId) : null,
|
||||
userId: req.session.user.id,
|
||||
});
|
||||
|
||||
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
|
||||
|
||||
const appType = config.type;
|
||||
@@ -39,10 +44,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for Paypal");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
|
||||
return res.status(200).json({ url: "/apps/paypal/setup" });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -38,10 +39,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for sylaps");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -36,10 +37,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error("Unable to create user credential for wipe-my-cal");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
|
||||
return res.status(200).json({ url: getInstalledAppPath({ variant: "other", slug: "wipe-my-cal" }) });
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import queue from "queue";
|
||||
import { z, ZodError } from "zod";
|
||||
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
|
||||
@@ -55,10 +56,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
await q.start();
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return res.status(500).json({ message: error.message });
|
||||
}
|
||||
return res.status(500);
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
return res.status(httpError.statusCode).json({ message: httpError.message });
|
||||
}
|
||||
return res.status(200).json({ success: true });
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createDefaultInstallation } from "@calcom/app-store/_utils/installation";
|
||||
import type { AppDeclarativeHandler } from "@calcom/types/AppHandler";
|
||||
|
||||
import appConfig from "../config.json";
|
||||
|
||||
const handler: AppDeclarativeHandler = {
|
||||
@@ -13,8 +12,6 @@ const handler: AppDeclarativeHandler = {
|
||||
newTab: true,
|
||||
url: "https://zapier.com/apps/calcom/integrations",
|
||||
},
|
||||
// Creates minimal credential record for tracking purposes only
|
||||
// No actual credentials are stored since this is a redirect app
|
||||
createCredential: ({ appType, user, slug, teamId }) =>
|
||||
createDefaultInstallation({ appType, user: user, slug, key: {}, teamId }),
|
||||
};
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { getOrgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import {
|
||||
getRoutedUsersWithContactOwnerAndFixedUsers,
|
||||
findMatchingHostsWithEventSegment,
|
||||
getNormalizedHosts,
|
||||
getRoutedUsersWithContactOwnerAndFixedUsers,
|
||||
} from "@calcom/features/users/lib/getRoutedUsers";
|
||||
import { withSelectedCalendars, UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { UserRepository, withSelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getServerErrorFromUnknown } from "@calcom/lib/server/getServerErrorFromUnknown";
|
||||
import prisma, { userSelect } from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[loadUsers]:handleNewBooking "] });
|
||||
@@ -69,10 +68,8 @@ export const loadUsers = async ({
|
||||
return users;
|
||||
} catch (error) {
|
||||
log.error("Unable to load users", safeStringify(error));
|
||||
if (error instanceof HttpError || error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new HttpError({ statusCode: 400, message: error.message });
|
||||
}
|
||||
throw new HttpError({ statusCode: 500, message: "Unable to load users" });
|
||||
const httpError = getServerErrorFromUnknown(error);
|
||||
throw httpError;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user