Skip to content

Commit

Permalink
Increase Regex Timeouts (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin authored Feb 7, 2025
1 parent 9f19e1b commit d54c645
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Immediate.Validations.Shared/ValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace Immediate.Validations.Shared;
/// <summary>
/// Represents the result of an in-progress or completed validation.
/// </summary>
[SuppressMessage("Security", "MA0009:Add regex evaluation timeout", Justification = "Limited danger scope (property names and message templates)")]
public sealed partial class ValidationResult : IEnumerable<ValidationError>
{
[GeneratedRegex("{(?<name>[^{}:]+)(?::(?<format>[^{}]+))?}", RegexOptions.ExplicitCapture, matchTimeoutMilliseconds: 50)]
[GeneratedRegex("{(?<name>[^{}:]+)(?::(?<format>[^{}]+))?}", RegexOptions.ExplicitCapture)]
private static partial Regex FormatRegex();

private List<ValidationError>? _errors;
Expand Down Expand Up @@ -244,7 +245,7 @@ private enum MemberIndex { None = 0, Member, Index, Method }
_ => null,
};

[GeneratedRegex(@"(?<=[^A-Z])([A-Z])", RegexOptions.None, matchTimeoutMilliseconds: 10)]
[GeneratedRegex(@"(?<=[^A-Z])([A-Z])", RegexOptions.None)]
private static partial Regex FirstCharInWord();

private static string GetMemberName(MemberInfo member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static bool ValidateProperty(string target, Regex? regex = null, [StringS
if (expr is null)
ThrowInvalidArgumentsException();

regex = new Regex(expr, RegexOptions.None, TimeSpan.FromMilliseconds(100));
regex = new Regex(expr, RegexOptions.None, TimeSpan.FromSeconds(1));
}

return regex.IsMatch(target);
Expand Down

0 comments on commit d54c645

Please sign in to comment.