Repository navigation
fix(docmdp): ignore unreferenced signature dictionaries - #9436
mateuscmtropical wants to merge 1 commit into
Conversation
Signed-off-by: mateuscmtropical <mateuscmtropical@gmail.com>
|
This feedback has now been submitted as a formal Request changes review on #9436. Please follow the review discussion for the proposed changes before merging. |
vitormattos
left a comment
There was a problem hiding this comment.
Thanks for investigating #9271 and adding the regression tests!
After reviewing the existing architecture, I suggest a different approach before merging. Removing unreferenced signature dictionaries using regex can produce incorrect results, particularly with incremental revisions and compressed objects.
The proposed solution is:
-
LibreSign/pdf-signature-validator— Add structural detection of active signatures and DocMDP levels (P=1/2/3), usingsignerphp/pdf-corerather than raw-text matching. It should distinguish orphaned signatures and report inconclusive cases safely, with regression tests. -
This PR (#9436) — Replace the regex-based logic in
DocMdpHandlerwith the new validation API. Also update signature detection inPhpNativeHandlerandJSignPdfHandler, ensuring orphaned signatures neither block signing nor prevent the configured certification.
Important: PR #9375, by Paulo Raoni, already handles freezing the request's DocMDP policy. That work is complementary, so we should avoid duplicating it and integrate this PR with #9375 once it is merged.
Would you be interested in continuing this work, starting with a PR in LibreSign/pdf-signature-validator and then updating #9436?
If you'd prefer to handle only the validation package, we can coordinate the integration separately.
I'd like to keep this PR open and preserve your existing tests and contribution.
|
Thanks for the review! Yes, I'd like to continue. I'll start with a PR in pdf-signature-validator and then update this one after #9375 is merged. |
|
Opened the first step: LibreSign/pdf-signature-validator#85. I'll update this PR to use it after #9375 is merged. |
Resolves: #9271
📝 Summary
DocMdpHandlerscans the raw PDF with regexes, so a leftover signature dictionary with DocMDP/P 1blocked signing even when nothing in the document points to it. This PR drops signature dictionaries that no other object references (N G R) before the DocMDP checks run. A dictionary referenced from a signature field/Vor from/Perms /DocMDPis kept, so a genuine P=1 certification still blocks.PDFs with compressed object streams are left unchanged, because a reference inside an object stream is not visible in the raw bytes. In that case the current behavior stays, which is the safe direction. Supporting them would mean inflating the object streams, and I kept that out of this PR.
🧪 How to test
Run the reporter's files from the issue through
DocMdpHandler::allowsAdditionalSignatures():Validation evidence
New
testOnlyReferencedSignatureDictionariesCertifycases:15 0 R) does not keep object 5/Permsstill blocksThe unsigned control is covered by
testUnsignedPdfIsDetectedAsLevelNone. The rewritten control has no signature object, so it is the same case. The correctly signed negative control istestRealJSignPdfWithDocMdpLevel1, which uses the real JSignPdf P=1 fixture and goes through the new filter.Commands that ran (PHP 8.3 in Docker):
phpunit tests/php/Unit/Handler/DocMdpHandlerTest.php: 46 tests pass. With the old handler, the unreferenced case fails.php-cs-fixer fix --dry-runon the three changed files: no changes.Not run locally: the full PHPUnit suite and Psalm, since they need a Nextcloud checkout.
⚙️ API / Back-end changes
composer openapiwhen necessary✅ Checklist
🤖 AI (if applicable)