I got this code adapted from the official Java-Tutorial Page Console - Java Tutorial
public class RedirectOutputStreamExample {
public static void main(String[] args) throws InterruptedException {
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String login = ((Console) c).readLine("Enter your login: ");
char [] oldPassword = c.readPassword("Enter your old password: ");
if (verify(login, oldPassword)) {
boolean noMatch;
do {
char [] newPassword1 = c.readPassword("Enter your new password: ");
char [] newPassword2 = c.readPassword("Enter new password again: ");
noMatch = ! Arrays.equals(newPassword1, newPassword2);
if (noMatch) {
c.format("Passwords don't match. Try again.%n");
} else {
c.format("Password for %s changed.%n", login);
}
Arrays.fill(newPassword1, ' ');
Arrays.fill(newPassword2, ' ');
System.out.println("password is: "+newPassword1);
System.out.println("password is: "+newPassword2);
} while (noMatch);
}
Arrays.fill(oldPassword, ' ');
System.out.println(oldPassword);
Thread.sleep(60000);
}
}
After the three passwords have been overwritten, they are printed out as empty lines (as expected). As you see:
(I had to do it in the console cause the IntelliJ terminal had security problems and threw the error "no Console")
However, after the program was halted, a memory dump was created using jmap and the process ID.
My entered password was still visible in the memory dump as you see:
How is that possible? Did I do something wrong? Is there a weak default security configuration in my JVM?
I asked ChatGPT and it suggests that console uses Strings in its internal operations.


changedo?verifymethod? Could it be holding a copy of the password?