Increases timeout on Regex in Rewrite. (#280)
This commit is contained in:
parent
8f0cc61808
commit
d866293e9e
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue