Document.Protect does not work with AllowOnlyFormFields protection type

Hi Aspose Team,

one of our customers reported an issue with setting the document protection. We use ProtectionType.AllowOnlyFormFields as protection type.

I already did some analysis with the document they provided and noticed some strange behaviours.

  1. The error also occurs if you replace all document content
  2. If you are using MS Word itself to protect the document (only allowing fields) the protection works fine.
  3. If you add protection using MS Word, remove protection and save the document, Aspose.Words does not fail any more

I attached the documents for you:
input.docx: Original word document which fails (only content is replaced)
input2.docx: Original word document but it has been protected and unprotected via MS Word once
out.docx: Output document of input.docx generated by Aspose with the following code
out2.docx: Output document of input2.docx generated by Aspose with the following code

var doc = new Document(@"S:\input.docx");
doc.Protect(ProtectionType.AllowOnlyFormFields);
doc.Save(@"S:\out.docx", SaveFormat.Docx);

doc = new Document(@"S:\input2.docx");
doc.Protect(ProtectionType.AllowOnlyFormFields);
doc.Save(@"S:\out2.docx", SaveFormat.Docx);

As word can set a protection on the input.docx I would expect Aspose to be able, too, so I I hope you can provide a fix for this. I also would appreciate if you can tell what is causing this issue (or may have damaged the original document) so we may give our customers a hint what they maybe have done wrong to destroy the document and avoid such issues in future.

Kind Regards,
Daniel

documents.zip (51.3 KB)

@Serraniel,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16404. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi,

is there any feedback so far?

Kind regards,
Daniel

@Serraniel,

Thanks for your inquiry. Currently, you issue is under “In Review” phase. We will inform you via this forum thread once the ETA of this issue is available. Thanks for your patience.

The issues you have found earlier (filed as WORDSNET-16404) have been fixed in this Aspose.Words for .NET 18.6 update and this Aspose.Words for Java 18.6 update.

Hi @tahir.manzoor,

I guess we found a bug which is a result of the original bugfix from this issue. After updating Aspose we got some costumers which reported to us, that the full document becomes protected, even it is configured in a different way inside the document. After analyzing the documents I also understood the cause of the original issue reported in January.

If you are using the document protection type to allow form fields, you can configure the sections which shall be protected, if the document has multiple sections:
image.png (7.1 KB)

However, Word hides the linklabel if there only is one section.

After learning about this I found out, that word saves this option, but ignores it if there only is one section, so you could do the following:

  1. add at least two sections
  2. disable protection for first section
  3. remove all sections except the first one
  4. protect document
    -> this is what originally was the reason for not protecting the document I provided in January, I assume.

So far the summary what already happened. After your bugfix for Aspose 18.6 it seems like Aspose always is protecting all sections, even it is configured in a different way.

Case a:
Two sections and both are checked (default):
2018-10-16_15-26-07.png (3.3 KB)
Word: Both sections are protected (expected behaviour)
Aspose: Both sections are protected (expected behaviour)

Case b:
Disable protection for first section:
2018-10-16_15-27-24.png (3.3 KB)
Word: First section is not protected after applying protection (expected behaviour)
Aspose: Both sections are protected (wrong behaviour)

Case c:
Delete second section, while first section is still disabled:
Word: Document is protected as there only is one section and the option to chose sections is hidden in word (expected behaviour)
Aspose: Document is protected (expected behaviour)

Sample code:

var doc = new Document(@"S:\tmp\in.docx");
doc.Protect(ProtectionType.AllowOnlyFormFields, "");

doc.Save(@"S:\tmp2\protection\out.docx");

Sample files (orginal configured documents, protected with word, protected with aspose):
dev cases.zip (85.3 KB)

Kind Regards,
Daniel

@Serraniel

Thanks for your inquiry. We have tested the scenario ( Case b) and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17587. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-17587) have been fixed in this Aspose.Words for .NET 18.11 update and this Aspose.Words for Java 18.11 update.