Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
do not accidentally show password as username
Browse files Browse the repository at this point in the history
fix #7649

Test Plan:
1. automated tests for notificationBar should pass
2. changing the password on https://reg.ebay.com/reg/ChangePwd and clicking 'submit' should not show the current password in the notification bar
  • Loading branch information
diracdeltas committed Mar 11, 2017
1 parent 58b98a5 commit 56537e5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/extensions/brave/content/scripts/passwordManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ if (chrome.contentSettings.passwordManager == 'allow') {
// Last resort: find the first text input in the form
username = username || form.querySelector('input[type=text i]')

// If the username turns out to be a password field, just ignore it so
// we don't show the password in plaintext.
if (username) {
let autocomplete = username.getAttribute('autocomplete')
if (username.getAttribute('type') === 'password' ||
(autocomplete && autocomplete.includes('password'))) {
username = null
}
}

// If not a submission, autofill the first password field and ignore the rest
if (!isSubmission || passwords.length === 1) {
return [username instanceof HTMLInputElement ? username : null, passwords[0], null]
Expand Down
14 changes: 14 additions & 0 deletions test/components/notificationBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('notificationBar', function () {
this.loginUrl3 = Brave.server.url('login3.html')
this.loginUrl4 = Brave.server.url('login4.html')
this.loginUrl5 = Brave.server.url('login5.html')
this.loginUrl6 = Brave.server.url('login6.html')
yield setup(this.app.client)
})

Expand Down Expand Up @@ -105,6 +106,19 @@ describe('notificationBar', function () {
}).click('button=No')
})

it('does not include a password in the notification bar', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl6)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
return this.getText(notificationBar).then((val) => {
return val.includes('your password') && !val.includes('secret')
})
}).click('button=No')
})

it('autofills remembered password on login form', function * () {
yield this.app.client
.tabByIndex(0)
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/login6.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<body>
<script>
window.onload = window.setTimeout(function () {
if (!document.querySelector('#password').value) {
document.querySelector('#password').value = 'secret'
document.querySelector('#old-password').value = 'secret'
document.querySelector('#new-password').value = 'secret2'
document.querySelector('#submit').click()
}
}, 200)
</script>
<form action="/blah" name="ChangePassForm" id="ChangePassForm">
<input type="hidden" id="countryId" name="countryId" value="1" />
<input type="hidden" name="MfcISAPICommand" value="HandleNewPassword">
<input type="hidden" name="srt" value="01"><div class="rclSir"></div>
<input id='password' type="password" name="user" />
<input id='old-password' type="password" autocomplete="current-password" />
<input id='new-password' type="password" autocomplete="new-password" />
<input id="submit" type="submit" value="Change password" />
</form>
</body>

0 comments on commit 56537e5

Please sign in to comment.