Skip to content

Implement real PDF password protection in /api/pdf-lock using AES-256#9

Merged
aman124598 merged 3 commits into
mainfrom
copilot/fix-pdf-locking-issue
Apr 23, 2026
Merged

Implement real PDF password protection in /api/pdf-lock using AES-256#9
aman124598 merged 3 commits into
mainfrom
copilot/fix-pdf-locking-issue

Conversation

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Contributor
  • Inspect the failing pdf-unlock build error and current implementation
  • Apply a minimal type-safe fix for decryptPDF output assignment in /src/app/api/pdf-unlock/route.ts
  • Run targeted TypeScript/build validation for the fix
  • Re-run repository validation (npm run lint, npm run build) and report remaining unrelated failures

Copilot AI linked an issue Apr 23, 2026 that may be closed by this pull request
@vercel

vercel Bot commented Apr 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
toolverse Ready Ready Preview, Comment Apr 23, 2026 7:43pm

Copilot AI changed the title [WIP] Fix PDF not getting locked properly Implement real PDF password protection in /api/pdf-lock using AES-256 Apr 23, 2026
Copilot AI requested a review from aman124598 April 23, 2026 19:36
Agent-Logs-Url: https://github.com/aman124598/Toolverse/sessions/9c3a7118-e459-4942-b971-b5fb8080d019

Co-authored-by: aman124598 <84931030+aman124598@users.noreply.github.com>
@aman124598 aman124598 marked this pull request as ready for review April 23, 2026 19:52
Copilot AI review requested due to automatic review settings April 23, 2026 19:52
@aman124598 aman124598 merged commit 2b4063e into main Apr 23, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR switches /api/pdf-lock from producing an unencrypted “locked” copy to applying real AES-256 PDF encryption via cryptpdf, and updates /api/pdf-unlock to attempt cryptpdf decryption first (with a TypeScript-safe byte conversion) before falling back to the prior pdf-lib strategies.

Changes:

  • Add cryptpdf dependency.
  • Update /api/pdf-lock to encrypt PDFs using cryptpdf.encryptPDF (AES-256).
  • Update /api/pdf-unlock to attempt cryptpdf.decryptPDF first and feed the decrypted bytes into pdf-lib.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/app/api/pdf-unlock/route.ts Tries AES-256 decrypt via cryptpdf first; uses Uint8Array for type-safe loading into pdf-lib.
src/app/api/pdf-lock/route.ts Replaces prior “metadata-only” locking behavior with actual AES-256 encryption via cryptpdf.
package.json Adds cryptpdf dependency.
package-lock.json Locks cryptpdf@0.1.1 and its metadata (engines/peer deps).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 59 to +68
@@ -88,10 +63,9 @@ export async function POST(request: NextRequest) {
headers: {
'Content-Type': 'application/pdf',
'Content-Disposition': `attachment; filename="protected_${file.name}"`,
'X-Page-Count': pdfDoc.getPageCount().toString(),
'X-Protection-Level': ownerPassword ? 'owner+user' : 'user',
'X-Permissions': permissionList.join(',') || 'none',
'X-Note': 'PDF encryption requires native libraries. This creates a clean copy with protection metadata. For full encryption, use a desktop PDF tool or server-side qpdf.',
'X-Encryption': 'AES-256',

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permissions is parsed and echoed back in X-Permissions, but it is not used to configure encryptPDF(...). This makes the API response misleading (the produced PDF may not actually enforce the requested permission restrictions). Either pass the parsed permission set into the encryption call (if cryptpdf supports it) or stop accepting/returning permissions and update the client accordingly.

Copilot uses AI. Check for mistakes.
@aman124598 aman124598 deleted the copilot/fix-pdf-locking-issue branch May 19, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock pdf is not actually geting locked

3 participants