Skip to content

Feat/client side encryption#209

Open
onkar0127 wants to merge 2 commits into
imanchalsingh:mainfrom
onkar0127:feat/client-side-encryption
Open

Feat/client side encryption#209
onkar0127 wants to merge 2 commits into
imanchalsingh:mainfrom
onkar0127:feat/client-side-encryption

Conversation

@onkar0127

Copy link
Copy Markdown
Contributor

Description

This PR implements zero-knowledge Client-Side End-to-End Encryption (E2EE) for file uploads and downloads. Using a hybrid encryption scheme, files are encrypted chunk-by-chunk in the browser before they are transmitted over the network and uploaded to Cloudinary, ensuring complete data privacy (zero plaintext content or passphrases ever reach the backend server).

Proposed Changes

Frontend

  • Key Derivation & Wrapping (resumableUpload.ts): Implemented browser-native WebCrypto AES-GCM (256-bit) DEK generation. The DEK is wrapped client-side using a Key Encryption Key (KEK) derived from the user's password using PBKDF2 (100,000 iterations, SHA-256).
  • Isolated Chunk Encryption: Slices the file and encrypts each chunk independently with AES-GCM using deterministic IVs. The 12-byte IV is prepended directly to the front of each encrypted chunk array buffer before network transmission.
  • Client-Side Decryption (SharePage.tsx): Reconstructed the download landing page to show an E2EE password entry field. Downloads the raw encrypted buffer, slices it into (5MB + 28B) encrypted chunks, extracts the prepended IVs, decrypts each chunk using the DEK, and compiles them back into the original decrypted file locally.
  • UI Integrations: Added an E2EE password modal, warning panels, and access checkboxes in the manual upload flow (MyFiles.tsx).

Backend

  • Database Model Extensions (File.js & ShareLink.js): Added isEncrypted (Boolean), wrappedKey (String), and keySalt (String) fields to store base64 metadata.
  • Controller Adjustments (uploadController.js & shareController.js):
    • Saved E2EE parameters on initialization (initUpload) and metadata saving (saveFileInfo).
    • Copied E2EE properties from the parent File document to the ShareLink document on link generation.
    • Updated expected chunk size validations to dynamically account for the E2EE 28-byte overhead.

Testing & Verification

onkar0127 added 2 commits July 1, 2026 23:39
- Track upload status (PENDING / COMPLETED) in File model schema
- Link UploadSession to File model using fileId
- Pre-create PENDING file in initUpload and promote to COMPLETED in saveFileInfo
- Exclude PENDING files from listings, folder retrieval, tag retrieval, and statistics
- Add a background cron job scheduled daily at midnight to sweep stale PENDING uploads
- Support disabling queues via environment variables to prevent test lockups
@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

👷 Deploy request for file-sharingsystem pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4399489

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@onkar0127 is attempting to deploy a commit to the imanchalsingh Team on Vercel.

A member of the Team first needs to authorize it.

@onkar0127

Copy link
Copy Markdown
Contributor Author

@imanchalsingh can please check this one also!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend frontend SSoC26 Official label of org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Implement End-to-End Encryption (E2EE) using WebCrypto API

1 participant