diff --git a/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs b/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs index 33473ddbf7..2dd1c58c9e 100644 --- a/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs +++ b/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite private UrlMatch _match; private CookieActionFactory _cookieActionFactory = new CookieActionFactory(); - private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1); + private readonly TimeSpan _regexTimeout = TimeSpan.FromSeconds(1); public ApacheModRewriteRule Build() { @@ -68,11 +68,11 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite case ConditionType.Regex: if (flags.HasFlag(FlagType.NoCase)) { - condition.Match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, RegexTimeout), input.Invert); + condition.Match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, _regexTimeout), input.Invert); } else { - condition.Match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexTimeout), input.Invert); + condition.Match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled, _regexTimeout), input.Invert); } break; case ConditionType.IntComp: @@ -160,11 +160,11 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite { if (flags.HasFlag(FlagType.NoCase)) { - _match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, RegexTimeout), input.Invert); + _match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, _regexTimeout), input.Invert); } else { - _match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexTimeout), input.Invert); + _match = new RegexMatch(new Regex(input.Operand, RegexOptions.CultureInvariant | RegexOptions.Compiled, _regexTimeout), input.Invert); } } diff --git a/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UriMatchCondition.cs b/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UriMatchCondition.cs index 9f39d46670..c8378c6b77 100644 --- a/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UriMatchCondition.cs +++ b/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UriMatchCondition.cs @@ -9,12 +9,17 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite { public class UriMatchCondition : Condition { + private TimeSpan _regexTimeout = TimeSpan.FromSeconds(1); + public UriMatchCondition(InputParser inputParser, string input, string pattern, UriMatchPart uriMatchPart, bool ignoreCase, bool negate) { + var regexOptions = RegexOptions.CultureInvariant | RegexOptions.Compiled; + regexOptions = ignoreCase ? regexOptions | RegexOptions.IgnoreCase : regexOptions; var regex = new Regex( pattern, - ignoreCase ? RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase : RegexOptions.CultureInvariant | RegexOptions.Compiled, - TimeSpan.FromMilliseconds(1)); + regexOptions, + _regexTimeout + ); Input = inputParser.ParseInputString(input, uriMatchPart); Match = new RegexMatch(regex, negate); } diff --git a/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UrlRewriteRuleBuilder.cs b/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UrlRewriteRuleBuilder.cs index ea855fb4a4..69ed962154 100644 --- a/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UrlRewriteRuleBuilder.cs +++ b/src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UrlRewriteRuleBuilder.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite { public class UrlRewriteRuleBuilder { - private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1); + private readonly TimeSpan _regexTimeout = TimeSpan.FromSeconds(1); public string Name { get; set; } public bool Enabled { get; set; } @@ -48,12 +48,12 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite { if (ignoreCase) { - var regex = new Regex(input, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, RegexTimeout); + var regex = new Regex(input, RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase, _regexTimeout); _initialMatch = new RegexMatch(regex, negate); } else { - var regex = new Regex(input, RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexTimeout); + var regex = new Regex(input, RegexOptions.CultureInvariant | RegexOptions.Compiled, _regexTimeout); _initialMatch = new RegexMatch(regex, negate); } break;