Avoid leaking access token to log by filter it out

This commit is contained in:
khanhduytran0 2020-10-10 11:13:50 +07:00
parent 7ccb47d206
commit 546791d938
3 changed files with 18 additions and 5 deletions

View file

@ -47,7 +47,7 @@ public class InstallModActivity extends LoggableActivity
appendToLog("");
}
});
JREUtils.redirectAndPrintJRELog(this);
JREUtils.redirectAndPrintJRELog(this, null);
final File modFile = (File) getIntent().getExtras().getSerializable("modFile");
final String javaArgs = getIntent().getExtras().getString("javaArgs");

View file

@ -40,7 +40,8 @@ public class JREUtils
}
}
public static void redirectAndPrintJRELog(final LoggableActivity act) {
private static boolean checkAccessTokenLeak = true;
public static void redirectAndPrintJRELog(final LoggableActivity act, final String accessToken) {
JREUtils.redirectLogcat();
Log.v("jrelog","Log starts here");
Thread t = new Thread(new Runnable(){
@ -59,12 +60,24 @@ public class JREUtils
while ((line = reader.readLine()) != null) {
act.appendlnToLog(line);
}
reader.close();
*/
byte[] buf = new byte[512];
byte[] buf = new byte[1024];
int len;
while ((len = p.getInputStream().read(buf)) != -1) {
act.appendToLog(new String(buf, 0, len));
String currStr = new String(buf, 0, len);
// Avoid leaking access token to log by replace it.
// Also, Minecraft will just print it once.
if (checkAccessTokenLeak) {
checkAccessTokenLeak = false;
if (accessToken != null && accessToken.length() > 5 && currStr.contains(accessToken)) {
currStr.replace(accessToken, "ACCESS_TOKEN_HIDDEN");
}
}
act.appendToLog(currStr);
}
} catch (IOException e) {
Log.e("jrelog-logcat", "IOException on logging thread");

View file

@ -952,7 +952,7 @@ public class MainActivity extends LoggableActivity implements OnTouchListener, O
// checkJavaArgsIsLaunchable();
appendlnToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");
JREUtils.redirectAndPrintJRELog(this);
JREUtils.redirectAndPrintJRELog(this, mProfile.getAccessToken());
Tools.launchMinecraft(this, mProfile, mVersionInfo);
}