Skip to content

Implement digital signature validation #13351

Closed

Description

@timvandermeij

(Previously tracked in #1076.)

PDF.js now displays digital signatures, but doesn't validate them, which is comparable to what other PDF viewers do. However, it would be good if we can also implement validation for them, so this is a tracking issue for that.

Activity

  1. calixteman commented on May 9, 2021

    @calixteman
    Contributor

    It's pretty easy to implement (regarding existing js libraries) BUT the main concern is about having something the user can trust because here everything is a matter of trust.
    So if we rely on a third party js lib, it means that we must control everything happening in this lib to avoid a bug or injection of bad code or whatever: it's time consuming (any change in the lib could have an impact in every other place), it requires particular skills (crypto + js skills), so it's likely a bad solution.
    For this reason, we think that a good solution (at least for the build-in pdf viewer) is to rely on NSS (https://hg.mozilla.org/projects/nss), expose what is needed (from the crypto's side) to javascript and let the experts (crypto team, cc @beurdouche, @mozkeeler) decide what's the best way to implement that stuff.

  2. mozkeeler commented on May 10, 2021

    @mozkeeler

    Does this need to be in NSS? Does pdf.js have access to the gecko runtime?

  3. CetinSert commented on May 18, 2021

    @CetinSert
    Contributor

    Does window.crypto.subtle not expose the required primitives to do this without 3rd-party dependencies?

    (I think/support that non-browsers environments are not an official target for the project but for anyone concerned about support in Node, see https://nodejs.org/api/webcrypto.html#webcrypto_class_subtlecrypto .)

  4. rmhrisk commented on May 18, 2021

    @rmhrisk

    @CetinSert the complication isn't crypto, it is support for certificate decoding, trust stores, path validation, timestamping, CMS, etc so, unfortunately, webcrypto isn't enough. Made https://pkijs.org/ to provide these things on top of WebCrypto but in Mozilla land, NSS would be a natural choice as it has many, but not all of these things.

    There is the question of trust store contents, this gets more complicated, the Mozilla Trust Store does have a S/MIME policy but nothing for document signing. It also lacks the necessary timestamping and numerous attributes one needs when doing a full implementation so there is still a non-trivial amount of work to do with this approach.

  5. earthchie commented on May 24, 2021

    @earthchie

    For anyone who's looking for a temporary solution while waiting for official support from this project.
    This repo might help you: https://github.com/rootca-id/pkiwebsdk/blob/master/src/pdf.js

  6. mozkeeler commented on May 24, 2021

    @mozkeeler

    Does this need to be in NSS? Does pdf.js have access to the gecko runtime?

    @calixteman just making sure you saw this ^

  7. calixteman commented on May 24, 2021

    @calixteman
    Contributor

    @mozkeeler, thanks for reminding me.
    I'm not crypto expert at all, but in poppler they're using some NSS stuff to implement part of signature validation so I guess we would need too.
    And yes we've access to gecko runtime, for example:
    https://searchfox.org/mozilla-central/source/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#268

  8. marco-c commented on Jun 23, 2021

    @marco-c
    Contributor

    @andrewyu7575 there are no short term plans to implement digital signature validation, but we'd be happy to accept a contribution.

  9. KentuckyMC commented on Feb 4, 2022

    @KentuckyMC

    Just bumped into this. Is there any 'simple' way to just display a 'warning' onscreen that the shown signatures are not validated? Now there is only a console.warn, but maybe just show something inside the pdf.js as overlay or something, to warn users that the signatures shown are not displayed? Any Idea where I can put something like this in the code?

  10. lexcorp commented on Apr 14, 2023

    @lexcorp
  11. lexcorp commented on May 9, 2023

    @lexcorp
  12. lexcorp commented on Dec 26, 2023

    @lexcorp

    Hello, what is required for this to move forward?

    What would the roadmap be?

    Could you list the requirements to know how we can contribute?

  13. 13 remaining items

  14. marco-c commented on Mar 16, 2026

    @marco-c
    Contributor

    The backend functionality for this, using crypto, is basically done in Firefox, but we need a good UX design to implement.

  15. deleted a comment from on Mar 16, 2026
  16. lexcorp commented on May 8, 2026

    @lexcorp

    The backend functionality for this, using crypto, is basically done in Firefox, but we need a good UX design to implement.

    Maybe something like this:

    https://hancock.ink/

    Image Image
  17. lexcorp commented on Jul 4, 2026

    @lexcorp

    Hi, in which version or release will this improvement be available? I'm eager to try it out...

  18. ousia commented on Jul 4, 2026

    @ousia

    Hi, in which version or release will this improvement be available? I'm eager to try it out...

    I’m just another user (who would like to test this implementation).

    Releases tend to be and the end of the month (https://github.com/mozilla/pdf.js/releases), so this commit may be included in the release of the end of July.

    Which “Firefox” version may include the feature is unknown to me. According to https://whattrainisitnow.com/calendar/, although version 154 wouldn’t be completely impossible, probably version 155 (due to 09.15.2026) would be a safer bet.

    If they choose an “intermediate” release (Firefox 152 includes PDF.js 6.0.109), I don’t know where that info may be publicly available.

    Just in case it might help.

  19. softboy99 commented on Jul 30, 2026

    @softboy99

    We tried v6.2.108, However, without finding any UI about signature.

    we need something like this:

    Image
  20. mdindoffer commented on Aug 17, 2026

    @mdindoffer

    PSA: If you want to test this feature on the latest FF nightly 156.0a1 with PDF.js 6.3.72, you have to set the pdfjs.enableSignatureVerification to true in about:config.

  21. williamdes commented on Oct 1, 2026

    @williamdes

    PSA: If you want to test this feature on the latest FF nightly 156.0a1 with PDF.js 6.3.72, you have to set the pdfjs.enableSignatureVerification to true in about:config.

    https://www.sautinsoft.com/products/pdf/help/net/Code%20samples/CSharp/07.%20Securing%20and%20signing/05.%20Read%20Signature%20Properties/digital%20signature.pdf

    Image

    Thanks for the tip, it works !
    LibreWolf 156.0.1-1

    Also https://www.tecxoft.com/samples.php but none are valid

  22. afife commented on Oct 1, 2026

    @afife

    This is great! How can we add CA certificates to the trust anchors?

  23. CetinSert commented on Oct 1, 2026

    @CetinSert
    Contributor

    Been waiting since 2021-05-18 ...

    My custom HTML elements for PDFs now have signature verification built-in!

    @afife @timvandermeij

    trust and trust:src on <pdf-file> set which certificate authorities you trust. A signature shows verified only if its certificate chain ends at one of them.

    <pdf-file src=contract.pdf trust:src=demo-root.pem signatures></pdf-file>
    <pdf-file src=contract.pdf trust="-----BEGIN CERTIFICATE-----
    MIIB…
    -----END CERTIFICATE-----"></pdf-file>
    
    Image
    • Nothing is trusted by default. Browsers don't give pages their root certificates, and the Adobe and EU signing trust lists aren't built in. With no anchors, an intact signature still shows untrusted ("no trust anchors are configured").
    • trust takes the certificates inline: one or more PEM certificates, a PEM PKCS#7 bundle, or bare base64.
    • trust:src takes exactly one URL, resolved against the page and fetched by the browser. Relative, //host/…, https:, data: and blob: all work, and the file can be PEM, a DER .cer/.crt, or a .p7b. Cross-origin URLs need CORS.
      • If the fetch fails, each signature gets a TRUST_SOURCE_FAILED warning and comes out untrusted. The next verification tries again.
    • Using both trusts all the certificates from both.
    • Roots or intermediates: an anchor can be a root or an intermediate CA. Trusting an intermediate trusts only what it issued. A certificate marked "not a CA" can't be an anchor, so you can't trust one signer's certificate on its own.
    • Changing either attribute re-checks the signatures without reloading or re-rendering the PDF. Changing both at once triggers a single re-check. Results arrive in the signed attribute and the verify event, and from JavaScript the attributes are file.trust and file.trustSrc.
    • Online OCSP/CRL checks (through the proxy) run only for chains that reach an anchor. An untrusted PDF therefore can't make the browser fetch URLs.

    My custom HTML elements also support maintained SVG backend that builds upon what PDF.js abandoned a while ago. Testing it every month against issues from PDF.js and PDFium! It also supports PDFium and does all the rendering off the main thread!

  24. CetinSert commented on Oct 1, 2026

    @CetinSert
    Contributor

    Now with more examples:
    Image

    and before someone starts scaremongering with "oh it's all in the frontend, we can't trust this" nonsense, the platform where I am building my custom HTML elements does have adjacent service/edge workers so signature verifications can be offloaded to the edge with zero user access. As for any unasked for concerns of people tampering with the pages in the frontend, obfuscator.io × closed shadow roots × MutationObserver and I am done before you can even open your mouth to complain!

    Sorry, not sorry! Security guys act all snobby and annoyingly look down on people and I can't just shut up and take it anymore! Just because you have a browser (Firefox), does not mean the open web cannot be secured! I can even do open-source code delivered with obfuscation with proofs that what you get obfuscated for tamper-proofing IS exactly the open-source code byte for byte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions