mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1730194 - Prevent Copy button to send information to Cloud Clipboard and Clipboard History on Windows r=dimi,johannh,cmartin
Differential Revision: https://phabricator.services.mozilla.com/D125831
This commit is contained in:
parent
d9c4a57805
commit
f00d159f71
@ -121,7 +121,7 @@ class AboutLoginsChild extends JSWindowActorChild {
|
||||
break;
|
||||
}
|
||||
case "AboutLoginsCopyLoginDetail": {
|
||||
ClipboardHelper.copyString(event.detail);
|
||||
ClipboardHelper.copyString(event.detail, ClipboardHelper.Sensitive);
|
||||
break;
|
||||
}
|
||||
case "AboutLoginsCreateLogin": {
|
||||
|
@ -1481,6 +1481,15 @@
|
||||
#endif
|
||||
mirror: always
|
||||
|
||||
#ifdef XP_WIN
|
||||
# allow to copy clipboard data to Clipboard History/Cloud
|
||||
# (used on sensitive data in about:logins and Private Browsing)
|
||||
- name: clipboard.copyPrivateDataToClipboardCloudOrHistory
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
#endif
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Prefs starting with "consoleservice."
|
||||
#---------------------------------------------------------------------------
|
||||
|
@ -36,7 +36,8 @@ nsClipboardHelper::~nsClipboardHelper() {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
|
||||
int32_t aClipboardID) {
|
||||
int32_t aClipboardID,
|
||||
SensitiveData aSensitive) {
|
||||
nsresult rv;
|
||||
|
||||
// get the clipboard
|
||||
@ -69,6 +70,9 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
|
||||
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
||||
|
||||
trans->Init(nullptr);
|
||||
if (aSensitive == SensitiveData::Sensitive) {
|
||||
trans->SetIsPrivateData(true);
|
||||
}
|
||||
|
||||
// Add the text data flavor to the transferable
|
||||
rv = trans->AddDataFlavor(kUnicodeMime);
|
||||
@ -102,11 +106,13 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsClipboardHelper::CopyString(const nsAString& aString) {
|
||||
nsClipboardHelper::CopyString(const nsAString& aString,
|
||||
SensitiveData aSensitive) {
|
||||
nsresult rv;
|
||||
|
||||
// copy to the global clipboard. it's bad if this fails in any way.
|
||||
rv = CopyStringToClipboard(aString, nsIClipboard::kGlobalClipboard);
|
||||
rv = CopyStringToClipboard(aString, nsIClipboard::kGlobalClipboard,
|
||||
aSensitive);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// unix also needs us to copy to the selection clipboard. this will
|
||||
@ -118,7 +124,7 @@ nsClipboardHelper::CopyString(const nsAString& aString) {
|
||||
// if this fails in any way other than "not being unix", we'll get
|
||||
// the assertion we need in CopyStringToClipboard, and we needn't
|
||||
// assert again here.
|
||||
CopyStringToClipboard(aString, nsIClipboard::kSelectionClipboard);
|
||||
CopyStringToClipboard(aString, nsIClipboard::kSelectionClipboard, aSensitive);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -18,19 +18,28 @@
|
||||
[scriptable, uuid(438307fd-0c68-4d79-922a-f6cc9550cd02)]
|
||||
interface nsIClipboardHelper : nsISupports
|
||||
{
|
||||
cenum SensitiveData : 8 {
|
||||
NotSensitive = 0,
|
||||
Sensitive = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* copy string to given clipboard
|
||||
*
|
||||
* @param aString, the string to copy to the clipboard
|
||||
* @param aClipboardID, the ID of the clipboard to copy to
|
||||
* (eg. kSelectionClipboard -- see nsIClipboard.idl)
|
||||
* @param aSensitive, optional flag to indicate that data is sensitive, like a password.
|
||||
* That will exclude data from Cloud Clipboard/Clipboard History on Windows.
|
||||
*/
|
||||
void copyStringToClipboard(in AString aString, in long aClipboardID);
|
||||
void copyStringToClipboard(in AString aString, in long aClipboardID,
|
||||
[optional, default(NotSensitive)] in nsIClipboardHelper_SensitiveData aSensitive);
|
||||
|
||||
/**
|
||||
* copy string to (default) clipboard
|
||||
*
|
||||
* @param aString, the string to copy to the clipboard
|
||||
*/
|
||||
void copyString(in AString aString);
|
||||
void copyString(in AString aString,
|
||||
[optional, default(NotSensitive)] in nsIClipboardHelper_SensitiveData aSensitive);
|
||||
};
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "mozilla/StaticPrefs_clipboard.h"
|
||||
#include "nsArrayUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDataObj.h"
|
||||
@ -147,6 +148,29 @@ nsresult nsClipboard::CreateNativeDataObject(nsITransferable* aTransferable,
|
||||
return res;
|
||||
}
|
||||
|
||||
static nsresult StoreValueInDataObject(nsDataObj* aObj,
|
||||
LPCWSTR aClipboardFormat, DWORD value) {
|
||||
HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(DWORD));
|
||||
if (!hGlobalMemory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
DWORD* pdw = (DWORD*)::GlobalLock(hGlobalMemory);
|
||||
*pdw = value;
|
||||
::GlobalUnlock(hGlobalMemory);
|
||||
|
||||
STGMEDIUM stg;
|
||||
stg.tymed = TYMED_HGLOBAL;
|
||||
stg.pUnkForRelease = nullptr;
|
||||
stg.hGlobal = hGlobalMemory;
|
||||
|
||||
FORMATETC fe;
|
||||
SET_FORMATETC(fe, ::RegisterClipboardFormat(aClipboardFormat), 0,
|
||||
DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
||||
aObj->SetData(&fe, &stg, TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsClipboard::SetupNativeDataObject(nsITransferable* aTransferable,
|
||||
IDataObject* aDataObj) {
|
||||
@ -253,6 +277,23 @@ nsresult nsClipboard::SetupNativeDataObject(nsITransferable* aTransferable,
|
||||
}
|
||||
}
|
||||
|
||||
if (!StaticPrefs::clipboard_copyPrivateDataToClipboardCloudOrHistory()) {
|
||||
// Let Clipboard know that data is sensitive and must not be copied to
|
||||
// the Cloud Clipboard, Clipboard History and similar.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats#cloud-clipboard-and-clipboard-history-formats
|
||||
if (aTransferable->GetIsPrivateData()) {
|
||||
nsresult rv =
|
||||
StoreValueInDataObject(dObj, TEXT("CanUploadToCloudClipboard"), 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv =
|
||||
StoreValueInDataObject(dObj, TEXT("CanIncludeInClipboardHistory"), 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = StoreValueInDataObject(
|
||||
dObj, TEXT("ExcludeClipboardContentFromMonitorProcessing"), 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user