Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: ensure file exists & is of the right size after encryption

Abdullah Attae59b4320076d
diff --git a/apps/web/src/interfaces/fs.ts b/apps/web/src/interfaces/fs.ts
index 889825ca3..046583c07 100644
--- a/apps/web/src/interfaces/fs.ts
+++ b/apps/web/src/interfaces/fs.ts
@@ -110,6 +110,11 @@ export async function writeEncryptedFile(
)
.pipeTo(fileHandle.writeable);
+ if (!(await exists(fileHandle))) {
+ await fileHandle.delete();
+ throw new Error("Failed to encrypt file. Please try again.");
+ }
+
AppEventManager.publish(AppEvents.fileEncrypted, {
hash,
total: 1,
@@ -624,6 +629,11 @@ export async function streamingDecryptFile(
if (!fileMetadata) return false;
const fileHandle = await streamablefs.readFile(filename);
+ logger.info("decrypting file", {
+ filename,
+ size: fileHandle?.file.size,
+ actualSize: await fileHandle?.size()
+ });
if (!fileHandle) return false;
const { key, iv } = fileMetadata;