Skip to content
CyberBadger
← All articles
Cybersecurity

A Signed PDF, Changed After Signing, Reported as Untouched: Inside the pyHanko Fix

November 26, 20266 min readNathan Cross
Security advisory
Published on GitHub by the maintainer
Fixed
Library
pyHanko (pyhanko on PyPI), by Matthias Valvekens
Affected
0.38.1 and earlier
Patched
0.38.2, November 19, 2026
Credit
Julian Neuber and Nathan Cross (CyberBadger), independent reports

pyHanko, a Python library for signing and checking PDF signatures with about 5.9 million downloads a month, fixed an issue we reported in November. A signed PDF could be changed after signing and still be reported as valid and untouched. Here's how, who it affects, and what to do.

pyHanko is an open-source Python library for signing PDFs and checking the signatures on them. It's maintained by Matthias Valvekens and downloaded about 5.9 million times a month from PyPI, often as a building block inside other software: e-signature services, document workflows, archiving tools.

In November we reported an issue in how pyHanko decides whether a signed PDF has been changed. It's fixed in pyHanko 0.38.2, and the advisory is public. Julian Neuber found the same issue independently, and the advisory credits us both.

The short version

  • What went wrong: a signed PDF could be changed after signing, and pyHanko still reported the signature as valid, trusted and covering the whole file, with nothing changed since signing.
  • What it takes: a copy of any normally signed PDF. No signing key, and no help from the person who signed it.
  • Fixed in pyHanko 0.38.2, released November 19, 2026. All earlier releases are affected. If your software checks signed PDFs with pyHanko, update it.

Timeline

We reported the issue through GitHub's private vulnerability reporting on November 18, with test files and a script that reproduces it. Julian Neuber reported the same issue independently. On November 19 the maintainer released 0.38.2 and published one advisory crediting both reporters.

We then ran all of our test files against 0.38.2. None of the altered files we built is reported as untouched any more, and untouched or legitimately updated files still check out as before.

  1. ReportedNov 18, 3:30 PM

    A private GitHub security advisory, with test files and a script that reproduces the issue.

    About a day from our report to the fix
  2. FixedNov 19, 4:59 PM

    pyHanko 0.38.2 released on GitHub and PyPI.

  3. Advisory publishedNov 19, 5:30 PM

    One advisory for the two independent reports, crediting both reporters.

  4. Fix confirmedNov 19

    We ran every test file against 0.38.2. Each altered file is now flagged, and untouched files still pass.

  5. Write-upNov 26

    This post, a week after the fix. No CVE ID has been assigned yet.

Times Eastern, from the GitHub advisories and the 0.38.2 release.

How a PDF signature covers a file

When a PDF is signed, the signature covers the whole file except one gap: the spot where the signature itself is stored. A signature can't cover its own bytes, so the file records which two stretches it covers, before the gap and after it.

PDFs can also be added to after signing. That's normal: a second person signs, or a form gets filled in. So a checker has to answer two questions. Is the signature genuine? And has anything been added since, and if so, is it allowed?

If the signature covers the file right to the end, the second question answers itself: nothing has been added. pyHanko took that shortcut, and that's where the problem was.

What a PDF signature covers
Our signed test file, 8,016 bytes, from top to bottom
  1. Signed
    Bytes 0 to 1,008: the document, up to the signature
  2. The signature itself
    Bytes 1,008 to 7,438. Not covered: a signature can’t sign its own bytes
  3. Signed
    Bytes 7,438 to 8,016: the rest of the file
  4. Added later, if anything
    A second signature, a filled-in form, any update. Not covered by this signature
  1. Is the signature genuine?

    Check the two signed stretches against the signature. A change there breaks it.

  2. Was anything added after signing?

    If the signature reaches the end of the file, nothing was. If it doesn’t, review what was added and decide whether it’s allowed.

Byte positions from the signed test file we made for the report. The issue lives in the shortcut in question 2.

The issue: a sum instead of a check

To decide whether the signature reached the end of the file, pyHanko didn't look at where the signed stretches actually ended. It added up the sizes: the two signed stretches, plus the size of the signature in the gap. If the total matched the file's size, the signature was treated as covering the entire file.

The sum behind “covers the entire file”
Sizes in bytes. If the expected size equals the real size, pyHanko 0.38.1 reports full coverage
The signed file: As pyHanko signed it
First signed stretch
1,008
Second signed stretch
578
Signature space2 × 3,214 + 2
6,430
Expected size
8,016
Real size (nothing added)
8,016
Sizes match: “covers the entire file.” Correct.
The altered file: Signature rewritten, an update added
First signed stretch
1,008
Second signed stretch
578
Signature space2 × 6,373 + 2
12,748
Expected size
14,334
Real size (6,318 bytes added)
14,334
Sizes match: “covers the entire file.” Wrong: 6,318 bytes at the end were never signed.
The signature space is counted as two characters per byte of signature, plus its two brackets. That’s only true when the signature is written in hexadecimal.

That sum assumed the signature in the gap is written in hexadecimal, two characters per byte, which is what the PDF standard requires. pyHanko never checked that it was. The signature can be rewritten in another text form that pyHanko still reads, without touching the signed stretches, so the signature stays genuine. Read back that way, the signature counts as roughly twice as big, and the sum now expects a longer file than the one that was signed.

The same space, written two ways
The first 16 characters of the signature space in our test file. Each shaded group is one byte
Hexadecimal, as signed: Two characters per byte
These 16 characters
8 bytes
All 6,430 characters
3,214 bytes
Rewritten as text: One character per byte, two for an escaped one
These 16 characters
15 bytes
All 6,430 characters
6,373 bytes
Dots are bytes with no printable character. Both versions decode to the same signature; the rest of the space is padding, which pyHanko tolerated. The signed stretches either side don’t change at all.

That extra room, several thousand bytes, is enough to add a change at the end of the file. In our test, it replaced an invoice total of 100.00 with 9,999.00. The sizes added up, so pyHanko reported the signature as covering the entire file. A signature that covers everything has nothing after it to review, so the added page was never looked at.

Three views of the same bytes, to scale
Each bar is the whole file, drawn against the altered file’s 14,334 bytes
The signed file
8,016 bytes

Signature reaches the end. Correctly reported as covering the entire file.

The altered file, as it really is
14,334 bytes

Same signed bytes, then 6,318 bytes nobody signed, holding the new page.

The altered file, as the sum pictured it
14,334 bytes

A signature space twice as big, ending at the end of the file. Reported as covering the entire file.

  • Signed
  • Signature space
  • Added, never signed
  • Signature space, as counted
From our test files. The first signed stretch is 1,008 bytes and the second 578, so they’re thin at this scale.

Every verdict an application would check said the same thing. Valid, trusted, untouched, and an exit code of 0 from pyHanko's command-line checker. The page anyone opened showed 9,999.00.

What pyHanko 0.38.1 reported
$ pyhanko sign validate --pretty-print invoice.pdf
Integrity
The signature is cryptographically sound.
Modifications
The signature covers the entire file.
Bottom line
The signature is judged VALID.
exit code: 0
What the document says
invoice.pdf, page 1
Invoice
As signed100.00 EUR
Invoice total9,999.00 EUR
Changed after signing
Lines from our test run, trimmed to the verdicts; the full report also names the signer and its trusted certificate. The page shows only the new total, as a PDF reader displays the same file; the struck-out line is ours, for comparison.
  • The fix: pyHanko 0.38.2 now checks that the gap holds exactly one hexadecimal signature of the expected size, and that the signed stretches really line up with it, before it reports full coverage.
  • Severity: 7.5High CVSS 3.1, from the advisory.
Before and after the fix
pyhanko sign validate on three of our test files
The signed file, untouched
Page total: 100.00 EUR
VALIDRight
0.38.1: Covers the entire file
VALIDRight
0.38.2: Covers the entire file
The same change, added the ordinary way
Page total: 9,999.00 EUR
INVALIDRight
0.38.1: Illegal modifications
INVALIDRight
0.38.2: Illegal modifications
The same change, with the signature rewritten
Page total: 9,999.00 EUR
VALIDWrong
0.38.1: Covers the entire file
INVALIDRight
0.38.2: Doesn’t cover the entire file
An ordinary update was always caught. Only the rewritten signature fooled 0.38.1, and 0.38.2 catches it while untouched files still pass.

Where it was harder to pull off

The advisory lists the cases tested. Signatures from three other signing tools were affected too (one of them only in pyHanko's lenient reading mode), as were signatures carrying long-term validation data. Documents with a second signature, or a timestamp added after the signature, were harder to fool: another check flagged the change. That only helps if the application checks every signature and timestamp, not just the last signature.

Which signed files could be fooled
pyHanko 0.38.1, from the cases listed in the advisory
  • One signature, from pyHanko, OpenPDF or endesive
    The case we reported. Room for about 6,300 bytes of new content with pyHanko’s default settings.
    Passed as untouched
  • One signature, from pdfsig
    In pyHanko’s lenient reading mode, with room for about 19,900 bytes. Its strict mode rejects even untouched pdfsig files.
    Passed as untouched
  • Signature with long-term validation data
    PAdES B-LT, or Adobe-style revocation data. The later revision holding that data survives.
    Passed as untouched
  • A document timestamp on its own
    Reported as covering the entire file, with nothing modified.
    Passed as untouched
  • Two signatures
    The earlier signature reports the change. Software that checks only the last signature sees it as untouched.
    Caught only if checked
  • PAdES B-LTA
    The signature passes, but the archive timestamp fails, so a full AdES check doesn’t pass.
    Caught only if checked
  • A signature, then a document timestamp
    The signature reports illegal modifications.
    Change flagged
In our tests, 0.38.2 flags the change in every one of these. “Caught only if checked” means the change shows up in a second check that some software never runs.

Who should care

Anything that accepts signed PDFs from outside and trusts pyHanko's answer: e-signature and contract platforms, document intake for loans, claims or onboarding, invoice processing, archives that certify what they received. For a service like that, the danger is a document that passes every check while saying something its signer never signed.

The issue is in pyHanko's own verdict. Adobe Acrobat and other PDF viewers don't use pyHanko to check signatures, so it only matters for software that does.

Could a changed document have passed your checks?
Only if all three are true
  • pyHanko 0.38.1 or earlier
    Fixed in 0.38.2, released November 19, 2026, on PyPI.
  • It checks signed PDFs you didn’t create
    Uploads, emailed contracts, documents from customers or partners.
  • It acts on pyHanko’s verdict
    The bottom line, the coverage level, the summary, or the exit code of pyhanko sign validate.
All three: a document changed after signing could have passed as signed and untouched. Update, and recheck the documents that matter.

What to do

  • Update to pyHanko 0.38.2 or later. It's the pyhanko package on PyPI.
  • Check whether you use it without knowing. pyHanko can arrive as a dependency of another package. Run pip show pyhanko in each environment, or search your lock files for pyhanko.
  • Recheck what you've already accepted. If you accepted important signed documents on pyHanko's verdict alone, run them through 0.38.2. An altered file will now fail the check.

The common thread

The signature itself was never broken. The problem was in the bookkeeping around it: pyHanko worked out where the signature ended from a sum, not by looking. The sum was right for every file made the normal way, so tests built from normal files wouldn't catch it. Finding it means asking what happens when the file is not made the normal way.

Why we look at code like this

We look for security problems in the software businesses rely on, including the open-source libraries underneath it, report them privately and publish details only once they're fixed. You can see our other credits and disclosures on our security research page.

If your business builds or runs software that handles documents from outside, that's exactly what a penetration test puts under pressure.

pyHanko vulnerabilitypyHanko 0.38.2PDF signature validationdigital signature bypasssigned PDF tamperingPython security
Penetration testing

Want us to look at your systems?

Book a free scoping call. We agree on what to test and when, put it in writing, and quote it before anything starts.

CallGet a quote