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 UrlMatch _match;
|
||||||
private CookieActionFactory _cookieActionFactory = new CookieActionFactory();
|
private CookieActionFactory _cookieActionFactory = new CookieActionFactory();
|
||||||
|
|
||||||
private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1);
|
private readonly TimeSpan _regexTimeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
public ApacheModRewriteRule Build()
|
public ApacheModRewriteRule Build()
|
||||||
{
|
{
|
||||||
|
|
@ -68,11 +68,11 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
||||||
case ConditionType.Regex:
|
case ConditionType.Regex:
|
||||||
if (flags.HasFlag(FlagType.NoCase))
|
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
|
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;
|
break;
|
||||||
case ConditionType.IntComp:
|
case ConditionType.IntComp:
|
||||||
|
|
@ -160,11 +160,11 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
|
||||||
{
|
{
|
||||||
if (flags.HasFlag(FlagType.NoCase))
|
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
|
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
|
public class UriMatchCondition : Condition
|
||||||
{
|
{
|
||||||
|
private TimeSpan _regexTimeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
public UriMatchCondition(InputParser inputParser, string input, string pattern, UriMatchPart uriMatchPart, bool ignoreCase, bool negate)
|
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(
|
var regex = new Regex(
|
||||||
pattern,
|
pattern,
|
||||||
ignoreCase ? RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase : RegexOptions.CultureInvariant | RegexOptions.Compiled,
|
regexOptions,
|
||||||
TimeSpan.FromMilliseconds(1));
|
_regexTimeout
|
||||||
|
);
|
||||||
Input = inputParser.ParseInputString(input, uriMatchPart);
|
Input = inputParser.ParseInputString(input, uriMatchPart);
|
||||||
Match = new RegexMatch(regex, negate);
|
Match = new RegexMatch(regex, negate);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
|
||||||
{
|
{
|
||||||
public class UrlRewriteRuleBuilder
|
public class UrlRewriteRuleBuilder
|
||||||
{
|
{
|
||||||
private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1);
|
private readonly TimeSpan _regexTimeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
|
|
@ -48,12 +48,12 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
|
||||||
{
|
{
|
||||||
if (ignoreCase)
|
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);
|
_initialMatch = new RegexMatch(regex, negate);
|
||||||
}
|
}
|
||||||
else
|
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);
|
_initialMatch = new RegexMatch(regex, negate);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue