Skip to content

addReference with empty URI i.e. URI="" #268

Closed

Description

@jaikathuria

Couldn't find a way to sign the whole XML document and have the URL as an empty string while adding the reference

Reference URI=""

Activity

  1. changed the title [-]How to create enveloped signature and sign the whole document i.e. have `URI=""`[/-] [+]Enveloped signature and sign the whole document i.e. have `URI=""`[/+] on Nov 7, 2022
  2. changed the title [-]Enveloped signature and sign the whole document i.e. have `URI=""`[/-] [+]addReference with empty URI i.e. `URI=""`[/+] on Nov 7, 2022
  3. jaikathuria commented on Nov 7, 2022

    @jaikathuria
    Author

    Went through the code and was able to find the way to sign the document and add the reference with URI=""

    The addReference method takes the 7th argument as isEmptyUri and when it's value is true the URI is saved as "" which was the desired output.

    It can be achieve something like

    sign.addReference("/*", undefined, undefined, undefined, undefined, undefined, true);
  4. jaikathuria commented on Nov 7, 2022

    @jaikathuria
    Author

    @LoneRifle Probably you can help here.

    Suggestion: The 4th argument in addReference method takes uri as input and if the argument's value is passed as "" it should automatically set isEmptyUri to be true. That would make the functionality easier to achieve with a cleaner code.

    If you agree, I would be happy to implement it.


    Also, It would be nice to add this to the documentation.
    Signing the XML document with reference URI="" is one of the most basic requirements. And the library supports it, it would be really nice to add it to the README. Willing to take the documentation task as well

  5. Rodrigobanselmo commented on Nov 11, 2022

    @Rodrigobanselmo

    I'm having issues when using isEmptyUri=true.

    When I try isEmptyUri = false I can verify my signature and it is all good but,

    When try isEmptyUri = true I get the bellow error when verifying the signature

    VERIFY ERROR:
    'invalid signature: for uri calculated digest is 4jyM3Mma3Wo1zTUT8njmv9wHWVnsf2cz4bAS2POf6Do= but the xml to validate supplies digest cJ1B4QVSGSggHteZGcwznrpo5aZy+3L+tK3ZF9PXwj8='

    @jaikathuria are you having the same issue?

  6. jaikathuria commented on Nov 13, 2022

    @jaikathuria
    Author

    Not actually. I had to sign the XML to be verified by an external library and I was only able to validate it with isEmptyUri=true.

    I didn't try to verify the XML myself though.

    How you are trying to sign and verify, I might be able to assist.

  7. cjbarth commented on May 29, 2023

    @cjbarth
    Contributor

    Feel free to put up a PR that includes some better documentation about this or that improves the user experience.

  8. cjbarth commented on Sep 24, 2026

    @cjbarth
    Contributor

    isEmptyUri: true is how to get URI="":

    sig.addReference({
      xpath: "/*",
      transforms: ["http://www.w3.org/2000/09/xmldsig#enveloped-signature"],
      digestAlgorithm: "http://www.w3.org/2001/04/xmlenc#sha256",
      isEmptyUri: true,
    });

    The verification failure reported in #268 (comment) was most likely fixed by #581, released in 6.2.0. When enveloped-signature was the only transform, the signer hashed xmldom's serialization while the verifier canonicalized, so their digests differed for any document whose serialization wasn't already canonical. With 6.3.2, signing with isEmptyUri: true and then verifying passes.

    If you still see this on 6.3.2 or later, please comment here with a reproduction and we'll reopen.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions