A Signed PDF, Changed After Signing, Reported as Untouched: Inside the pyHanko Fix
- 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
- A signed PDF changed after signing is reported as covering the whole file7.5HighAnyone with a copy of a signed PDFGHSA-639c-rx63-qgmx
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.
- 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 - FixedNov 19, 4:59 PM
pyHanko 0.38.2 released on GitHub and PyPI.
- Advisory publishedNov 19, 5:30 PM
One advisory for the two independent reports, crediting both reporters.
- Fix confirmedNov 19
We ran every test file against 0.38.2. Each altered file is now flagged, and untouched files still pass.
- Write-upNov 26
This post, a week after the fix. No CVE ID has been assigned yet.
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.
- SignedBytes 0 to 1,008: the document, up to the signature
- The signature itselfBytes 1,008 to 7,438. Not covered: a signature can’t sign its own bytes
- SignedBytes 7,438 to 8,016: the rest of the file
- Added later, if anythingA second signature, a filled-in form, any update. Not covered by this signature
- Is the signature genuine?
Check the two signed stretches against the signature. A change there breaks it.
- 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.
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.
- 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
- 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
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.
- These 16 characters
- 8 bytes
- All 6,430 characters
- 3,214 bytes
- These 16 characters
- 15 bytes
- All 6,430 characters
- 6,373 bytes
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.
Signature reaches the end. Correctly reported as covering the entire file.
Same signed bytes, then 6,318 bytes nobody signed, holding the new page.
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
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.
- 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.
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.
- Passed as untouchedOne signature, from pyHanko, OpenPDF or endesiveThe case we reported. Room for about 6,300 bytes of new content with pyHanko’s default settings.
- Passed as untouchedOne signature, from pdfsigIn pyHanko’s lenient reading mode, with room for about 19,900 bytes. Its strict mode rejects even untouched pdfsig files.
- Passed as untouchedSignature with long-term validation dataPAdES B-LT, or Adobe-style revocation data. The later revision holding that data survives.
- Passed as untouchedA document timestamp on its ownReported as covering the entire file, with nothing modified.
- Caught only if checkedTwo signaturesThe earlier signature reports the change. Software that checks only the last signature sees it as untouched.
- Caught only if checkedPAdES B-LTAThe signature passes, but the archive timestamp fails, so a full AdES check doesn’t pass.
- Change flaggedA signature, then a document timestampThe signature reports illegal modifications.
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.
- pyHanko 0.38.1 or earlierFixed in 0.38.2, released November 19, 2026, on PyPI.
- It checks signed PDFs you didn’t createUploads, emailed contracts, documents from customers or partners.
- It acts on pyHanko’s verdictThe bottom line, the coverage level, the summary, or the exit code of pyhanko sign validate.
What to do
- Update to pyHanko 0.38.2 or later. It's the
pyhankopackage on PyPI. - Check whether you use it without knowing. pyHanko can arrive as a dependency of another package. Run
pip show pyhankoin each environment, or search your lock files forpyhanko. - 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.
Keep reading
All articlesWhat Cyber Insurance Applications Ask Small Businesses in Canada
We read three Canadian cyber insurance application forms. They ask about controls like MFA, backups and patching, not penetration tests. Here's what they ask, and how to check your answers before you sign.
Read articleTwo 896-Byte Files That Crashed a Java HDF5 Reader: Inside the jhdf Fixes
jhdf, an open-source Java library for reading HDF5 data files, fixed two issues we reported in November. Each one let a file smaller than 1 KB crash the application reading it. Here's how, why a normal try/catch didn't help, and who should update.
Read articleHow Two WordPress Blocks Got Around the Members Plugin's Content Restrictions
Members, a content restriction plugin on more than 300,000 WordPress sites, has fixed four issues we reported, each now with a CVE ID. Two let any visitor read members-only posts and comments through standard WordPress blocks. Here's how that happened, who was affected, and what to check on your own site.
Read articleWant 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.