Skip to content

Title: Prevent file corruption by adding pre-execution encryption validation #74

@Adinath-j

Description

@Adinath-j

Description:
Currently, running the "Lock PDF" tool on an already-encrypted file, or the "Unlock PDF" tool on a standard (unencrypted) file, results in irreversible file corruption. We need to implement a validation layer that checks the document's encryption state before triggering any cryptographic operations.

Expected Behavior:

  • Lock PDF: Should block execution and show an error toast if the uploaded PDF is already encrypted.
  • Unlock PDF: Should block execution and show an error toast if the uploaded PDF is NOT encrypted.

Proposed Solution:

  1. Implement a checkEncryptionStatus utility in pdf.service.js using pdfjs-dist to lightly read the file buffer and catch PasswordException (which indicates encryption).
  2. Add guard clauses to the submit handlers in LockPdf.jsx and UnlockPdf.jsx to validate the file state via this utility before allowing the user to proceed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions