//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; /// /// Represents the section of a .config file where security policies regarding web requests /// to user-provided, untrusted servers is controlled. /// internal class UntrustedWebRequestElement : ConfigurationElement { #region Attribute names /// /// Gets the name of the @timeout attribute. /// private const string TimeoutConfigName = "timeout"; /// /// Gets the name of the @readWriteTimeout attribute. /// private const string ReadWriteTimeoutConfigName = "readWriteTimeout"; /// /// Gets the name of the @maximumBytesToRead attribute. /// private const string MaximumBytesToReadConfigName = "maximumBytesToRead"; /// /// Gets the name of the @maximumRedirections attribute. /// private const string MaximumRedirectionsConfigName = "maximumRedirections"; /// /// Gets the name of the @whitelistHosts attribute. /// private const string WhitelistHostsConfigName = "whitelistHosts"; /// /// Gets the name of the @whitelistHostsRegex attribute. /// private const string WhitelistHostsRegexConfigName = "whitelistHostsRegex"; /// /// Gets the name of the @blacklistHosts attribute. /// private const string BlacklistHostsConfigName = "blacklistHosts"; /// /// Gets the name of the @blacklistHostsRegex attribute. /// private const string BlacklistHostsRegexConfigName = "blacklistHostsRegex"; #endregion /// /// Gets or sets the read/write timeout after which an HTTP request will fail. /// [ConfigurationProperty(ReadWriteTimeoutConfigName, DefaultValue = "00:00:01.500")] [PositiveTimeSpanValidator] public TimeSpan ReadWriteTimeout { get { return (TimeSpan)this[ReadWriteTimeoutConfigName]; } set { this[ReadWriteTimeoutConfigName] = value; } } /// /// Gets or sets the timeout after which an HTTP request will fail. /// [ConfigurationProperty(TimeoutConfigName, DefaultValue = "00:00:10")] [PositiveTimeSpanValidator] public TimeSpan Timeout { get { return (TimeSpan)this[TimeoutConfigName]; } set { this[TimeoutConfigName] = value; } } /// /// Gets or sets the maximum bytes to read from an untrusted web server. /// [ConfigurationProperty(MaximumBytesToReadConfigName, DefaultValue = 1024 * 1024)] [IntegerValidator(MinValue = 2048)] public int MaximumBytesToRead { get { return (int)this[MaximumBytesToReadConfigName]; } set { this[MaximumBytesToReadConfigName] = value; } } /// /// Gets or sets the maximum redirections that will be followed before an HTTP request fails. /// [ConfigurationProperty(MaximumRedirectionsConfigName, DefaultValue = 10)] [IntegerValidator(MinValue = 0)] public int MaximumRedirections { get { return (int)this[MaximumRedirectionsConfigName]; } set { this[MaximumRedirectionsConfigName] = value; } } /// /// Gets or sets the collection of hosts on the whitelist. /// [ConfigurationProperty(WhitelistHostsConfigName, IsDefaultCollection = false)] [ConfigurationCollection(typeof(HostNameOrRegexCollection))] public HostNameOrRegexCollection WhitelistHosts { get { return (HostNameOrRegexCollection)this[WhitelistHostsConfigName] ?? new HostNameOrRegexCollection(); } set { this[WhitelistHostsConfigName] = value; } } /// /// Gets or sets the collection of hosts on the blacklist. /// [ConfigurationProperty(BlacklistHostsConfigName, IsDefaultCollection = false)] [ConfigurationCollection(typeof(HostNameOrRegexCollection))] public HostNameOrRegexCollection BlacklistHosts { get { return (HostNameOrRegexCollection)this[BlacklistHostsConfigName] ?? new HostNameOrRegexCollection(); } set { this[BlacklistHostsConfigName] = value; } } /// /// Gets or sets the collection of regular expressions that describe hosts on the whitelist. /// [ConfigurationProperty(WhitelistHostsRegexConfigName, IsDefaultCollection = false)] [ConfigurationCollection(typeof(HostNameOrRegexCollection))] public HostNameOrRegexCollection WhitelistHostsRegex { get { return (HostNameOrRegexCollection)this[WhitelistHostsRegexConfigName] ?? new HostNameOrRegexCollection(); } set { this[WhitelistHostsRegexConfigName] = value; } } /// /// Gets or sets the collection of regular expressions that describe hosts on the blacklist. /// [ConfigurationProperty(BlacklistHostsRegexConfigName, IsDefaultCollection = false)] [ConfigurationCollection(typeof(HostNameOrRegexCollection))] public HostNameOrRegexCollection BlacklistHostsRegex { get { return (HostNameOrRegexCollection)this[BlacklistHostsRegexConfigName] ?? new HostNameOrRegexCollection(); } set { this[BlacklistHostsRegexConfigName] = value; } } } }