Skip to content

Commit 8103352

Browse files
authored
Update README.md
1 parent 3a2dd28 commit 8103352

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,20 @@ Example:
132132
sig.keyInfoProvider = new FileKeyInfo("client_public.pem")
133133
sig.loadSignature(signature)
134134
var res = sig.checkSignature(xml)
135-
if (!res) console.log(sig.validationErrors)
135+
if (!res) console.log(sig.validationErrors)
136136
`````
137137

138138
if the verification process fails `sig.validationErrors` will have the errors.
139139

140+
In order to protect from some attacks we must check the content we want to use is the one that has been signed:
141+
`````javascript
142+
var elem = select(doc, "/xpath_to_interesting_element");
143+
var uri = sig.references[0].uri; // might not be 0 - depending on the document you verify
144+
var id = (uri[0] === '#') ? uri.substring(1) : uri;
145+
if (node.getAttribute('ID') != id && node.getAttribute('Id') != id)
146+
throw new Error('the interesting element was not the one verified by the signature')
147+
`````
148+
140149
Note:
141150

142151
The xml-crypto api requires you to supply it separately the xml signature ("<Signature>...</Signature>", in loadSignature) and the signed xml (in checkSignature). The signed xml may or may not contain the signature in it, but you are still required to supply the signature separately.

0 commit comments

Comments
 (0)