Skip to content

armgit / ente

Public Imported from GitHub
0

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

Harden Locker info type parsing

Neeraj Gupta09a154da859d
diff --git a/web/apps/locker/src/services/info-type-wire.ts b/web/apps/locker/src/services/info-type-wire.ts
index cc2137b927..f49ddf069b 100644
--- a/web/apps/locker/src/services/info-type-wire.ts
+++ b/web/apps/locker/src/services/info-type-wire.ts
@@ -6,8 +6,10 @@ type LockerInfoWireType =
| "account-credential"
| "emergency-contact";
+type LockerInfoInternalType = Exclude<LockerItemType, "file">;
+
const wireTypeByInternalType: Record<
- Exclude<LockerItemType, "file">,
+ LockerInfoInternalType,
LockerInfoWireType
> = {
note: "note",
@@ -16,20 +18,20 @@ const wireTypeByInternalType: Record<
emergencyContact: "emergency-contact",
};
-const internalTypeByWireType: Record<string, Exclude<LockerItemType, "file">> = {
- note: "note",
- "physical-record": "physicalRecord",
- physicalRecord: "physicalRecord",
- "account-credential": "accountCredential",
- accountCredential: "accountCredential",
- "emergency-contact": "emergencyContact",
- emergencyContact: "emergencyContact",
-};
+const internalTypeByWireType = new Map<string, LockerInfoInternalType>([
+ ["note", "note"],
+ ["physical-record", "physicalRecord"],
+ ["physicalRecord", "physicalRecord"],
+ ["account-credential", "accountCredential"],
+ ["accountCredential", "accountCredential"],
+ ["emergency-contact", "emergencyContact"],
+ ["emergencyContact", "emergencyContact"],
+]);
export const toInfoTypeWireValue = (
- type: Exclude<LockerItemType, "file">,
+ type: LockerInfoInternalType,
): LockerInfoWireType => wireTypeByInternalType[type];
export const fromInfoTypeWireValue = (
value: string,
-): LockerItemType | undefined => internalTypeByWireType[value];
+): LockerItemType | undefined => internalTypeByWireType.get(value);
diff --git a/web/apps/locker/src/services/remote-read.ts b/web/apps/locker/src/services/remote-read.ts
index 17b1bd0bd3..2b93e285ae 100644
--- a/web/apps/locker/src/services/remote-read.ts
+++ b/web/apps/locker/src/services/remote-read.ts
@@ -21,6 +21,7 @@ import {
encryptBox,
stringToB64,
} from "./crypto";
+import { fromInfoTypeWireValue } from "./info-type-wire";
import {
type StoredTrashFileRecord,
deleteCollectionSinceTime,
@@ -49,7 +50,6 @@ import {
RemoteCollectionUserSchema,
toLockerCollectionParticipant,
} from "./remote-types";
-import { fromInfoTypeWireValue } from "./info-type-wire";
const RemoteMagicMetadata = z.object({
version: z.number(),
diff --git a/web/apps/locker/src/services/remote.ts b/web/apps/locker/src/services/remote.ts
index f624079747..da1c917e8b 100644
--- a/web/apps/locker/src/services/remote.ts
+++ b/web/apps/locker/src/services/remote.ts
@@ -36,6 +36,7 @@ import {
generateKey,
stringToB64,
} from "./crypto";
+import { toInfoTypeWireValue } from "./info-type-wire";
import {
clearLockerCache,
findCollectionByType,
@@ -76,7 +77,6 @@ import {
type LockerUploadProgress,
uploadLockerFileWithDeps,
} from "./remote-uploads";
-import { toInfoTypeWireValue } from "./info-type-wire";
export {
clearLockerCache,
diff --git a/web/apps/share/src/services/file-share.ts b/web/apps/share/src/services/file-share.ts
index c72485ad80..264dc9586e 100644
--- a/web/apps/share/src/services/file-share.ts
+++ b/web/apps/share/src/services/file-share.ts
@@ -126,7 +126,9 @@ const decryptPubMagicMetadata = async (
}
};
-const normalizeLockerInfoType = (type: string | undefined): string | undefined => {
+const normalizeLockerInfoType = (
+ type: string | undefined,
+): string | undefined => {
switch (type) {
case "note":
return "note";
@@ -167,10 +169,7 @@ const parseLockerInfo = (
return undefined;
}
- return {
- ...parsedInfo,
- type: normalizeLockerInfoType(parsedInfo.type),
- };
+ return { ...parsedInfo, type: normalizeLockerInfoType(parsedInfo.type) };
};
/**