Skip to content

Commit

Permalink
Fix SSO on applications with shared uid
Browse files Browse the repository at this point in the history
Signed-off-by: Erfan Abdi <[email protected]>
  • Loading branch information
erfanoabdi committed Nov 21, 2023
1 parent 574cfae commit 1bcef78
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/src/main/java/com/nextcloud/android/sso/InputStreamBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,23 @@ private Response processRequestV2(final NextcloudRequest request, final InputStr
}

private boolean isValid(NextcloudRequest request) {
String callingPackageName = context.getPackageManager().getNameForUid(Binder.getCallingUid());
String[] callingPackageNames = context.getPackageManager().getPackagesForUid(Binder.getCallingUid());

SharedPreferences sharedPreferences = context.getSharedPreferences(SSO_SHARED_PREFERENCE,
Context.MODE_PRIVATE);
String hash = sharedPreferences.getString(callingPackageName + DELIMITER + request.getAccountName(), "");
return validateToken(hash, request.getToken());
for (String callingPackageName : callingPackageNames) {
String hash = sharedPreferences.getString(callingPackageName + DELIMITER + request.getAccountName(), "");
if (hash.isEmpty())
continue;
if (validateToken(hash, request.getToken())) {
return true;
}
}
return false;
}

private boolean validateToken(String hash, String token) {
if (hash.isEmpty() || !hash.contains("$")) {
if (!hash.contains("$")) {
throw new IllegalStateException(EXCEPTION_INVALID_TOKEN);
}

Expand Down

0 comments on commit 1bcef78

Please sign in to comment.