-
Notifications
You must be signed in to change notification settings - Fork 155
8268775: Password is being converted to String in AccessibleJPasswordField #127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -510,20 +510,19 @@ private String getEchoString(String str) { | |
| * @since 1.6 | ||
| */ | ||
| public String getAtIndex(int part, int index) { | ||
| String str = null; | ||
| if (part == AccessibleText.CHARACTER) { | ||
| str = super.getAtIndex(part, index); | ||
| return getEchoString(super.getAtIndex(part, index)); | ||
| } else { | ||
| // Treat the text displayed in the JPasswordField | ||
| // as one word and sentence. | ||
| char[] password = getPassword(); | ||
| if (password == null || | ||
| index < 0 || index >= password.length) { | ||
| int length = getDocument().getLength(); | ||
| if (index < 0 || index >= length) { | ||
| return null; | ||
| } | ||
| str = new String(password); | ||
| char[] password = new char[length]; | ||
| Arrays.fill(password, getEchoChar()); | ||
| return new String(password); | ||
| } | ||
| return getEchoString(str); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -544,8 +543,7 @@ public String getAtIndex(int part, int index) { | |
| */ | ||
| public String getAfterIndex(int part, int index) { | ||
| if (part == AccessibleText.CHARACTER) { | ||
| String str = super.getAfterIndex(part, index); | ||
| return getEchoString(str); | ||
| return getEchoString(super.getAfterIndex(part, index)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how removing the local variable changes anything. Explanation ??
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it is just a slight code cleanup. We do not need additional variable for passing value from one method to another. It serves no other purpose at all.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me ask it this way.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For CHARACTER it will return String with a single character in the corresponding position. There is a possibility that someone will iterate the entirety of the password text and get all the characters in the password as a separate strings but digging it from the memory dump is much more difficult than the singular string with the whole password. |
||
| } else { | ||
| // There is no word or sentence after the text | ||
| // displayed in the JPasswordField. | ||
|
|
@@ -571,8 +569,7 @@ public String getAfterIndex(int part, int index) { | |
| */ | ||
| public String getBeforeIndex(int part, int index) { | ||
| if (part == AccessibleText.CHARACTER) { | ||
| String str = super.getBeforeIndex(part, index); | ||
| return getEchoString(str); | ||
| return getEchoString(super.getBeforeIndex(part, index)); | ||
| } else { | ||
| // There is no word or sentence before the text | ||
| // displayed in the JPasswordField. | ||
|
|
@@ -627,14 +624,14 @@ public AccessibleTextSequence getTextSequenceAt(int part, int index) { | |
| } else { | ||
| // Treat the text displayed in the JPasswordField | ||
| // as one word, sentence, line and attribute run | ||
| char[] password = getPassword(); | ||
| if (password == null || | ||
| index < 0 || index >= password.length) { | ||
| int length = getDocument().getLength(); | ||
| if (index < 0 || index >= length) { | ||
| return null; | ||
| } | ||
| char[] password = new char[length]; | ||
| Arrays.fill(password, getEchoChar()); | ||
| String text = new String(password); | ||
| return new AccessibleTextSequence(0, password.length - 1, | ||
| getEchoString(text)); | ||
| return new AccessibleTextSequence(0, password.length - 1, text); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the accessible text is just the right number of "echo" chars. If it weren't for all of this (the class and the getPassword() method being non-final I'd suggest you look into a way to pull just the length rather than the actual chars.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. But not as a string - and the window of opportunity to get the characters before they are overwritten by the echo characters is minimal.
Since in order to enter non-BPM characters you have to have an input methods helper which should be disabled on password fields for obvious reason - it would pretty much disclose the typed password in the IM helper window - the only way to enter such symbols would b copy/paste and in this case i do not expect it to be edited within password field.
Well, accessibility is not only about text to speech - it is also about easier navigation so having exact number of the bullets is preferable. There are limitations - like some non-BPM text can be pasted into the password field and then navigating within it might be broken but since there will be no IM engaged fixing it would be equally problematic.
That would be preferable but under the current circumstances i would say that my fix makes things better without adding incompatible changes.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the "getDocument().getLength()"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We can surely do that. Fixed. |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how removing the local variable changes anything. Explanation ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is just a slight code cleanup. We do not need additional variable for passing value from one method to another. It serves no other purpose at all. It was used before on the second leg of the if but the usage was removed so it became useless.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is about security, I don’t see how it might help. There is a chance that the heap dump might capture the content of the local variable. If you submit your heap dump to someone, whom you do not trust, I have bad news for you.
The probability of the heap dump to capture a local variable is more than zero. True, but less than probable.
I don’t know if calling same methods in a single line makes this control more secure (if we take the situation that the heap dump pauses an execution of the thread exactly at our „moment of time“). I am not a member of the project JDK, but I doubt that this PR solves something.
To me, an additional local variable adds better supportability (debugging) to this code. Otherwise everything should be put into a single fat method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As i said above this exact change is not about making code more secure - it is just to eliminate additional variable that has no purpose after the second half of the method is changed. I would say that it would add to the supportability if we do anything with this information - but we don't.