| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- commit d866293e9eb82e70f9947415b278f3cc8c71afdb
- Author: Justin Kotalik <[email protected]>
- Date: Wed Jan 3 12:37:02 2018 -0800
- Increases timeout on Regex in Rewrite. (#280)
- diff --git a/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs b/src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/RuleBuilder.cs
- index 33473ddbf78..2dd1c58c9e8 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 9f39d466706..c8378c6b778 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 ea855fb4a4b..69ed9621540 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;
|