Skip to content

[stable31] fix: prevent footer on signed pdfs#6039

Merged
vitormattos merged 5 commits intostable31from
backport/6035/stable31
Dec 9, 2025
Merged

[stable31] fix: prevent footer on signed pdfs#6039
vitormattos merged 5 commits intostable31from
backport/6035/stable31

Conversation

@backportbot-libresign
Copy link
Copy Markdown

Backport of PR #6035

This service provides a dedicated, testable way to detect if a PDF
already contains signatures. It encapsulates the signature detection
logic that was previously scattered across multiple handlers.

The service creates a memory resource from PDF content and uses the
SignEngineFactory to check for existing certificate chains. It handles
exceptions gracefully and returns false for any detection failures.

Tests use real PDF fixtures (signed and unsigned) instead of mocks,
providing better confidence in the detection logic.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Changed createMinimalPdf() and createPdfWithDocMdp() from protected
to public visibility. This simplifies test code by allowing direct
usage without wrapper methods or complex workarounds.

The methods are already designed for test usage only and making them
public improves usability in data providers and static contexts.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
When a PDF already has signatures, applying a footer causes the PDF to
be rewritten, which invalidates existing signatures. This results in
"Digest mismatch" errors when validating the original signatures.

This fix detects existing signatures before applying footer/stamp and
skips the footer application when signatures are present. The signed
content is returned directly without modification.

The detection uses the new PdfSignatureDetectionService to check for
existing certificate chains in the PDF content.

Fixes the issue where adding a second signature invalidates the first
signature due to PDF rewriting during footer application.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Added PdfSignatureDetectionService as a new dependency in the
SignFileService constructor. Updated all test setup code to create
and inject a mock of this service.

This maintains test isolation while allowing the service to use the
new signature detection logic.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@github-project-automation github-project-automation Bot moved this to 0. Needs triage in Roadmap Dec 9, 2025
@backportbot-libresign backportbot-libresign Bot added this to the Next Patch (31) milestone Dec 9, 2025
@vitormattos vitormattos merged commit 418774a into stable31 Dec 9, 2025
62 checks passed
@vitormattos vitormattos deleted the backport/6035/stable31 branch December 9, 2025 01:31
@github-project-automation github-project-automation Bot moved this from 0. Needs triage to 4. to release in Roadmap Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant