Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Read xms_edov in the string form Microsoft emits (#3391)

Luke Vellafa6bfd478b06
diff --git a/apps/web/src/lib/oauth/microsoft-claims.test.ts b/apps/web/src/lib/oauth/microsoft-claims.test.ts
index d531bf894..349297bb6 100644
--- a/apps/web/src/lib/oauth/microsoft-claims.test.ts
+++ b/apps/web/src/lib/oauth/microsoft-claims.test.ts
@@ -8,6 +8,24 @@ describe("isMicrosoftEmailVerified", () => {
).toBe(true);
});
+ it("reads the domain owner verified claim in the string form Microsoft emits", () => {
+ expect(
+ isMicrosoftEmailVerified({ email: "[email protected]", xms_edov: "1" }),
+ ).toBe(true);
+ expect(
+ isMicrosoftEmailVerified({ email: "[email protected]", xms_edov: "true" }),
+ ).toBe(true);
+ expect(
+ isMicrosoftEmailVerified({ email: "[email protected]", xms_edov: "0" }),
+ ).toBe(false);
+ expect(
+ isMicrosoftEmailVerified({
+ email: "[email protected]",
+ xms_edov: "false",
+ }),
+ ).toBe(false);
+ });
+
it("trusts an explicit email_verified claim", () => {
expect(
isMicrosoftEmailVerified({
diff --git a/apps/web/src/lib/oauth/microsoft-claims.ts b/apps/web/src/lib/oauth/microsoft-claims.ts
index 13616efbe..8f21e402b 100644
--- a/apps/web/src/lib/oauth/microsoft-claims.ts
+++ b/apps/web/src/lib/oauth/microsoft-claims.ts
@@ -5,11 +5,11 @@
export function isMicrosoftEmailVerified(claims: {
email?: string | null;
email_verified?: boolean;
- xms_edov?: boolean;
+ xms_edov?: boolean | string | number;
verified_primary_email?: string[];
verified_secondary_email?: string[];
}) {
- if (claims.email_verified === true || claims.xms_edov === true) {
+ if (claims.email_verified === true || isTruthyClaim(claims.xms_edov)) {
return true;
}
const email = claims.email?.toLowerCase();
@@ -21,3 +21,9 @@ export function isMicrosoftEmailVerified(claims: {
...(claims.verified_secondary_email ?? []),
].some((verified) => verified.toLowerCase() === email);
}
+
+// Microsoft documents `xms_edov` as a boolean but emits it as the string "1"
+// for personal accounts.
+function isTruthyClaim(value: boolean | string | number | undefined) {
+ return value === true || value === 1 || value === "1" || value === "true";
+}