You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Access restrictions are enforced inconsistently: Modify open is blocked without the owner password, but Import page copying from the same document is not #379
PDFsharp refuses to open an owner-password-protected document in PdfDocumentOpenMode.Modify without that password. It applies no equivalent check to PdfDocumentOpenMode.Import, so the same document's full content can be copied into a new unencrypted document with no password and no diagnostic. Changing one enum value bypasses the check, and the Encryption docs recommend exactly that substitution as the workaround.
Filed as a bug rather than a feature request because PDFsharp already enforces part of the permission model. The inconsistency is the defect, not the absence of enforcement.
Expected
Given that Modify is blocked, either the Import path applies a comparable check (consulting PermitExtractContent and PermitAssembleDocument when HasOwnerPermissions is false), or the Modify restriction is documented as a technical constraint rather than an access control, and the docs stop offering Import as the way around it.
Actual
Modify throws, blocking in-place modification of the document. Import succeeds and yields the complete content of the protected document, unencrypted, without exceptions, warnings, or log entries.
Both paths protect the same thing, since copying every page into a new file achieves a result equivalent to modifying the original. Guarding one and not the other leaves the guard without practical effect.
Reproduction
usingPdfSharp.Pdf;usingPdfSharp.Pdf.IO;conststringpath="test-with-aes-256.pdf";// (1) Blocked, as documented.try{usingvardoc=PdfReader.Open(path,string.Empty,PdfDocumentOpenMode.Modify);Console.WriteLine("Modify: opened");}catch(Exceptionex){Console.WriteLine($"Modify: refused, {ex.GetType().Name}");}// (2) Not blocked. Same file, same absent password, one enum value changed.usingvarinput=PdfReader.Open(path,string.Empty,PdfDocumentOpenMode.Import);Console.WriteLine(input.SecuritySettings.HasOwnerPermissions);// FalseConsole.WriteLine(input.SecuritySettings.PermitExtractContent);// FalseConsole.WriteLine(input.SecuritySettings.PermitAssembleDocument);// Falseusingvaroutput=newPdfDocument();foreach(varpageininput.Pages)output.AddPage(page);output.Save("output.pdf");// unencrypted, every restriction dropped
No password is needed at any point. The user password is empty, which is the normal configuration for a document restricted by its author rather than kept confidential.
Suggested resolution
Add opt-in validation that turns the same condition into an exception, for callers that want the operation to fail.
PDFsharp works as intended. If the file has no User password, then it can be opened in Adobe Reader and everything can be seen. Similarly, it can be opened in PDFsharp and used for import.
To modify the file, you need the Owner password.
As you show, you can try to open in Modify mode to test if there is an Owner password.
Thanks for your feedback and your suggestion. We'll think about it.
Activity
cbra-nbb commentedon Jul 28, 2026
test-with-aes-256_2.pdf
ThomasHoevel commentedon Aug 3, 2026
PDFsharp works as intended. If the file has no User password, then it can be opened in Adobe Reader and everything can be seen. Similarly, it can be opened in PDFsharp and used for import.
To modify the file, you need the Owner password.
As you show, you can try to open in Modify mode to test if there is an Owner password.
Thanks for your feedback and your suggestion. We'll think about it.