Skip to content

Commit ee0725f

Browse files
authored
Merge pull request #248 from Microsoft/dm/regexfix
Fix for regex to potentially prevent catastrophic backtracking
2 parents c83ae29 + b95f137 commit ee0725f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class OpenApiResponsesRules
2828
});
2929

3030
/// <summary>
31-
/// The response key must either be "default" or an HTTP status code (1xx, 2xx, 3xx, 4xx, 5xx)
31+
/// The response key must either be "default" or an HTTP status code (1xx, 2xx, 3xx, 4xx, 5xx).
3232
/// </summary>
3333
public static ValidationRule<OpenApiResponses> ResponsesMustBeIdentifiedByDefaultOrStatusCode =>
3434
new ValidationRule<OpenApiResponses>(
@@ -38,7 +38,7 @@ public static class OpenApiResponsesRules
3838
{
3939
context.Enter(key);
4040

41-
if (key != "default" && !Regex.IsMatch(key, "^[1-5]([0-9][0-9]|XX)$"))
41+
if (key != "default" && !Regex.IsMatch(key, "^[1-5](?>[0-9]{2}|XX)$"))
4242
{
4343
context.CreateError(nameof(ResponsesMustBeIdentifiedByDefaultOrStatusCode),
4444
"Responses key must be 'default', an HTTP status code, " +
@@ -50,4 +50,4 @@ public static class OpenApiResponsesRules
5050
}
5151
});
5252
}
53-
}
53+
}

0 commit comments

Comments
 (0)