Repository navigation
[SM-2126] Updating regex #8809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cd-bitwarden
wants to merge
6
commits into
main
Choose a base branch
from
SM-2126-Vuln
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[SM-2126] Updating regex #8809
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f2d5298
Fixing vulnerability with regex
cd-bitwarden 0ce67f2
Merge branch 'main' into SM-2126-Vuln
cd-bitwarden e6f6198
Merge branch 'main' into SM-2126-Vuln
cd-bitwarden c179fb9
Merge branch 'main' into SM-2126-Vuln
cd-bitwarden 6dadf97
Merge branch 'main' into SM-2126-Vuln
cd-bitwarden ff75361
Merge branch 'main' into SM-2126-Vuln
cd-bitwarden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| namespace Bit.Core.Utilities; | ||
|
|
||
| /// <summary> | ||
| /// Process-wide defaults for <see cref="System.Text.RegularExpressions.Regex"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Deliberately kept free of any static <c>Regex</c> fields: the default match timeout is read once, | ||
| /// when the <c>Regex</c> type is first initialized, so it must be configured before any regular | ||
| /// expression is constructed anywhere in the process. | ||
| /// </remarks> | ||
| public static class RegexDefaults | ||
| { | ||
| /// <summary> | ||
| /// The timeout applied to every <c>Regex</c> that does not specify its own. | ||
| /// </summary> | ||
| public static readonly TimeSpan DefaultMatchTimeout = TimeSpan.FromSeconds(5); | ||
|
|
||
| /// <summary> | ||
| /// Configures a process-wide default <c>Regex</c> match timeout as defence in depth against | ||
| /// catastrophic backtracking on untrusted input (CWE-1333). Call this as the very first | ||
| /// statement of <c>Main</c>, before anything else has a chance to construct a <c>Regex</c>. | ||
| /// </summary> | ||
| public static void ConfigureDefaultMatchTimeout() | ||
| { | ||
| AppContext.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", DefaultMatchTimeout); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/Api.Test/SecretsManager/Models/Request/RequestSMAccessRequestModelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Bit.Api.SecretsManager.Models.Request; | ||
| using Xunit; | ||
|
|
||
| namespace Bit.Api.Test.SecretsManager.Models.Request; | ||
|
|
||
| public class RequestSMAccessRequestModelTests | ||
| { | ||
| [Theory] | ||
| [InlineData("I need access to the deployment secrets.")] | ||
| [InlineData("x")] | ||
| public void Validate_WithReasonableNote_ReturnsNoErrors(string emailContent) | ||
| { | ||
| var results = Validate(BuildModel(emailContent)); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Validate_WithNoteAtMaxLength_ReturnsNoErrors() | ||
| { | ||
| var results = Validate(BuildModel(new string('a', RequestSMAccessRequestModel.MaxEmailContentLength))); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Validate_WithNoteOverMaxLength_ReturnsError() | ||
| { | ||
| var results = Validate(BuildModel(new string('a', RequestSMAccessRequestModel.MaxEmailContentLength + 1))); | ||
|
|
||
| var error = Assert.Single(results); | ||
| Assert.Contains(nameof(RequestSMAccessRequestModel.EmailContent), error.MemberNames); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(null)] | ||
| [InlineData("")] | ||
| public void Validate_WithMissingNote_ReturnsError(string? emailContent) | ||
| { | ||
| var results = Validate(BuildModel(emailContent)); | ||
|
|
||
| var error = Assert.Single(results); | ||
| Assert.Contains(nameof(RequestSMAccessRequestModel.EmailContent), error.MemberNames); | ||
| } | ||
|
|
||
| private static RequestSMAccessRequestModel BuildModel(string? emailContent) => new() | ||
| { | ||
| OrganizationId = Guid.NewGuid(), | ||
| EmailContent = emailContent!, | ||
| }; | ||
|
|
||
| private static List<ValidationResult> Validate(RequestSMAccessRequestModel model) | ||
| { | ||
| var results = new List<ValidationResult>(); | ||
| Validator.TryValidateObject(model, new ValidationContext(model), results, true); | ||
| return results; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ QUESTION: Were the
SsoandScimhosts left out on purpose? Both reference Core, but neitherMaincallsConfigureDefaultMatchTimeout().Details and fix
The PR description says the timeout is set "in each service host's Main". That is true for the eight hosts under
src/, butbitwarden_license/src/Sso/Program.csandbitwarden_license/src/Scim/Program.csare unchanged. Both referenceCore.csproj, and both already haveusing Bit.Core.Utilities;. So those two processes still run everyRegexwith no timeout, and SSO handles external IdP input.If the omission is not intentional, add this as the first statement of each
Main:code-review