File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
apps/webapp/app/routes/_app.github.callback Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import { linkGitHubAppInstallation } from "~/services/gitHub.server";
55import { logger } from "~/services/logger.server" ;
66import { redirectWithErrorMessage , redirectWithSuccessMessage } from "~/models/message.server" ;
77import { tryCatch } from "@trigger.dev/core" ;
8+ import { $replica } from "~/db.server" ;
9+ import { requireUser } from "~/services/session.server" ;
810
911const 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" : {
You can’t perform that action at this time.
0 commit comments