Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit ae67028

Browse files
committed
disable DTD processing by default
1 parent 7c88d65 commit ae67028

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ServiceStack.Text/XmlSerializer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public XmlSerializer(bool omitXmlDeclaration = false, int maxCharsInDocument = 1
1919
XWSettings.Encoding = PclExport.Instance.GetUTF8Encoding(false);
2020
XWSettings.OmitXmlDeclaration = omitXmlDeclaration;
2121
XRSettings.MaxCharactersInDocument = maxCharsInDocument;
22+
23+
//Prevent XML bombs by default: https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
24+
XRSettings.DtdProcessing = DtdProcessing.Prohibit;
2225
}
2326

2427
private static object Deserialize(string xml, Type type)
@@ -86,7 +89,7 @@ public static string SerializeToString<T>(T from)
8689
}
8790
catch (Exception ex)
8891
{
89-
throw new SerializationException(string.Format("Error serializing object of type {0}", from.GetType().FullName), ex);
92+
throw new SerializationException($"Error serializing object of type {@from.GetType().FullName}", ex);
9093
}
9194
}
9295

@@ -102,7 +105,7 @@ public static void SerializeToWriter<T>(T value, TextWriter writer)
102105
}
103106
catch (Exception ex)
104107
{
105-
throw new SerializationException(string.Format("Error serializing object of type {0}", value.GetType().FullName), ex);
108+
throw new SerializationException($"Error serializing object of type {value.GetType().FullName}", ex);
106109
}
107110
}
108111

0 commit comments

Comments
 (0)