Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(fusionauth): reconcile lambda rejecting secondary-link sign-in (#3623)
gbirman45b2a987d825
diff --git a/infra/stacks/fusionauth-instance/index.ts b/infra/stacks/fusionauth-instance/index.tsindex 8abb97900a..8e30e12a3f 100644--- a/infra/stacks/fusionauth-instance/index.ts+++ b/infra/stacks/fusionauth-instance/index.ts@@ -213,6 +213,29 @@ const populateJwtLambda = new FusionAuthLambda(export const populateJwtLambdaId = populateJwtLambda.lambdaId;+// Aborts Sign-in-with-Google when the id_token email differs from the FA user's+// email — the signal that the link being matched was created by /link/gmail as a+// secondary inbox, not the user's primary signup link. Must be wired to the+// reconcile slot of the google_gmail IdP via FA admin UI per environment until+// the IdP itself is declared in Pulumi.+const reconcileSecondaryIdpLinkLambda = new FusionAuthLambda(+ 'reconcile-secondary-idp-link-lambda',+ {+ lambdaId: 'b8c1f6d3-5e2a-4d8b-9f7e-2c3d4e5f6a7b',+ name: 'reconcile_secondary_idp_link',+ type: 'OpenIDReconcile',+ debug: stack !== 'prod',+ body: fs.readFileSync(+ './templates/reconcile_secondary_idp_link.js',+ 'utf-8'+ ),+ },+ { provider: fusionAuthProvider }+);++export const reconcileSecondaryIdpLinkLambdaId =+ reconcileSecondaryIdpLinkLambda.lambdaId;+// Custom signing key for applicationconst signingKey = new FusionAuthKey('jwt-signing-key',diff --git a/infra/stacks/fusionauth-instance/templates/reconcile_secondary_idp_link.js b/infra/stacks/fusionauth-instance/templates/reconcile_secondary_idp_link.jsnew file mode 100644index 0000000000..f1d86424b1--- /dev/null+++ b/infra/stacks/fusionauth-instance/templates/reconcile_secondary_idp_link.js@@ -0,0 +1,20 @@+// Aborts an OpenIDConnect login whose id_token email doesn't match the FA user's+// email. Triggers on FA links created via /link/gmail — those links bind a Google+// account to a primary macro user as a secondary inbox; signing in with that+// Google account must not yield a session for the primary user.+//+// Fails closed: missing jwt.email or user.email is treated the same as a+// mismatch. Google always returns email when the openid+email scopes are+// granted, so legitimate primary sign-ins always satisfy the check.+function reconcile(user, registration, jwt, id_token, tokens) {+ var jwtEmail =+ jwt && typeof jwt.email === 'string' ? jwt.email.toLowerCase() : null;+ var userEmail =+ user && typeof user.email === 'string' ? user.email.toLowerCase() : null;++ if (!jwtEmail || !userEmail || jwtEmail !== userEmail) {+ throw new Error(+ 'This Google account is linked as a secondary inbox to another Macro account. Sign in with your primary email or contact support.'+ );+ }+}