A password-protected PDF that isn't password-protected is worse than no tool at all
I was going through ForgePlug's own tools looking for pages Google wasn't indexing well, and Protect PDF was on the list. Its page claims AES encryption in three different places — the meta description, the guide, the FAQ. Reading the actual code to write better copy for that page, I found something I didn't expect: the encryption was never happening. The tool had been generating PDFs that looked password-protected and weren't, for months.
What was actually happening
Protect PDF is built on pdf-lib, a popular JavaScript library for creating and editing PDFs entirely in the browser. The encryption code looked reasonable at a glance — it loaded the PDF, then called pdf-lib's save() with a password and a permissions object:
const pdfBytes = await (pdfDoc.save as any)({
useObjectStreams: true,
addDefaultPage: false,
encryption: {
userPassword: options.userPassword,
ownerPassword: options.ownerPassword,
permissions: { /* ... */ },
},
});Notice the "as any" cast. That was the tell. pdf-lib 1.17.1 — the current version, there is no newer one — never added write-side encryption support. Its real save() only ever reads four options: useObjectStreams, addDefaultPage, objectsPerTick, and updateFieldAppearances. An encryption key passed alongside those isn't rejected or flagged; it's just not one of the properties the function looks at, so it's silently ignored. The cast to any was there specifically to stop TypeScript from catching this, because without it the compiler would have refused to let that key exist on the options object at all.
The output file had zero encryption applied
The UI reported success with "AES" encryption and the correct page count. The download even had a plausible file size. Opening it required no password whatsoever, because none had been set — pdf-lib produced the same plain, unencrypted PDF it would have produced with no password arguments at all. Every claim the result object made (hasUserPassword, hasOwnerPassword, encryptionLevel: "AES") was set directly from the input options, not read back from anything the output file actually contained.
How we fixed it
pdf-lib is still the right tool for everything it does well — loading, editing, and re-saving PDF structure in the browser. It was never going to grow encryption support retroactively, so the fix is a second pass: let pdf-lib produce the plain PDF as before, then run the finished bytes through a library that actually implements the PDF encryption spec, using the Web Crypto API your browser already has built in.
const plainBytes = await pdfDoc.save({ useObjectStreams: true, addDefaultPage: false });
const { encryptPDF } = await import("@pdfsmaller/pdf-encrypt");
const encryptedBytes = await encryptPDF(plainBytes, options.userPassword ?? "", {
ownerPassword: options.ownerPassword ?? options.userPassword,
algorithm: "AES-256",
allowPrinting: options.permissions.printing,
allowCopying: options.permissions.copyContent,
// ...the rest of the permission flags
});This keeps the tool 100% client-side — the encryption runs through crypto.subtle in your own browser, nothing is uploaded, nothing changes about ForgePlug's privacy model. It's a genuinely different library, not a config flag pdf-lib was hiding.
How we verified it, not just claimed it
Having been burned once by code that looked correct and wasn't, I didn't want to just trust that the fix worked either. I wrote a round-trip test using pdfjs-dist — a completely separate PDF library from either of the two used to build the file — and checked three things against a real encrypted output:
- Opening the file with no password at all must fail.
- Opening the file with the wrong password must fail.
- Opening the file with the correct password must succeed, and the extracted text must match what was actually written to the PDF.
All three passed. That's the actual bar for "this PDF is encrypted" — not that a UI says so, but that an independent reader enforces the password and nothing else does.
How to check your own PDF tool
If you use any browser-based "add a password to my PDF" tool — ForgePlug's or anyone else's — this is worth thirty seconds to check yourself, because the failure mode is silent by design: the UI has no reason to look broken.
- Encrypt a test PDF with a password through the tool.
- Close the tab, open the downloaded file fresh in a different PDF reader than the one you used (your OS's default viewer is fine) — don't reuse a cached, already-unlocked tab.
- If it opens without ever asking for the password, nothing was actually encrypted, whatever the tool told you.
Why this is worth checking, specifically
pdf-lib is one of the most widely used client-side PDF libraries on the web. Any "protect PDF" tool built on it that passes an encryption option straight to save() without a second library doing the actual encryption has the identical bug this article describes — the exact same silent no-op. We can't speak for what other sites are running, but the pattern itself is common enough, and easy enough to miss in review, that it's worth the thirty-second check above rather than assuming a green checkmark means what it says.
- A library not supporting a feature and a library silently ignoring an unsupported option are very different failure modes — the second one is the dangerous one, because nothing errors.
- "AES" in a UI message is a claim, not a fact, until something that isn't the tool itself tries to open the file without the password.
- Client-side encryption done right doesn't need a server: the Web Crypto API (crypto.subtle) in every modern browser can do real AES-256, which is exactly what fixed this.
- If you maintain a PDF tool on pdf-lib, search your own code for "encryption" and "as any" near a save() call — that combination is the specific signature of this bug.
Try the fixed Protect PDF tool
Real AES-256 encryption via the Web Crypto API, verified with a password round-trip test — no uploads, no signup.
Open Protect PDFNeed to remove a password instead?
Unlock a PDF you already have the password for, entirely in your browser.
Open Unlock PDF