Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit 1f0b0ea

Browse files
committed
Disable logging by default
Summary: Logging was turned on unconditionally before, which led to apps leaking sensitive data. This change puts the logging api behind an explicit gate that developers have to turn on. It's unfortunate that this isn't automatic - ideally this would automatically turn on for non-release signed bits. I couldn't find such a check in Android framework. If android experts have better ways of tackling this, i'm all ears. But bear in mind this is a security fix and needs to go out asap. Test Plan: Launched in default mode and verified no logging in emulator. Turned on log gate and verified logging. Reviewers: mmarucheck, lshepard, yariv, raghuc1 Reviewed By: mmarucheck CC: gregschechte, jacl Differential Revision: https://phabricator.fb.com/D411377 Task ID: 933141
1 parent fc4785c commit 1f0b0ea

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

facebook/src/com/facebook/android/Facebook.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import android.os.Messenger;
4040
import android.os.RemoteException;
4141
import android.text.TextUtils;
42-
import android.util.Log;
4342
import android.webkit.CookieSyncManager;
4443

4544
/**
@@ -349,7 +348,7 @@ public void onComplete(Bundle values) {
349348
setAccessToken(values.getString(TOKEN));
350349
setAccessExpiresIn(values.getString(EXPIRES));
351350
if (isSessionValid()) {
352-
Log.d("Facebook-authorize", "Login Success! access_token="
351+
Util.logd("Facebook-authorize", "Login Success! access_token="
353352
+ getAccessToken() + " expires="
354353
+ getAccessExpires());
355354
mAuthDialogListener.onComplete(values);
@@ -360,17 +359,17 @@ public void onComplete(Bundle values) {
360359
}
361360

362361
public void onError(DialogError error) {
363-
Log.d("Facebook-authorize", "Login failed: " + error);
362+
Util.logd("Facebook-authorize", "Login failed: " + error);
364363
mAuthDialogListener.onError(error);
365364
}
366365

367366
public void onFacebookError(FacebookError error) {
368-
Log.d("Facebook-authorize", "Login failed: " + error);
367+
Util.logd("Facebook-authorize", "Login failed: " + error);
369368
mAuthDialogListener.onFacebookError(error);
370369
}
371370

372371
public void onCancel() {
373-
Log.d("Facebook-authorize", "Login canceled");
372+
Util.logd("Facebook-authorize", "Login canceled");
374373
mAuthDialogListener.onCancel();
375374
}
376375
});
@@ -405,19 +404,19 @@ public void authorizeCallback(int requestCode, int resultCode, Intent data) {
405404
if (error != null) {
406405
if (error.equals(SINGLE_SIGN_ON_DISABLED)
407406
|| error.equals("AndroidAuthKillSwitchException")) {
408-
Log.d("Facebook-authorize", "Hosted auth currently "
407+
Util.logd("Facebook-authorize", "Hosted auth currently "
409408
+ "disabled. Retrying dialog auth...");
410409
startDialogAuth(mAuthActivity, mAuthPermissions);
411410
} else if (error.equals("access_denied")
412411
|| error.equals("OAuthAccessDeniedException")) {
413-
Log.d("Facebook-authorize", "Login canceled by user.");
412+
Util.logd("Facebook-authorize", "Login canceled by user.");
414413
mAuthDialogListener.onCancel();
415414
} else {
416415
String description = data.getStringExtra("error_description");
417416
if (description != null) {
418417
error = error + ":" + description;
419418
}
420-
Log.d("Facebook-authorize", "Login failed: " + error);
419+
Util.logd("Facebook-authorize", "Login failed: " + error);
421420
mAuthDialogListener.onFacebookError(
422421
new FacebookError(error));
423422
}
@@ -427,7 +426,7 @@ public void authorizeCallback(int requestCode, int resultCode, Intent data) {
427426
setAccessToken(data.getStringExtra(TOKEN));
428427
setAccessExpiresIn(data.getStringExtra(EXPIRES));
429428
if (isSessionValid()) {
430-
Log.d("Facebook-authorize",
429+
Util.logd("Facebook-authorize",
431430
"Login Success! access_token="
432431
+ getAccessToken() + " expires="
433432
+ getAccessExpires());
@@ -443,7 +442,7 @@ public void authorizeCallback(int requestCode, int resultCode, Intent data) {
443442

444443
// An Android error occured.
445444
if (data != null) {
446-
Log.d("Facebook-authorize",
445+
Util.logd("Facebook-authorize",
447446
"Login failed: " + data.getStringExtra("error"));
448447
mAuthDialogListener.onError(
449448
new DialogError(
@@ -453,7 +452,7 @@ public void authorizeCallback(int requestCode, int resultCode, Intent data) {
453452

454453
// User pressed the 'back' button.
455454
} else {
456-
Log.d("Facebook-authorize", "Login canceled by user.");
455+
Util.logd("Facebook-authorize", "Login canceled by user.");
457456
mAuthDialogListener.onCancel();
458457
}
459458
}

facebook/src/com/facebook/android/FbDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private class FbWebViewClient extends WebViewClient {
131131

132132
@Override
133133
public boolean shouldOverrideUrlLoading(WebView view, String url) {
134-
Log.d("Facebook-WebView", "Redirect URL: " + url);
134+
Util.logd("Facebook-WebView", "Redirect URL: " + url);
135135
if (url.startsWith(Facebook.REDIRECT_URI)) {
136136
Bundle values = Util.parseUrl(url);
137137

@@ -175,7 +175,7 @@ public void onReceivedError(WebView view, int errorCode,
175175

176176
@Override
177177
public void onPageStarted(WebView view, String url, Bitmap favicon) {
178-
Log.d("Facebook-WebView", "Webview loading URL: " + url);
178+
Util.logd("Facebook-WebView", "Webview loading URL: " + url);
179179
super.onPageStarted(view, url, favicon);
180180
mSpinner.show();
181181
}

facebook/src/com/facebook/android/Util.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
*/
4848
public final class Util {
4949

50+
/**
51+
* Set this to true to enable log output. Remember to turn this back off
52+
* before releasing. Sending sensitive data to log is a security risk.
53+
*/
54+
private static boolean ENABLE_LOG = false;
55+
5056
/**
5157
* Generate the multi-part post body providing the parameters and boundary
5258
* string
@@ -144,7 +150,7 @@ public static String openUrl(String url, String method, Bundle params)
144150
if (method.equals("GET")) {
145151
url = url + "?" + encodeUrl(params);
146152
}
147-
Log.d("Facebook-Util", method + " URL: " + url);
153+
Util.logd("Facebook-Util", method + " URL: " + url);
148154
HttpURLConnection conn =
149155
(HttpURLConnection) new URL(url).openConnection();
150156
conn.setRequestProperty("User-Agent", System.getProperties().
@@ -298,4 +304,17 @@ public static void showAlert(Context context, String title, String text) {
298304
alertBuilder.create().show();
299305
}
300306

307+
/**
308+
* A proxy for Log.d api that kills log messages in release build. It
309+
* not recommended to send sensitive information to log output in
310+
* shipping apps.
311+
*
312+
* @param tag
313+
* @param msg
314+
*/
315+
public static void logd(String tag, String msg) {
316+
if (ENABLE_LOG) {
317+
Log.d(tag, msg);
318+
}
319+
}
301320
}

0 commit comments

Comments
 (0)