Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Validate accounts URL in auth responses

Manav Rathidf5c3925f60d
diff --git a/web/packages/accounts-rs/services/user.ts b/web/packages/accounts-rs/services/user.ts
index 95591c9ffb..361400cd2b 100644
--- a/web/packages/accounts-rs/services/user.ts
+++ b/web/packages/accounts-rs/services/user.ts
@@ -559,16 +559,21 @@ export interface EmailOrSRPVerificationResponse {
*
* See: [Note: Duplicated Zod schema and TypeScript type]
*/
-const RemoteEmailOrSRPVerificationResponse = z.object({
- id: z.number(),
- keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
- encryptedToken: z.string().nullish().transform(nullToUndefined),
- token: z.string().nullish().transform(nullToUndefined),
- twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
- passkeySessionID: z.string().nullish().transform(nullToUndefined),
- accountsUrl: z.string().nullish().transform(nullToUndefined),
- twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
-});
+const RemoteEmailOrSRPVerificationResponse = z
+ .object({
+ id: z.number(),
+ keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
+ encryptedToken: z.string().nullish().transform(nullToUndefined),
+ token: z.string().nullish().transform(nullToUndefined),
+ twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
+ passkeySessionID: z.string().nullish().transform(nullToUndefined),
+ accountsUrl: z.string().nullish().transform(nullToUndefined),
+ twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
+ })
+ .refine((r) => (r.passkeySessionID ? !!r.accountsUrl : true), {
+ path: ["accountsUrl"],
+ message: "accountsUrl is required when passkeySessionID is present",
+ });
/**
* A specialization of {@link RemoteEmailOrSRPVerificationResponse} for SRP
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index e9e4661bef..f13f620001 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -524,16 +524,21 @@ export interface EmailOrSRPVerificationResponse {
*
* See: [Note: Duplicated Zod schema and TypeScript type]
*/
-const RemoteEmailOrSRPVerificationResponse = z.object({
- id: z.number(),
- keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
- encryptedToken: z.string().nullish().transform(nullToUndefined),
- token: z.string().nullish().transform(nullToUndefined),
- twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
- passkeySessionID: z.string().nullish().transform(nullToUndefined),
- accountsUrl: z.string().nullish().transform(nullToUndefined),
- twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
-});
+const RemoteEmailOrSRPVerificationResponse = z
+ .object({
+ id: z.number(),
+ keyAttributes: RemoteKeyAttributes.nullish().transform(nullToUndefined),
+ encryptedToken: z.string().nullish().transform(nullToUndefined),
+ token: z.string().nullish().transform(nullToUndefined),
+ twoFactorSessionID: z.string().nullish().transform(nullToUndefined),
+ passkeySessionID: z.string().nullish().transform(nullToUndefined),
+ accountsUrl: z.string().nullish().transform(nullToUndefined),
+ twoFactorSessionIDV2: z.string().nullish().transform(nullToUndefined),
+ })
+ .refine((r) => (r.passkeySessionID ? !!r.accountsUrl : true), {
+ path: ["accountsUrl"],
+ message: "accountsUrl is required when passkeySessionID is present",
+ });
/**
* A specialization of {@link RemoteEmailOrSRPVerificationResponse} for SRP