Bug 1433030 - Stop nsTransferable writing to /tmp in PB windows r=jdm

We shouldn't assume it's safe to write to /tmp unless we know
for sure we are not in a private browsing window. So
use mPrivateData = true as default.

Based on a patch by Neill Miller:
https://trac.torproject.org/projects/tor/ticket/21830
This commit is contained in:
Arthur Edelstein 2018-02-12 10:34:00 +02:00
Родитель b3561c0819
Коммит 7d2a9476f0
2 изменённых файлов: 30 добавлений и 27 удалений

Просмотреть файл

@ -222,7 +222,7 @@ DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen)
//
//-------------------------------------------------------------------------
nsTransferable::nsTransferable()
: mPrivateData(false)
: mPrivateData(true)
, mContentPolicyType(nsIContentPolicy::TYPE_OTHER)
#ifdef DEBUG
, mInitialized(false)

Просмотреть файл

@ -37,36 +37,39 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(Ipsum);
// Disabled private browsing mode should cache large selections to disk
ok(clipboardFile.exists(), "correctly saved memory by caching to disk");
// Undefined private browsing mode should not cache to disk
ok(!clipboardFile.exists(), "correctly avoided caching to disk when PBM is undefined");
// Sanitize environment again
if (clipboardFile.exists()) {
clipboardFile.remove(false);
}
ok(!clipboardFile.exists(), "failed to postsanitize the environment");
// Repeat procedure of plain text selection with private browsing enabled
// Repeat procedure of plain text selection with private browsing
// disabled and enabled
ChromeUtils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
var Winpriv = window.open("about:blank", "_blank", "chrome, width=500, height=200, private");
ok(Winpriv, "failed to open private window");
ok(PrivateBrowsingUtils.isContentWindowPrivate(Winpriv), "correctly used a private window context");
// Select plaintext in private channel
ChromeUtils.import('resource://gre/modules/Services.jsm');
const nsTransferable = Components.Constructor("@mozilla.org/widget/transferable;1", "nsITransferable");
const nsSupportsString = Components.Constructor("@mozilla.org/supports-string;1", "nsISupportsString");
var Loadctx = PrivateBrowsingUtils.privacyContextFromWindow(Winpriv);
var Transfer = nsTransferable();
var Suppstr = nsSupportsString();
Suppstr.data = Ipsum;
Transfer.init(Loadctx);
Transfer.addDataFlavor("text/plain");
Transfer.setTransferData("text/plain", Suppstr, Ipsum.length);
Services.clipboard.setData(Transfer, null, Services.clipboard.kGlobalClipboard);
for (let private of [false, true]) {
// Sanitize environment again
if (clipboardFile.exists()) {
clipboardFile.remove(false);
}
ok(!clipboardFile.exists(), "failed to postsanitize the environment");
// Enabled private browsing mode should not cache any selection to disk
ok(!clipboardFile.exists(), "did not violate private browsing mode");
var win = window.open("about:blank", "_blank", "chrome, width=500, height=200" + (private ? ", private" : ""));
ok(win, "failed to open private window");
is(PrivateBrowsingUtils.isContentWindowPrivate(win), private, "used correct window context");
// Select plaintext in private channel
const nsTransferable = Components.Constructor("@mozilla.org/widget/transferable;1", "nsITransferable");
const nsSupportsString = Components.Constructor("@mozilla.org/supports-string;1", "nsISupportsString");
var Loadctx = PrivateBrowsingUtils.privacyContextFromWindow(win);
var Transfer = nsTransferable();
var Suppstr = nsSupportsString();
Suppstr.data = Ipsum;
Transfer.init(Loadctx);
Transfer.addDataFlavor("text/plain");
Transfer.setTransferData("text/plain", Suppstr, Ipsum.length);
Services.clipboard.setData(Transfer, null, Services.clipboard.kGlobalClipboard);
// Enabled private browsing mode should not cache any selection to disk; disabled should
is(!clipboardFile.exists(), private, "did not violate private browsing mode");
}
}
]]>
</script>