Skip to content

Commit 9662440

Browse files
committed
Add additional org check on gh app installation callback
1 parent 1849b76 commit 9662440

File tree

1 file changed

+21
-0
lines changed
  • apps/webapp/app/routes/_app.github.callback

1 file changed

+21
-0
lines changed

apps/webapp/app/routes/_app.github.callback/route.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { linkGitHubAppInstallation } from "~/services/gitHub.server";
55
import { logger } from "~/services/logger.server";
66
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
77
import { tryCatch } from "@trigger.dev/core";
8+
import { $replica } from "~/db.server";
9+
import { requireUser } from "~/services/session.server";
810

911
const QuerySchema = z.object({
1012
installation_id: z.coerce.number(),
@@ -42,6 +44,25 @@ export async function loader({ request }: LoaderFunctionArgs) {
4244

4345
const { organizationId, redirectTo } = sessionResult;
4446

47+
const user = await requireUser(request);
48+
const org = await $replica.organization.findFirst({
49+
where: { id: organizationId, members: { some: { userId: user.id } }, deletedAt: null },
50+
orderBy: { createdAt: "desc" },
51+
select: {
52+
id: true,
53+
},
54+
});
55+
56+
if (!org) {
57+
// the secure cookie approach should already protect against this
58+
// just an additional check
59+
logger.error("GitHub app installation attempt on unauthenticated org", {
60+
userId: user.id,
61+
organizationId,
62+
});
63+
return redirectWithErrorMessage(redirectTo, request, "Failed to install GitHub App");
64+
}
65+
4566
switch (setup_action) {
4667
case "install":
4768
case "update": {

0 commit comments

Comments
 (0)