Skip to content

Commit 482c5aa

Browse files
committed
Ensure that Read is compliant with xenc xsd schema
* KeyInfo could be empty (self-closing) element - don't attempt to read * EncryptionMethod supports any element as a child. Log and Skip everything except DigestMethod * (Data/Key) Reference supports any element as a child. As we care only about URI attribute - skip child elements that might appear * Add tests for above cases
1 parent 2bcf6c5 commit 482c5aa

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

src/Microsoft.IdentityModel.Xml/EncryptedReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal virtual void ReadXml(XmlDictionaryReader reader)
6767
if (reader.IsStartElement(XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace) || reader.IsStartElement(XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace))
6868
{
6969
Uri = reader.GetAttribute(XmlEncryptionConstants.Attributes.Uri, null);
70-
reader.Read();
70+
reader.Skip();
7171
}
7272
}
7373
}

src/Microsoft.IdentityModel.Xml/EncryptionMethod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ internal void ReadXml(XmlDictionaryReader reader)
106106
if (reader.IsStartElement(XmlSignatureConstants.Elements.DigestMethod, XmlSignatureConstants.Namespace))
107107
{
108108
DigestMethod = reader.GetAttribute(XmlSignatureConstants.Attributes.Algorithm, null);
109-
reader.Read();
110109
}
111110
else
112111
{
113112
LogInformation(LogMessages.IDX30302, reader.LocalName, XmlEncryptionConstants.Elements.EncryptionMethod);
114-
reader.Skip();
115113
}
114+
115+
reader.Skip();
116116
}
117117

118118
reader.ReadEndElement();

src/Microsoft.IdentityModel.Xml/KeyInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ internal void ReadXml(XmlDictionaryReader reader)
291291

292292
if (reader.IsStartElement(XmlSignatureConstants.Elements.KeyInfo, XmlSignatureConstants.Namespace))
293293
{
294+
if (reader.IsEmptyElement)
295+
{
296+
reader.Skip();
297+
return;
298+
}
299+
294300
reader.ReadStartElement(XmlSignatureConstants.Elements.KeyInfo, XmlSignatureConstants.Namespace);
295301

296302
while (reader.IsStartElement())

0 commit comments

Comments
 (0)