From 528941fc27ede9f9ff7440f9428c5207b4431539 Mon Sep 17 00:00:00 2001 From: "dolske%mozilla.com" Date: Wed, 23 Sep 2009 21:06:46 +0000 Subject: [PATCH] Bug 511639 - Login manager should ignore untrusted events. r=gavin, sr=mconnor, a190=dveditz git-svn-id: svn://10.0.0.236/trunk@258483 18797224-902f-48f8-a5cc-f745e15eee43 --- .../passwordmgr/src/nsLoginManager.js | 3 ++ .../test/test_basic_form_autocomplete.html | 38 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js b/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js index b25c0eca267..652f0f5cca7 100644 --- a/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js +++ b/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js @@ -316,6 +316,9 @@ LoginManager.prototype = { handleEvent : function (event) { + if (!event.isTrusted) + return; + this._pwmgr.log("domEventListener: got event " + event.type); var doc, inputElement; diff --git a/mozilla/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html b/mozilla/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html index 61202bd9419..831f99f5ee3 100644 --- a/mozilla/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html +++ b/mozilla/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html @@ -150,6 +150,12 @@ function doKey(aKey, modifier) { } +function sendFakeAutocompleteEvent(element) { + var acEvent = document.createEvent("HTMLEvents"); + acEvent.initEvent("DOMAutoComplete", true, false); + element.dispatchEvent(acEvent); +} + /* * Main section of test... @@ -161,7 +167,11 @@ function doKey(aKey, modifier) { */ function runTest(testNum) { // Seems we need to enable this again, or sendKeyEvent() complaints. - netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + // But don't for test 14, or else dispatchEvent will send it as a trusted + // event (we're testing to see if we ignore untrusted events, so don't want + // that). + if (testNum != 14) + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); ok(true, "Starting test #" + testNum); switch(testNum) { @@ -323,6 +333,19 @@ function runTest(testNum) { doKey("page_down"); doKey("return"); checkACForm("zzzuser4", "zzzpass4"); + restoreForm(); + break; + + case 14: + // Send a fake (untrusted) event. + checkACForm("", ""); + uname.value = "zzzuser4"; + sendFakeAutocompleteEvent(uname); + checkACForm("zzzuser4", ""); + break; + + case 15: + checkACForm("zzzuser4", ""); // Trigger autocomplete popup restoreForm(); @@ -330,19 +353,6 @@ function runTest(testNum) { testNum = 49; break; - case 14: - // Abort with ESC -// XXX This isn't working in the test suite, seems to fubar any later tests. -// doKey("down"); -// doKey("down"); -// doKey("escape"); -// checkACForm("", ""); - - // Trigger autocomplete popup -// restoreForm(); -// doKey("down"); - break; - // XXX tried sending character "t" before/during dropdown to test // filtering, but had no luck. Seemed like the character was getting lost. // Setting uname.value didn't seem to work either. This works with a human