Repository navigation
fix: freeze the PDF certification level with the request snapshot - #9375
paulo-raoni wants to merge 6 commits into
Conversation
vitormattos
left a comment
There was a problem hiding this comment.
Requesting changes for the confirmed mismatch between frozen DocMDP and signer validation. The separate JSignPdf parameter-reuse concern is a hypothesis: please run the proposed discriminating regression test and change production code only if it reproduces.
| * Once frozen, the request certifies with the level it stores, whatever the | ||
| * current level. Without a stored level, the current one applies. | ||
| */ | ||
| private function getDocMdpLevel(): ?DocMdpLevel { |
There was a problem hiding this comment.
The signing engine now uses the frozen request's DocMDP level, but signer validation still relies on the current system configuration in some cases.
DocMdp\Validator::getDocMdpLevel() ignores request/group overrides when creating a request and treats a stored level of 0 as missing.
This can allow two signers on a request whose effective certification is level 1, or reject signers on a frozen level-0 request after the administrator changes the global configuration.
Please align signer validation with the backend-resolved effective policy.
Add regression tests covering:
- System level 2 with an authorized request override to level 1: two signing participants must be rejected.
- A frozen level-0 request followed by a global change to level 1: adding valid signers must remain allowed.
- A valid level-2 request with two signing participants: it must continue to be accepted.
The tests should assert the observable API behavior and persisted policy, rather than only checking calls to the validator.
| return null; | ||
| $level = $this->getDocMdpLevel(); | ||
| if ($level === null && $this->docMdpConfigService->isEnabled()) { | ||
| $level = $this->docMdpConfigService->getLevel(); |
There was a problem hiding this comment.
The request-specific DocMDP level may expose stale certification parameters when a JSignPdfHandler instance is reused.
getJSignParam() caches its parameter object, and addJSignParameters() merges new options without clearing previously supplied ones.
When a first document uses a certifying level and a second document uses NOT_CERTIFIED, the second signing operation does not explicitly remove the previous -cl option.
Please add a regression test using the same handler instance for two consecutive signing operations:
- Sign a document with certification level 1.
- Sign another document with
NOT_CERTIFIED. - Verify that the second operation does not pass
-cland that its resulting PDF contains no DocMDP certification. - Use a fresh handler signing with
NOT_CERTIFIEDas a control.
Please also cover the visible-signature path, which clones the cached parameters.
If the test confirms parameter reuse, reset or rebuild the per-document parameters and retain the regression test.
|
Thanks for the review. Both points are addressed in two new commits: Signer validation ( API tests, red before the change:
JSignPdf reuse ( Two gaps I noticed that are older than this PR, and that I left unchanged:
|
vitormattos
left a comment
There was a problem hiding this comment.
Requesting changes to verify two potentially inconsistent DocMDP signer-validation paths before merging this snapshot-freeze change.
Please implement the focused API regressions proposed inline, using named DataProvider datasets and shared fixture helpers. The assertions should distinguish an incorrect acceptance/rejection from unrelated failures and verify that frozen policy snapshots and signer associations remain unchanged after a rejected request.
Both findings are based on reachable source paths, not an executed reproduction. If the tests pass against the current implementation, please share the evidence and we can close the concern without a production-code change. If either fails, fix the shared policy-resolution path and retain the regression test.
The earlier signer-validation and JSignPdf state-leak feedback appears addressed by the latest commits. CI is green for the scenarios it currently covers.
| } | ||
|
|
||
| $policySnapshot = ($file->getMetadata() ?? [])['policy_snapshot'] ?? null; | ||
| return is_array($policySnapshot) && array_key_exists(DocMdpPolicy::KEY, $policySnapshot) |
There was a problem hiding this comment.
resolveLevel() reads the envelope's own DocMDP snapshot, but EnvelopeService::createEnvelope() only stores the observer-profile policy on the envelope. The effective DocMDP level is stored on each child document.
Consequently, signer validation may fall back to the current system level even though the children will be signed using their frozen levels.
Please add a parameterized API regression test in tests/php/Api/Controller/RequestSignatureControllerTest.php using #[DataProvider('provideFrozenEnvelopeDocMdpCases')].
Suggested named datasets, expressed as (initial system level, request override, subsequent system level, expected status):
frozen override L1, current L3:(2, 1, 3, 422)frozen L2, current L1:(2, null, 1, 200)frozen L0, current L1:(0, null, 1, 200)
Use a shared fixture helper to create a two-document envelope with one signing participant, then PATCH the envelope UUID with two signing participants after changing the system level.
Assert the effective DocMDP level and sourceScope persisted on each child, the HTTP response, the final signer counts on the envelope and children, and that both child snapshots remain unchanged. In the rejected case, verify that no additional signers were persisted and that the failure is specifically caused by DocMDP validation.
The initial single-signer request also serves as a control proving that the override was authorized.
If the regression reproduces, align envelope signer validation with the effective frozen policy of its documents. Avoid introducing a separate policy-resolution implementation solely for envelopes.
| if ($docMdpLevel === null || $docMdpLevel === 0) { | ||
| return $this->configService->getLevel()->value; | ||
| } | ||
| $level = $this->docMdpFilePolicyApplier->resolveLevel($file, $data) |
There was a problem hiding this comment.
getDocMdpLevel() resolves existing requests only by UUID. However, RequestSignatureService::saveFile() can reuse an existing file by nodeId after all its signers have been removed.
This means signer validation may use the current system level while persistence retains the existing file's frozen DocMDP snapshot.
Please add a parameterized API regression test using #[DataProvider('provideFrozenNodeIdDocMdpCases')], preferably alongside the existing DocMDP tests in RequestSignatureControllerTest.php.
Suggested named datasets, expressed as (frozen level, subsequent system level, expected status):
frozen L1, current L2:(1, 2, 422)frozen L0, current L1:(0, 1, 200)frozen L2, current L1:(2, 1, 200)
Use one shared setup helper that creates a request with one signer, removes every signer through the existing removal workflow, and verifies that the file returns to DRAFT while retaining its freeze marker and DocMDP snapshot.
Then change the system configuration and perform a real POST using the same file.nodeId with two signing participants.
Assert the HTTP status and DocMDP-specific error for rejected requests, verify that the original file ID and frozen snapshot remain unchanged, and check the resulting signer count. Rejected requests must not create new file records or signer associations.
Keep the existing successful new-request test as a control, so the regression distinguishes reuse of a frozen file from ordinary request creation.
If the regression reproduces, resolve the existing file consistently in validation and persistence instead of duplicating the lookup logic or changing the stored policy.
|
Thanks for the review. Both regressions reproduced on the previous head, and both are fixed in two new commits. Envelope ( Reuse by nodeId ( On the fixtures: the envelope is created as a draft and then sent, because its documents only freeze when it is sent. Setup goes through One older gap that I left unchanged: in a draft envelope, a PATCH syncs only the envelope, not its documents. The documents then freeze at the level they were created with, while validation uses the current level. |
Later changes to the PDF certification policy no longer apply to it. Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
Overrides, the frozen level and an uncertified level are no longer replaced by the current level. Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
An envelope's documents and a file reused by node id keep their frozen level, so signers are checked against it. Signed-off-by: Paulo Raoni <raoni_jkd@hotmail.com>
130c89f to
34678ff
Compare
vitormattos
left a comment
There was a problem hiding this comment.
Thanks for the latest improvements and for adding the parameterized regressions covering frozen envelopes and requests reused by nodeId.
The unrelated PHPUnit failures caused by the Nextcloud 36 ISimpleFolder interface change have now been fixed in #9527, which has been merged into main.
Could you please rebase this PR onto the latest main and rerun the CI? There is no need to include the PHPUnit compatibility fix in this branch.
Before we proceed with the merge, I would also like to verify one remaining DocMDP scenario that does not appear to be covered by the current tests: an envelope that has never left DRAFT, after the system certification level changes, transitioning to ABLE_TO_SIGN.
The potential inconsistency is:
DocMdp\Validator::getDocMdpLevel()resolves the current policy for draft children.- A PATCH by envelope UUID synchronizes policies on the envelope, but not its child documents.
propagateStatusToChildren()then freezes the children's existing DocMDP snapshots without refreshing them.- The signing engines subsequently use those frozen child levels.
For example, an envelope created at level 1 could potentially accept two signers after the system level changes to 2, while its child documents remain frozen at level 1.
Please add a focused, parameterized API regression using a named DataProvider, with these cases:
- L1 → L2, two signers: validation and the levels eventually frozen on both children must be consistent.
- L2 → L1, two signers: verify the reverse transition.
- L1 → L1, two signers: negative control; reject the additional signer.
- L2 → L2, two signers: positive control; accept both signers.
The fixture should create a two-document envelope in DRAFT with one signer, confirm the initial snapshots and absence of freeze markers, change the system level, then perform a real HTTP PATCH to ABLE_TO_SIGN with two signers and no explicit DocMDP override.
Please assert the response, the persisted DocMDP levels and snapshots on both children, their freeze markers, and the signer counts. A rejected request must not partially update the envelope or its children.
This is still a suspected inconsistency, not a test-confirmed defect. If the regression passes on the rebased branch, please share the evidence and we can close this concern without changing production code. If it reproduces the mismatch, please fix the draft-to-frozen transition and retain the regression test.
Once the rebase, CI and this verification are complete, we can reassess merge readiness.
Refs: #8715
📝 Summary
Next slice of #8715:
docmdpfollows the request-snapshot freeze. As decided in the issue (2026-10-08, item 1), the signing operation uses the frozen request value: once a request is frozen, both signing engines certify with the level the request stores, not with the current system level.One commit per step:
fix: certify a frozen request with the level it stores– until now JSignPdf and the PHP-native engine read only the current system level (DocMdp\ConfigService::getLevel()), whatever the request stored.SignFileService::configureEngine()now hands the request's level to the engine when the request (or its envelope) is frozen and has a storeddocmdp, throughSignEngineHandler::setDocMdpLevel(), next to the existing setters. A given level is used as is, in both directions: a request stored as not certified is not certified while the system level certifies, and the reverse. Without a stored level, or on a draft that was never sent, the current level applies as before. The level is set on everyconfigureEngine(), null included, so it never carries over to the next file.fix: freeze the PDF certification once the request is sent–DocMdpFilePolicyApplier::sync()returns before any resolution when the request is frozen. Nothing ornullsubmitted keeps the stored level; the same level (also as a numeric string) is a no-op; any other value gets 422, "The PDF certification cannot be changed after the signing flow has started." This also covers a PATCH by uuid:docmdpwas already in the core-flow sync.docmdpABLE_TO_SIGNor later without marker, or document of a frozen envelope), back in DRAFT includednulldocmdpwas stored in the snapshotdocmdp_levelcolumnBehaviour change: besides a later admin change no longer reaching a sent request, frozen requests now certify with their own resolved level instead of the system level. When a group or user rule differs from the system value (for example system 2, group 3), a request from that group was certified at 2 and is now certified at 3, which is the level stored for it. No payload changes; nothing new is sent to anonymous or
#[PublicPage]endpoints. The request sidebar has nodocmdpcontrol, so there is no frontend change.Not in this PR: the other snapshot keys and envelope new-file inheritance.
🧪 How to test
composer test:unit -- --filter 'DocMdpFilePolicyApplierTest|SignFileServiceTest|PhpNativeHandlerTest|Pkcs12HandlerTest' vendor/bin/phpunit -c tests/php/phpunit.xml tests/php/Integration/Handler/SignEngine/JSignPdf/JSignPdfHandlerTest.php vendor/bin/phpunit -c tests/php/phpunit.xml tests/php/Api/Controller/RequestSignatureControllerTest.phpPhpNativeHandlerTest/JSignPdfHandlerTest: a given level wins over the current one (another certifying level, not certified while the system certifies, certified while it does not); without one, the current level applies.Pkcs12HandlerTest: the level reaches the concrete engine.SignFileServiceTest: a frozen request (sent, back in DRAFT, sent before the marker existed, document of a sent envelope) hands its stored level to the engine; a request without a stored level and a draft never sent use the current one.DocMdpFilePolicyApplierTest: the strict sync rules above; a draft still resolves the submitted level.RequestSignatureControllerTest: a sent request keeps level 2 after the admin sets 3 and an unrelated PATCH by uuid; another level by uuid gets 422 and the snapshot is unchanged; a draft sent by uuid picks up the admin change.Manually: enable DocMDP, send a request, change the certification level as admin, then sign: the signed PDF carries the level the request was sent with.
Validation evidence
composer psalm, php-cs-fixer dry-run on the touched filesRan locally, on top of current
main:tests/php/Unit/Service/Policy(1030 tests);--filter 'JSignPdfHandlerTest|PhpNativeHandlerTest|Pkcs12HandlerTest'(181 tests);SignFileServiceTest(157 tests);--filter DocMdp(120 tests);RequestSignatureControllerTest(11 tests);composer psalm; php-cs-fixer on the changed files.Not run locally: the whole PHPUnit, Behat and Playwright suites, and no end-to-end signature checking the certification level of a signed PDF; the engines are covered by unit and integration tests.
composer openapi/npm run typescript:generatewere not needed: no contract change.⚙️ API / Back-end changes
docmdplevel by both engines.docmdpis frozen with the request policy snapshot; a different value after the freeze returns 422.composer openapiwhen necessary – not needed, no contract change❓ Open questions
docmdpwas stored in the snapshot still signs with the current level, like the footer. Itsdocmdp_levelcolumn does hold the level from creation time, but rows older than the column hold 0, so using it would sign those requests without certification. Should signing use the column for them?DocMdp\Validator::getDocMdpLevel()treats a stored level 0 as unset and reads the current config. It runs when signers are added, not at signing time, so it is not changed here. As a result, a second signer can be refused on a request sent as not certified if the admin later enables certification.✅ Checklist
🤖 AI (if applicable)