diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-09-29 16:27:29 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-09-29 16:27:29 -0700 |
commit | 5ceb75f6632a70c564b4556500b9c3e5a98bfa73 (patch) | |
tree | f00bc6d1d47a6ea8aa655a79a8ca2eb0760d50a8 /src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | |
parent | cdd3e95f4eac8076ffd78641bf4cf61d4422572a (diff) | |
download | DotNetOpenAuth-5ceb75f6632a70c564b4556500b9c3e5a98bfa73.zip DotNetOpenAuth-5ceb75f6632a70c564b4556500b9c3e5a98bfa73.tar.gz DotNetOpenAuth-5ceb75f6632a70c564b4556500b9c3e5a98bfa73.tar.bz2 |
Mitigates the XML DTD DoS attack from expanding entities.
Fixes #209
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index b26deeb..084403a 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -21,6 +21,7 @@ namespace DotNetOpenAuth.Messaging { using System.Text; using System.Web; using System.Web.Mvc; + using System.Xml; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; @@ -290,6 +291,28 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Creates the XML reader settings to use for reading XML from untrusted sources. + /// </summary> + /// <returns> + /// The new instance of <see cref="XmlReaderSettings"/>. + /// </returns> + /// <remarks> + /// The default values set here are based on recommendations from + /// http://msdn.microsoft.com/en-us/magazine/ee335713.aspx + /// </remarks> + internal static XmlReaderSettings CreateUntrustedXmlReaderSettings() { + return new XmlReaderSettings { + MaxCharactersFromEntities = 1024, + XmlResolver = null, +#if CLR4 + DtdProcessing = DtdProcessing.Prohibit, +#else + ProhibitDtd = true, +#endif + }; + } + + /// <summary> /// Clears any existing elements in a collection and fills the collection with a given set of values. /// </summary> /// <typeparam name="T">The type of value kept in the collection.</typeparam> |