Skip to content

Commit

Permalink
RHPAM-4719: Replace single qoute with nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
domhanak committed Jun 27, 2023
1 parent b8eaab5 commit cc2b241
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public Response addBranch(@PathParam("spaceName") String spaceName,
jobRequest.setJobId(id);
jobRequest.setSpaceName(spaceName);
jobRequest.setProjectName(projectName);
jobRequest.setNewBranchName(StringEscapeUtils.escapeHtml4(addBranchRequest.getNewBranchName()));
jobRequest.setNewBranchName(escapeHtmlInput(addBranchRequest.getNewBranchName()));
jobRequest.setBaseBranchName(addBranchRequest.getBaseBranchName());
jobRequest.setUserIdentifier(sessionInfo.getIdentity().getIdentifier());
addAcceptedJobResult(id);
Expand Down Expand Up @@ -455,6 +455,16 @@ private ProjectResponse getProjectResponse(WorkspaceProject workspaceProject) {
return projectResponse;
}

private String escapeHtmlInput(String input) {
if (input != null) {
String escapedInput = StringEscapeUtils.escapeHtml4(input);
escapedInput = escapedInput.replace("'", "");
return escapedInput;
} else {
return null;
}
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/spaces/{spaceName}/projects/{projectName}/maven/compile")
Expand Down Expand Up @@ -685,7 +695,7 @@ public Response createSpace(Space space) {
jobRequest.setJobId(id);
jobRequest.setSpaceName(space.getName());
jobRequest.setDescription(space.getDescription());
jobRequest.setOwner(StringEscapeUtils.escapeHtml4(space.getOwner()));
jobRequest.setOwner(escapeHtmlInput(space.getOwner()));
jobRequest.setDefaultGroupId(space.getDefaultGroupId());
addAcceptedJobResult(id);

Expand All @@ -710,7 +720,7 @@ public Response updateSpace(Space space) {
jobRequest.setJobId(id);
jobRequest.setSpaceName(space.getName());
jobRequest.setDescription(space.getDescription());
jobRequest.setOwner(StringEscapeUtils.escapeHtml4(space.getOwner()));
jobRequest.setOwner(escapeHtmlInput(space.getOwner()));
jobRequest.setDefaultGroupId(space.getDefaultGroupId());
addAcceptedJobResult(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ public void updateSpace() throws Exception {
assertEquals(JobStatus.ACCEPTED, jobResultArgumentCaptor.getValue().getStatus());
}

@Test
public void updateSpaceWithXSSOwer() throws Exception {
String xssOwner = "<img/src/onerror=alert(\"XSS\")>";
Space testedSpace = new Space();
testedSpace.setOwner(xssOwner);
projectResource.updateSpace(testedSpace);

verify(jobManager).putJob(jobResultArgumentCaptor.capture());
assertEquals(JobStatus.ACCEPTED, jobResultArgumentCaptor.getValue().getStatus());
}

@Test
public void createSpaceWithXSSOwner() throws Exception {
String xssOwner = "<img/src/onerror=alert(document.cookie)>";
Space testedSpace = new Space();
testedSpace.setOwner(xssOwner);
projectResource.createSpace(testedSpace);

verify(jobManager).putJob(jobResultArgumentCaptor.capture());
assertEquals(JobStatus.ACCEPTED, jobResultArgumentCaptor.getValue().getStatus());
}

@Test
public void deleteSpace() throws Exception {

Expand All @@ -334,6 +356,19 @@ public void addBranch() {
assertEquals(JobStatus.ACCEPTED, jobResultArgumentCaptor.getValue().getStatus());
}

@Test
public void addBranchWithXSSName() {
AddBranchRequest addBranchRequest = new AddBranchRequest();
addBranchRequest.setNewBranchName("<img/src/onerror=alert(\"Xss\")>");

projectResource.addBranch("spaceName",
"projectName",
addBranchRequest);

verify(jobManager).putJob(jobResultArgumentCaptor.capture());
assertEquals(JobStatus.ACCEPTED, jobResultArgumentCaptor.getValue().getStatus());
}

@Test
public void removeBranch() {
projectResource.removeBranch("spaceName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ private Collection<Contributor> escapeContributorsNames(Collection<Contributor>
Collection<Contributor> escapedContributors = new ArrayList<>();
contributors.forEach((contributor -> {
String escapedName = StringEscapeUtils.escapeHtml4(contributor.getUsername());
escapedName = escapedName.replace("'", "");
escapedContributors.add(new Contributor(escapedName, contributor.getType()));
}));
return escapedContributors;
Expand Down

0 comments on commit cc2b241

Please sign in to comment.