Rule Definition
Authentication failures may expose underlying authorization failures as well. When authentication controls fail, the solution is unable to verify the user's identity
Remediation
Ensure you have enclosed the GoogleSignInAccount account try/catch to check if account is set or not
Violation Code Sample
private boolean setupClient(@NonNull SharedPreferences prefs) {
final GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.build();
final GoogleSignInClient signInClient = GoogleSignIn.getClient(mContext, signInOptions);
final GoogleSignInAccount signInAccount = Tasks.await(signInClient.silentSignIn());
if(signInAccount) {
Log.d(TAG, "Connection successful. ");
return true;
}
Log.w(TAG, "Connection failed!");
return false;
}
Fixed Code Sample
private boolean setupClient(@NonNull SharedPreferences prefs) {
final GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.build();
final GoogleSignInClient signInClient = GoogleSignIn.getClient(mContext, signInOptions);
try {
final GoogleSignInAccount signInAccount = Tasks.await(signInClient.silentSignIn());
mClient = Drive.getDriveClient(mContext, signInAccount);
mResourceClient = Drive.getDriveResourceClient(mContext, signInAccount);
Log.d(TAG, "Connection successful. sync: " + mShouldSync + " media: " + mMediaMounted);
return true;
} catch(ExecutionException e) {
final ApiException result = (ApiException)e.getCause();
switch(result.getStatusCode()) {
case GoogleSignInStatusCodes.SIGN_IN_REQUIRED:
case GoogleSignInStatusCodes.INVALID_ACCOUNT:
Log.i(TAG, "User not signed in. Disabling photo syncing.");
prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply();
break;
case GoogleSignInStatusCodes.API_NOT_CONNECTED:
case GoogleSignInStatusCodes.NETWORK_ERROR:
case GoogleSignInStatusCodes.INTERNAL_ERROR:
Log.i(TAG, "Google Drive service unavailable. Disabling photo syncing.");
prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply();
}
Log.w(TAG, "Connection failed! Reason: " + result.getMessage());
} catch(InterruptedException ignored) {
}
return false;
}
Reference
https://www.owasp.org/index.php/Mobile_Top_10_2016-M4-Insecure_Authentication
https://developers.google.com/identity/sign-in/android/
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.