Skip to content

Commit

Permalink
Prevent Klipper from storing secrets in clipboard history (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZ3ro authored and droidmonkey committed Aug 29, 2018
1 parent ca27fb0 commit 08a36b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/gui/Clipboard.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -19,6 +20,7 @@

#include <QApplication>
#include <QClipboard>
#include <QMimeData>
#include <QTimer>

#include "core/Config.h"
Expand Down Expand Up @@ -46,15 +48,20 @@ void Clipboard::setText(const QString& text)
{
QClipboard* clipboard = QApplication::clipboard();

#ifdef Q_OS_MAC
QMimeData* mime = new QMimeData;
#ifdef Q_OS_MAC
mime->setText(text);
mime->setData("application/x-nspasteboard-concealed-type", text.toUtf8());
clipboard->setMimeData(mime, QClipboard::Clipboard);
#else
clipboard->setText(text, QClipboard::Clipboard);
const QString secretStr = "secret";
QByteArray secretBa = secretStr.toUtf8();
mime->setText(text);
mime->setData("x-kde-passwordManagerHint", secretBa);
clipboard->setMimeData(mime, QClipboard::Clipboard);

if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
clipboard->setMimeData(mime, QClipboard::Selection);
}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/gui/Clipboard.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
Expand Down

0 comments on commit 08a36b4

Please sign in to comment.