-
Notifications
You must be signed in to change notification settings - Fork 282
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
Username validation for special characters #2277
Conversation
39b2627
to
d895275
Compare
Thank you for the change. Can you add tests as well? |
d895275
to
ba09e9d
Compare
Added unit tests. |
ba09e9d
to
3d5f259
Compare
@rutuja-amazon Should I add any backport labels to this PR? |
3d5f259
to
c7f7ee1
Compare
@@ -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()); |
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.
Is this test case specifically related to this fix? If yes, why isn't it also HttpStatus.SC_BAD_REQUEST
.
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.
Yes, we need to updated all test cases that use special characters in username
to now fail at creation
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.
Agreed. Then shouldn't this PUT
request with special characters in username
get HttpStatus.SC_BAD_REQUEST
, which would be consistent with the fix?
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.
Sounds good, updated to HttpStatus.SC_BAD_REQUEST
.
c7f7ee1
to
d207161
Compare
@@ -93,6 +94,12 @@ protected void handlePut(RestChannel channel, final RestRequest request, final C | |||
return; | |||
} | |||
|
|||
Pattern usernamePattern = Pattern.compile("[$&+,:;=\\\\?@#|/'<>.^*()%!-]"); |
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.
I think .
should be allowed
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.
Permitted .
. Do we also allow @
in username?
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.
@
shouldn't be allowed and only one .
should be allowed. Thoughts? @cwperks @peternied @davidlago
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.
Do we also allow -
, _
and @
along with .
? Please suggest.
In the current fix I have permitted the four special characters above.
a7d4d64
to
ad27f3e
Compare
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
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("[$&+,:;=\\\\?@#|/'<>^*()%!-]"); |
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.
Username should not include special characters
Why not, are there bugs associated with these characters?
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.
permitting special characters results in security risk & vulnerabilities.
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.
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 [email protected]. Please do not create a public GitHub issue.
[1] https://github.com/opensearch-project/security/security/policy
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.
Added more details on the main thread #2277 (comment)
Signed-off-by: Rutuja Surve <[email protected]>
ad27f3e
to
2958f40
Compare
Requesting addition of backport labels @cwperks |
@rutuja-amazon which branches would you like this change to be backported to? |
@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:
For the moment, lets block only the colon character. |
Signed-off-by: Peter Nied <[email protected]>
@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 |
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 |
Updated PR to only allow |
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.
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 <[email protected]>
Note; |
Failing CI check is known fixed in main, merging! |
The backport to
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 |
The backport to
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 |
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b)
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b)
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b)
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b)
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b) Co-authored-by: rutuja-amazon <[email protected]>
* Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b) Co-authored-by: rutuja-amazon <[email protected]>
) * Username validation for special characters (#2277) * Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b)
) * Username validation for special characters (#2277) * Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b) * Fix compliation issue Signed-off-by: Peter Nied <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: rutuja-amazon <[email protected]>
…pensearch-project#2317) * Only prevent user creation on colon characters, separate out tests Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Rutuja Surve <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit efbc48b) Co-authored-by: rutuja-amazon <[email protected]>
Add username validation: