Replies: 4 comments 13 replies
-
One way to force usage of configured new SignedXml(
{
publicCert: client_public_pem
}
) seems to be to modify aforementioned configuration so that one overrides default new SignedXml(
{
publicCert: client_public_pem,
getCertFromKeyInfo: () => undefined
}
); and after that this code would use Line 335 in 06cab68 but IMHO this should be default behaviour. I.e. it should be impossible to accidentally after migration from 3.x or via any other "paths" to end up using embedded certificate from untrusted input XML for validation purposes. If someone wants to accept embedded certificate for such purposes (use case could be something like: "if embedded certificate is signed by trusted CA then use it to validate submitted XML document's signatures") then he/she would have to implement this behaviour explicitly. I mean default implementation of OR if disclaimer: I did not spend too much time to think all possible corner cases / implications of possibilities listed in this particular message. |
Beta Was this translation helpful? Give feedback.
-
@LoneRifle , what do you think of this? I'm getting close to releasing a semver-major release, and what @srd90 is suggesting would be a breaking change. I'm inclined to try to get this into the next release. Do you have time/interest in addressing this? |
Beta Was this translation helpful? Give feedback.
-
@srd90 - actually, wait. is this even an issue? W3C states in section 3.2.2 of XML Signature Syntax and Processing (Second Edition)1 that the signature value has to be validated against the information found in In other words, this isn't bypassing signature validation per se as it is simply validating the signature given in the request. It is up to the application to then decide whether it is a problem that the certificate presented does not match up with See also this StackOverflow post2. cc @cjbarth and @shunkica , who discussed the original intent of Footnotes |
Beta Was this translation helpful? Give feedback.
-
I may be late to this party but I don't see where the issue is. |
Beta Was this translation helpful? Give feedback.
-
Starting this as a discussion because this is at least not yet an issue and more like an possible oversight at the documentation and oversight from users of this library if they choose to follow that example without criticism.
Links to codebase point to
xml-crypto
's version4.1.0
(aka06cab681037981a4a9dffe27d3463f9f8014b12e
). Example code is also written against that version.I stumbled into this line (while browsing through codebase without any actual goal):
That line prefers certificate from
Signature/KeyInfo/X509Data/X509Certificate
over any other certificate sources.At the same time example at the README.md#verifying-xml-documents encourages users to read content
of the
Signature
element (along withKeyInfo
elements) into instance ofSignedXML
from input XML which is possibly under the control of attacker before it is submitted to system:i.e. at the runtime result is going to be:
due these:
when signature is validated control flow is (assuming that input XML contains
KeyInfo/X509Data/X509Certificate
):xml-crypto/src/signed-xml.ts
Lines 332 to 335 in 06cab68
xml-crypto/src/signed-xml.ts
Lines 211 to 215 in 06cab68
key
(certificate to be used to validate signature) is taken from input XMLIf some system uses approach instructed at the example then attacker can bypass signature
validation just by signing document with his/her own key and by adding that key's certificate into
KeyInfo
.Example:
Script that was used to generate test material (just in case someone wants to replicate this):
IMHO this issue can affect also those who migrate from
3.x
to4.x
if their3.x
based implementation looked something like README's example validation code and if they do minimal amount of modifications to make it work with4.x
(minimal amount can be seen from example code snippet). Furthermore their migrated codebase would start to accept silently documents that are signed by attacker (if they don't have proper integration tests in place to validate that under every circumstance only documents which are signed with "client_public.pem" are valid).Example code used version
4.1.0
which has also this signature validation bypass vulnerability #378 but IMHO lack of fix to that (i.e. not using more recent version) would not have any effect how codebase would work under in the cases introduced in this message (and after all4.1.0
is still most recent published version).IMHO
3.x
codebase is unaffected because it doesn' t lookupX509Certificate
element from anywhere (at least I didn't spot such code when I quickly looked into that codebase). Situation might be by product of this PR #301. ... and now - after all this writing - I searchedKeyInfo
related issues and I bumped into this #375 (by @IlyaRazuvaev) which seems to be a issue report that says that after upgrade to4.x
there is issues with SAML messages which have signed response and signed assertions (i.e. two KeyInfo elements in the document) and furthermore reporter seems to have noticed same behaviour (that certificate at SAML messages X509Certitificate element overrides whats being configured by developer toxml-crypto
stack).ping @cjbarth @markstos @LoneRifle @djaqua
Beta Was this translation helpful? Give feedback.
All reactions