[Bug]: cert-sign with showSignature=true and no reason answers 200 with an empty PDF

Author: KauanHolsteinCreated Sep 25, 2026Updated Sep 25, 2026

Installation Method

Docker

The Problem

POST /api/v1/security/cert-sign with showSignature=true and no reason field answers 200 with an empty PDF.

  1. CertSignController.CreateSignature.createVisibleSignature calls cs.showText(reason) with a null reason, and PDFBox throws a NullPointerException.
  2. The static CertSignController.sign() catches every exception (catch (Exception e) → ExceptionUtils.logException("PDF signing", e)) and returns normally.
  3. The endpoint then streams the empty temp file back with status 200.

The web UI is not affected because it always sends reason (default ""). API callers that omit the field are. Step 2 hides every other signing failure too: a PDF that fails to load, or any PDFBox error, also comes back as 200 with an empty body.

It also defeats CertificateSubmissionValidator.testSign, which test-signs a blank PDF through PdfSigningService.signWithKeystore and relies on an exception to reject an incompatible certificate with 400. Because sign() swallows the exception, that check can never fire.

Reproduce with any PKCS12 keystore (the new testSignPdfWithVisibleSignatureAndNoReason in the patch below reproduces it in a unit test):

bash
curl -s -o out.pdf -w '%{http_code}\n' \
  -F [email protected] -F certType=PKCS12 -F [email protected] -F password=... \
  -F showSignature=true -F pageNumber=1 \
  http://localhost:8080/api/v1/security/cert-sign
# expected: 200 and an empty out.pdf

Version of Stirling-PDF

main at 2e305db4b (3.0.0)

Last Working Version of Stirling-PDF

No response

Page Where the Problem Occurred

No response

Docker Configuration

No response

Relevant Log Output

txt
The NullPointerException is logged under "PDF signing" by ExceptionUtils.logException; the response is still 200.

Additional Information

Proposed fix, with tests:

  • Draw a null reason as an empty line (Objects.toString(signature.getReason(), "")).
  • Let sign() propagate failures (throws IOException) instead of catching them.
  • Close the temp file on a RuntimeException too in signPDFWithCert. Today its catch (IOException e) never runs, because sign() never throws.
  • Two tests in CertSignControllerTest: a visible signature without reason yields a signed PDF, and a failed signature throws instead of returning an empty body. Both fail on current main.

The patch is ready on GPS-Contadores:fix/cert-sign-null-reason (one commit on 2e305db4b). The CertSign*, PdfSigningService*, CertificateSubmissionValidatorTest and SigningFinalizationService*Test suites pass with it. I'm happy to open the PR if you assign this issue to me.

Note: #7262 rewrites these lines and keeps cs.showText(signature.getReason()), so it has the same NPE. Whichever lands second will need a small rebase.

Sample Files

No response

Browsers Affected

No response

No Duplicate of the Issue

  • I have verified that there are no existing issues raised related to my problem.

Source: Stirling-Tools/Stirling-PDF