Open ElijahLynn opened 5 years ago
When I copy a password from the LastPass Chrome Extension it shows in CopyQ. How can I stop that from happening?
Unfortunately, there is no easy way to tell that a password is copied to clipboard.
It's possible to ignore password managers by their window titles but sometimes that doesn't work.
Another way could be ignore some text patterns depending on the way passwords are generated. Or even ignore content by a hash though it requires to explicitly "blacklist" hashes. I could post a command to do that later.
edit: looks like one workaround for now is to right click on tray icon and "disable clipboard storing". Would be nice if the tray icon changed when it was disabled.
Well, the tray icon normally changes when it's disabled. Could be that the notification area on your system or the icon theme doesn't allow it.
Well, the tray icon normally changes when it's disabled. Could be that the notification area on your system or the icon theme doesn't allow it.
Oh, I see it changing now, it just wasn't obvious, the scissors is closed when disabled, open when enabled.
Thanks for clarifying there isn't a way to currently do this and listing some of the challenges around doing this. Can you elaborate on ignoring content by blacklisting hashes? I am not understanding how that would work with passwords. Thanks.
Below is command that will show popup to blacklist a password (here is how to add the command to CopyQ).
After adding the command, you'll be able to click "blacklist" button in notification which pops up for a second after copying a text. Blacklisting the text removes it from clipboard tab and it will be ignored next time it's copied ("whitelist" notification should pop up instead).
The command only stores salted hash of blacklisted texts so it's possible to figure out whether a copied text should be ignored without needing to remember the text itself.
[Command]
Command="
/*
Shows notification to blacklist copied text.
Blacklisted text will be removed from clipboard tab and ignored
(unless whitelisted again).
*/
var blacklistConfigKey = 'blacklisted-hashes'
var blacklistNotificationId = 'blacklist-notification'
var notificationTimeoutSeconds = 4
function blacklistedHashes() {
return settings(blacklistConfigKey) || []
}
function setBlacklistedHashes(hashes) {
return settings(blacklistConfigKey, hashes)
}
function removeItemHash(hash) {
for (var i = 2; i >= 0; --i) {
var text = read(mimeText, i)
if ( hash == calculateTextHash(text) )
remove(i)
}
}
function notifyClipboardBlacklisted(hash) {
notification(
'.id', blacklistNotificationId,
'.time', notificationTimeoutSeconds * 1000,
'.title', 'Clipboard Blacklisted',
'.button', 'Whitelist', 'copyq whitelistHash ' + hash
)
}
function notifyClipboardToBlacklist(hash) {
notification(
'.id', blacklistNotificationId,
'.time', notificationTimeoutSeconds * 1000,
'.title', 'Blacklist?',
'.button', 'Blacklist', 'copyq blacklistHash ' + hash
)
}
global.isHashBlacklisted = function(hash) {
return blacklistedHashes().indexOf(hash) !== -1
}
global.blacklistHash = function(hash) {
hash = str(hash)
var hashes = blacklistedHashes()
if ( hashes.indexOf(hash) !== -1 )
return;
hashes.push(hash)
setBlacklistedHashes(hashes)
removeItemHash(hash)
setTitle()
}
global.whitelistHash = function(hash) {
hash = str(hash)
var hashes = blacklistedHashes()
var i = hashes.indexOf(hash)
if (i === -1)
return;
hashes.splice(i, 1)
setBlacklistedHashes(hashes)
}
global.calculateTextHash = function(text) {
var salt = 'This is just some random salt prefix.'
var saltedText = salt + str(text)
return sha256sum(saltedText)
}
var onClipboardChanged_ = global.onClipboardChanged
global.onClipboardChanged = function() {
var hash = calculateTextHash(data(mimeText))
if ( isHashBlacklisted(hash) ) {
notifyClipboardBlacklisted(hash)
} else {
onClipboardChanged_()
notifyClipboardToBlacklist(hash)
}
}
var onOwnClipboardChanged_ = global.onOwnClipboardChanged
global.onOwnClipboardChanged = function() {
var hash = calculateTextHash(data(mimeText))
if ( !isHashBlacklisted(hash) ) {
notifyClipboardToBlacklist(hash)
onOwnClipboardChanged_()
}
}"
Icon=\xf05e
Input=text/plain
IsScript=true
Name=Blacklisted Texts
Remove=true
Nice, thank you, this is working! I did have trouble with the help, paste command was greyed out, so I pressed F6, clicked "+Add", clicked "Command" tab, pasted in command and exited and it asked me to save. Now it works!
I do wonder if a simpler way to solve this is for all users is to have a special keyboard shortcut for copying. Like Ctrl + Shift + C
for instance.
One odd behavior is that if I just select text, the blacklist window pops up. Does that mean my OS clipboard (xsel) is actually copying to clipboard on selection, maybe?
One odd behavior is that if I just select text, the blacklist window pops up. Does that mean my OS clipboard (xsel) is actually copying to clipboard on selection, maybe?
I've updated the command a bit and added it to the copyq-commands repo: https://github.com/hluk/copyq-commands/tree/master/Scripts#blacklisted-texts
I do wonder if a simpler way to solve this is for all users is to have a special keyboard shortcut for copying. Like
Ctrl + Shift + C
for instance.
I think it could be done with something like this:
[Command]
Command="
copyq:
try {
var wasMonitoring = monitoring()
if (wasMonitoring)
disable()
copy()
if (wasMonitoring)
enable()
} catch (e) {
}"
GlobalShortcut=ctrl+shift+c
Icon=\xf6fa
IsGlobalShortcut=true
Name=Copy a Secret
One odd behavior is that if I just select text, the blacklist window pops up. Does that mean my OS clipboard (xsel) is actually copying to clipboard on selection, maybe?
I've updated the command a bit and added it to the copyq-commands repo: https://github.com/hluk/copyq-commands/tree/master/Scripts#blacklisted-texts
Nice, this new one fixes the issue I had!
I do wonder if a simpler way to solve this is for all users is to have a special keyboard shortcut for copying. Like
Ctrl + Shift + C
for instance.I think it could be done with something like this:
[Command] Command=" copyq: try { var wasMonitoring = monitoring() if (wasMonitoring) disable() copy() if (wasMonitoring) enable() } catch (e) { }" GlobalShortcut=ctrl+shift+c Icon=\xf6fa IsGlobalShortcut=true Name=Copy a Secret
This is working great, I think I prefer this method and will keep it enabled over the blacklist method!!!
Oh yes, I still need to leave the Blacklist on for passwords I copy with LastPass' Copy Password menu item. This plays nice with ctrl + shift + c
too and doesn't pop up when I use that shortcut to copy a cleartext password.
@ElijahLynn I did a small fix for the "Copy a Secret" command [1] and uploaded it the repository: https://github.com/hluk/copyq-commands/tree/master/Global#copy-a-secret
[1] If copy operation failed the clipboard storing was not re-enabled.
Thanks, I found that ctrl + shift + c
conflicted with the terminal shortcut for copying text, so I tried ctr + shift + alt + c
and it doesn't take the shortcut, I feel like it is because of the alt
key.
I chose ctrl + shift + k
for now, with your new command. Thanks!
When I copy a password from the LastPass Chrome Extension it shows in CopyQ. How can I stop that from happening?
edit: looks like one workaround for now is to right click on tray icon and "disable clipboard storing". Would be nice if the tray icon changed when it was disabled.