Mitigate XSW in SMD verification#3148
Conversation
There's a bit of a mismatch between the bit that parses the Java object and the bit that validates the XML. The parser parses the Java root node, however the validator follows the reference in a (valid) signature to *any* node, which can be hidden elsewhere. To fix this robustly: - Enforce that the XML signature Reference URI matches the root element ID precisely - Assert that exactly one <smd:signedMark> element exists in the DOM - Don't allow additional signed marks elsewhere in the XML just in case
|
LGTM on the XSW mitigations ( One constructive recommendation to harden the cryptographic reference binding in Currently, the check uses List<Reference> references = signature.getSignedInfo().getReferences();
if (references.stream().noneMatch(ref -> expectedUri.equals(ref.getURI()))) {
throw new XMLSignatureException(
"Signature Reference URI does not match the root element ID.");
}While Recommended Drop-In Replacement:List<Reference> references = signature.getSignedInfo().getReferences();
if (references.size() != 1 || !expectedUri.equals(references.get(0).getURI())) {
throw new XMLSignatureException(
"Expected exactly one signature reference matching the root element ID.");
} |
gbrodman
left a comment
There was a problem hiding this comment.
Under RFC 7848 (TMCH SMD XML profile),
<ds:SignedInfo>must contain strictly one reference targeting the signed mark.
This is an AI hallucination and this entire comment is incorrect. That RFC specifies nothing about the dsig data and delegates that entirely to https://www.w3.org/TR/xmldsig-core1/.
See https://www.w3.org/TR/xmldsig-core1/#sec-SignedInfo: "The structure of SignedInfo includes the canonicalization algorithm, a signature algorithm, and one or more references. "
Indeed, our testing data all contains two references. in the signed info. One is to the signed mark (as expected), and the second signs the KeyInfo block itself, which is a necessary part to avoid key substitution attacks.
@gbrodman made 1 comment.
Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on CydeWeys).
There's a bit of a mismatch between the bit that parses the Java object and the bit that validates the XML. The parser parses the Java root node, however the validator follows the reference in a (valid) signature to any node, which can be hidden elsewhere.
To fix this robustly:
This change is