Virtual whiteboard for sketching hand-drawn like diagrams
feat: Remove support for V1 unencrypted backend (#4189)
Lipisf1eb9695653e
diff --git a/.env b/.envindex f1a93547b2..c3d24015f5 100644--- a/.env+++ b/.env@@ -1,4 +1,3 @@-REACT_APP_BACKEND_V1_GET_URL=https://json-dev.excalidraw.com/api/v1/REACT_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/REACT_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/diff --git a/.env.production b/.env.productionindex 31198f140f..248bb34727 100644--- a/.env.production+++ b/.env.production@@ -1,4 +1,3 @@-REACT_APP_BACKEND_V1_GET_URL=https://json.excalidraw.com/api/v1/REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/diff --git a/src/excalidraw-app/data/index.ts b/src/excalidraw-app/data/index.tsindex 25d55f3e3e..030c573f99 100644--- a/src/excalidraw-app/data/index.ts+++ b/src/excalidraw-app/data/index.ts@@ -22,7 +22,6 @@ import { saveFilesToFirebase } from "./firebase";const byteToHex = (byte: number): string => `0${byte.toString(16)}`.slice(-2);-const BACKEND_GET = process.env.REACT_APP_BACKEND_V1_GET_URL;const BACKEND_V2_GET = process.env.REACT_APP_BACKEND_V2_GET_URL;const BACKEND_V2_POST = process.env.REACT_APP_BACKEND_V2_POST_URL;@@ -176,44 +175,36 @@ export const decryptImported = async (};const importFromBackend = async (- id: string | null,- privateKey?: string | null,+ id: string,+ privateKey: string,): Promise<ImportedDataState> => {try {- const response = await fetch(- privateKey ? `${BACKEND_V2_GET}${id}` : `${BACKEND_GET}${id}.json`,- );+ const response = await fetch(`${BACKEND_V2_GET}${id}`);if (!response.ok) {window.alert(t("alerts.importBackendFailed"));return {};}- let data: ImportedDataState;- if (privateKey) {- const buffer = await response.arrayBuffer();-- let decrypted: ArrayBuffer;- try {- // Buffer should contain both the IV (fixed length) and encrypted data- const iv = buffer.slice(0, IV_LENGTH_BYTES);- const encrypted = buffer.slice(IV_LENGTH_BYTES, buffer.byteLength);- decrypted = await decryptImported(iv, encrypted, privateKey);- } catch (error: any) {- // Fixed IV (old format, backward compatibility)- const fixedIv = new Uint8Array(IV_LENGTH_BYTES);- decrypted = await decryptImported(fixedIv, buffer, privateKey);- }-- // We need to convert the decrypted array buffer to a string- const string = new window.TextDecoder("utf-8").decode(- new Uint8Array(decrypted),- );- data = JSON.parse(string);- } else {- // Legacy format- data = await response.json();+ const buffer = await response.arrayBuffer();++ let decrypted: ArrayBuffer;+ try {+ // Buffer should contain both the IV (fixed length) and encrypted data+ const iv = buffer.slice(0, IV_LENGTH_BYTES);+ const encrypted = buffer.slice(IV_LENGTH_BYTES, buffer.byteLength);+ decrypted = await decryptImported(iv, encrypted, privateKey);+ } catch (error: any) {+ // Fixed IV (old format, backward compatibility)+ const fixedIv = new Uint8Array(IV_LENGTH_BYTES);+ decrypted = await decryptImported(fixedIv, buffer, privateKey);}+ // We need to convert the decrypted array buffer to a string+ const string = new window.TextDecoder("utf-8").decode(+ new Uint8Array(decrypted),+ );+ const data: ImportedDataState = JSON.parse(string);+return {elements: data.elements || null,appState: data.appState || null,@@ -234,7 +225,7 @@ export const loadScene = async (localDataState: ImportedDataState | undefined | null,) => {let data;- if (id != null) {+ if (id != null && privateKey != null) {// the private key is used to decrypt the content from the server, take// extra care not to leak itdata = restore(diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsxindex a17404b2e1..ac0429c83e 100644--- a/src/excalidraw-app/index.tsx+++ b/src/excalidraw-app/index.tsx@@ -184,10 +184,7 @@ const initializeScene = async (opts: {// otherwise, prompt whether user wants to override current scenewindow.confirm(t("alerts.loadSceneOverridePrompt"))) {- // Backwards compatibility with legacy url format- if (id) {- scene = await loadScene(id, null, localDataState);- } else if (jsonBackendMatch) {+ if (jsonBackendMatch) {scene = await loadScene(jsonBackendMatch[1],jsonBackendMatch[2],diff --git a/src/global.d.ts b/src/global.d.tsindex cdce652ffd..af38a96e1a 100644--- a/src/global.d.ts+++ b/src/global.d.ts@@ -19,7 +19,6 @@ interface Window {// https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.tsdeclare namespace NodeJS {interface ProcessEnv {- readonly REACT_APP_BACKEND_V1_GET_URL: string;readonly REACT_APP_BACKEND_V2_GET_URL: string;readonly REACT_APP_BACKEND_V2_POST_URL: string;readonly REACT_APP_SOCKET_SERVER_URL: string;