Skip to content
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

Username validation for special characters #2277

Merged

Conversation

rutuja-amazon
Copy link
Contributor

@rutuja-amazon rutuja-amazon commented Nov 25, 2022

Add username validation:

  • Username should not include special characters

@shikharj05
Copy link
Contributor

Thank you for the change. Can you add tests as well?

@rutuja-amazon
Copy link
Contributor Author

Added unit tests.

@cwperks
Copy link
Member

cwperks commented Nov 25, 2022

@rutuja-amazon Should I add any backport labels to this PR?

@@ -133,6 +133,10 @@ public void testUserApi() throws Exception {
response = rh.executePutRequest(ENDPOINT + "/internalusers/", "{\"hash\": \"123\"}", new Header[0]);
Assert.assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, response.getStatusCode());

// username has special characters
response = rh.executePutRequest(ENDPOINT + "/internalusers/n@ag:ilum", "{\"hash\": \"123\"}", new Header[0]);
Assert.assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, response.getStatusCode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test case specifically related to this fix? If yes, why isn't it also HttpStatus.SC_BAD_REQUEST.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to updated all test cases that use special characters in username to now fail at creation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Then shouldn't this PUT request with special characters in username get HttpStatus.SC_BAD_REQUEST, which would be consistent with the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, updated to HttpStatus.SC_BAD_REQUEST.

@@ -93,6 +94,12 @@ protected void handlePut(RestChannel channel, final RestRequest request, final C
return;
}

Pattern usernamePattern = Pattern.compile("[$&+,:;=\\\\?@#|/'<>.^*()%!-]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think . should be allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permitted .. Do we also allow @ in username?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ shouldn't be allowed and only one . should be allowed. Thoughts? @cwperks @peternied @davidlago

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also allow -, _ and @ along with .? Please suggest.
In the current fix I have permitted the four special characters above.

@rutuja-amazon rutuja-amazon force-pushed the username-validation branch 4 times, most recently from a7d4d64 to ad27f3e Compare November 28, 2022 11:43
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2022

Codecov Report

Merging #2277 (3e552a9) into main (7cad5e4) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #2277      +/-   ##
============================================
+ Coverage     61.05%   61.07%   +0.01%     
  Complexity     3270     3270              
============================================
  Files           259      260       +1     
  Lines         18337    18369      +32     
  Branches       3248     3251       +3     
============================================
+ Hits          11196    11219      +23     
- Misses         5555     5563       +8     
- Partials       1586     1587       +1     
Impacted Files Coverage Δ
...security/dlic/rest/api/InternalUsersApiAction.java 83.78% <100.00%> (+1.43%) ⬆️
...ecurity/configuration/ConfigurationRepository.java 72.13% <0.00%> (-2.19%) ⬇️
.../dlic/auth/ldap2/LDAPConnectionFactoryFactory.java 57.46% <0.00%> (-1.50%) ⬇️
...iance/ComplianceIndexingOperationListenerImpl.java 61.76% <0.00%> (-1.48%) ⬇️
...arch/security/ssl/OpenSearchSecuritySSLPlugin.java 78.82% <0.00%> (-1.29%) ⬇️
...ensearch/security/ssl/DefaultSecurityKeyStore.java 67.28% <0.00%> (-0.55%) ⬇️
...amazon/dlic/util/SettingsBasedSSLConfigurator.java 62.30% <0.00%> (ø)
...opensearch/security/auditlog/sink/WebhookSink.java 76.74% <0.00%> (ø)
...opensearch/security/ssl/util/SSLRequestHelper.java 65.71% <0.00%> (ø)
...ensearch/security/ssl/util/SSLConfigConstants.java 77.77% <0.00%> (ø)
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change impacts forward combability as username might have been viable in older versions of OpenSearch that will no longer work.

@@ -93,6 +94,12 @@ protected void handlePut(RestChannel channel, final RestRequest request, final C
return;
}

Pattern usernamePattern = Pattern.compile("[$&+,:;=\\\\?@#|/'<>^*()%!-]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Username should not include special characters

Why not, are there bugs associated with these characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permitting special characters results in security risk & vulnerabilities.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking out for issues of this nature, could you be more specific as to the risks associated with individual characters? I am reticent to limit these usernames without cause.

If there is an issue please follow our reporting process [1] also quoted below.

Reporting a Vulnerability

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page or directly via email to aws-security@amazon.com. Please do not create a public GitHub issue.

[1] https://github.com/opensearch-project/security/security/policy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more details on the main thread #2277 (comment)

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
@rutuja-amazon
Copy link
Contributor Author

Requesting addition of backport labels @cwperks

@DarshitChanpura
Copy link
Member

@rutuja-amazon which branches would you like this change to be backported to?

@peternied
Copy link
Member

peternied commented Dec 1, 2022

@rutuja-amazon Since this is change is based on a LOW security finding we should discuss everything in the public on this pull request. Pulling in the context from our internal threads:

Bug

Repro

Create two users through the dashboards create internal user:

  • username: hello password: world:a_great_day
  • username: hello:world password: a_great_day

Attempt to logging to login via basic auth into both accounts
curl -k -s https://hello:world:a_great_day@localhost:9200/_plugins/_security/api/account | jq
curl -k -s https://hello:world:a_great_day@localhost:9200/_plugins/_security/api/account | jq (Both are the same!)

You cannot login as the user hello:world.

Additional details

Note; this is expected as the username cannot contain a colon [1].

As per CVSS rating (3.1), it's been categorized as LOW risk.

[1] https://stackoverflow.com/questions/11612854/http-https-basic-authentication-colon-in-username

For the moment, lets block only the colon character.

Signed-off-by: Peter Nied <petern@amazon.com>
@peternied
Copy link
Member

@rutuja-amazon I've created rutuja-amazon#1, if you merge that pull request into this change we can get this issue fixed, what do you think?

@rutuja-amazon
Copy link
Contributor Author

@rutuja-amazon I've created rutuja-amazon#1, if you merge that pull request into this change we can get this issue fixed, what do you think?

Issue is with other special characters as well, as discussed offline

@peternied
Copy link
Member

I've created an issue to track the set of special characters that should be included or not, and at this time the only exclusion that seems justified is colon :. Please feel free to discuss on the issue, but as this pull request stands its too restrictive without justification for me approve and merge.

@rutuja-amazon
Copy link
Contributor Author

rutuja-amazon commented Dec 9, 2022

Updated PR to only allow : for this use-case. Requesting merging this PR with backported labels.

Copy link
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me, once the code hygiene check is fixed I will approve this PR.

@peternied
Copy link
Member

The changes look good to me, once the code hygiene check is fixed I will approve this PR.

I'll take care of this to help get this merged more quickly...

Signed-off-by: Peter Nied <petern@amazon.com>
@peternied
Copy link
Member

Note; CI / build-artifact-names (pull_request) will fail because this hasn't merged the latest from main, and I'm am attempting to avoid rebasing these changes.

@peternied
Copy link
Member

Failing CI check is known fixed in main, merging!

@peternied peternied merged commit efbc48b into opensearch-project:main Dec 9, 2022
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-2277-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 efbc48b405ff6ff372c4821aa15c53fc50a409a3
# Push it to GitHub
git push --set-upstream origin backport/backport-2277-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

Then, create a pull request where the base branch is 1.x and the compare/head branch is backport/backport-2277-to-1.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.3 1.3
# Navigate to the new working tree
cd .worktrees/backport-1.3
# Create a new branch
git switch --create backport/backport-2277-to-1.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 efbc48b405ff6ff372c4821aa15c53fc50a409a3
# Push it to GitHub
git push --set-upstream origin backport/backport-2277-to-1.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.3

Then, create a pull request where the base branch is 1.3 and the compare/head branch is backport/backport-2277-to-1.3.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)
peternied pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)
peternied pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)
peternied pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)

Co-authored-by: rutuja-amazon <110013621+rutuja-amazon@users.noreply.github.com>
peternied pushed a commit that referenced this pull request Dec 9, 2022
* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)

Co-authored-by: rutuja-amazon <110013621+rutuja-amazon@users.noreply.github.com>
cwperks pushed a commit that referenced this pull request Dec 15, 2022
)

* Username validation for special characters (#2277)

* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)
peternied added a commit that referenced this pull request Jan 3, 2023
)

* Username validation for special characters (#2277)

* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)

* Fix compliation issue

Signed-off-by: Peter Nied <petern@amazon.com>

Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: rutuja-amazon <110013621+rutuja-amazon@users.noreply.github.com>
wuychn pushed a commit to ochprince/security that referenced this pull request Mar 16, 2023
…pensearch-project#2317)

* Only prevent user creation on colon characters, separate out tests

Signed-off-by: Rutuja Surve <rutuja@amazon.com>
Signed-off-by: Rutuja Surve <110013621+rutuja-amazon@users.noreply.github.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Co-authored-by: Peter Nied <petern@amazon.com>
(cherry picked from commit efbc48b)

Co-authored-by: rutuja-amazon <110013621+rutuja-amazon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x backport to 1.x branch backport 1.3 backport to 1.3 branch backport 2.x backport to 2.x branch backport 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants