Skip to content

Commit

Permalink
username validation for special chars
Browse files Browse the repository at this point in the history
Signed-off-by: Rutuja Surve <[email protected]>
  • Loading branch information
rutuja-amazon committed Nov 25, 2022
1 parent 7cad5e4 commit 39b2627
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -93,6 +95,12 @@ protected void handlePut(RestChannel channel, final RestRequest request, final C
return;
}

Pattern usernamePattern = Pattern.compile("[$&+,:;=\\\\?@#|/'<>.^*()%!-]");
if (usernamePattern.matcher(username).find()) {
badRequestResponse(channel, "Username has special characters, not permitted.");
return;
}

// TODO it might be sensible to consolidate this with the overridden method in
// order to minimize duplicated logic

Expand Down

0 comments on commit 39b2627

Please sign in to comment.