Ditto icon indicating copy to clipboard operation
Ditto copied to clipboard

Ignore copy feature

Open matthewacarson opened this issue 1 year ago • 11 comments

Hi. Sometimes I have to copy passwords from Chrome's password manager manually--i.e, autofill doesn't work. Only problem is that they end up in Ditto.

I know that excluding Chrome entirely wouldn't work, so would it be possible to create a hotkey that allows Windows to copy text as it normally does but have Ditto ignore it?

I'm not much of a programmer aside from R, but I imagine that this would require Ditto to initiate the copy command to the Windows API while having Ditto temporarily ignore the clipboard or something like that. This could be assigned to Ctrl+Alt+C or something like that (probably best to leave that up to the end user, though).

matthewacarson avatar Mar 08 '24 20:03 matthewacarson

It would be great to have js or regex to filter out clipboard items.

lyaaz avatar Oct 15 '24 06:10 lyaaz

How would I use them to keep passwords out of Ditto?

matthewacarson avatar Oct 15 '24 13:10 matthewacarson

Most of my passwords are generated by a password manager, so I use this script in CopyQ to filter out items that look like passwords.

function isPassword(str) {

    const minLength = 8;
    const maxLength = 64;
    const trimStr = str.trim();

    if (trimStr.length < minLength || trimStr.length > maxLength) {
        return false;
    }
    if (/[^0-9a-zA-Z!@#$%^&*=]/.test(trimStr)) {
        return false;
    }
    
    const isEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimStr);
    const isBase64 = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(trimStr);
    const isHex = /^0x(?:[0-9a-f]+|[0-9A-F]+)$/.test(trimStr); 

    const hasUpperCase = /[A-Z]/.test(trimStr);
    const hasLowerCase = /[a-z]/.test(trimStr);
    const hasNumbers = /[0-9]/.test(trimStr);
    const hasSpecialChar = /[!@#$%^&*=]/.test(trimStr);

    const typeCount = [hasUpperCase, hasLowerCase, hasNumbers, hasSpecialChar].filter(Boolean).length;
    
    if (isEmail) {
        return false;
    }
    if (isBase64) {
        return false;
    }
    if (isHex) {
        return false;
    }

    return typeCount >= 3;
}

function isPasswdLike() {
    if (dataFormats().includes(mimeText)) {
        var text = str(data(mimeText));
        if (isPassword(text)) {
            serverLog('Ignoring text like password');
            return true;
        }
    }
    return false;
}

var onClipboardChanged_ = onClipboardChanged;
onClipboardChanged = function() {
    if (!isPasswdLike()) {
        onClipboardChanged_();
    }
}

var synchronizeFromSelection_ = synchronizeFromSelection;
synchronizeFromSelection = function() {
    if (!isPasswdLike()) {
        synchronizeFromSelection_();
    }
}

var synchronizeToSelection_ = synchronizeToSelection;
synchronizeToSelection = function() {
    if (!isPasswdLike()) {
        synchronizeToSelection_();
    }
}

lyaaz avatar Oct 15 '24 13:10 lyaaz

So are you using this script with a different clipboard manager? Are you not using Ditto?


From: lyaaz notifications-at-github.com |github-carsonm| @.> Sent: Tuesday, October 15, 2024 6:49:42 AM To: *********************** <***********>; sabrogden/Ditto @.> Cc: Matt Carson @.>; Author @.> Subject: Re: [sabrogden/Ditto] Ignore copy feature (Issue #634)

Most of my passwords are generated by a password manager, so I use this script in CopyQ to filter out items that look like passwords.

function isPassword(str) {

const minLength = 8;
const maxLength = 64;
const trimStr = str.trim();

if (trimStr.length < minLength || trimStr.length > maxLength) {
    return false;
}
if (/[^0-9a-zA-Z!@#$%^&*=]/.test(trimStr)) {
    return false;
}

const isEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimStr);
const isBase64 = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(trimStr);
const isHex = /^0x(?:[0-9a-f]+|[0-9A-F]+)$/.test(trimStr);

const hasUpperCase = /[A-Z]/.test(trimStr);
const hasLowerCase = /[a-z]/.test(trimStr);
const hasNumbers = /[0-9]/.test(trimStr);
const hasSpecialChar = /[!@#$%^&*=]/.test(trimStr);

const typeCount = [hasUpperCase, hasLowerCase, hasNumbers, hasSpecialChar].filter(Boolean).length;

if (isEmail) {
    return false;
}
if (isBase64) {
    return false;
}
if (isHex) {
    return false;
}

return typeCount >= 3;

}

function isPasswdLike() { if (dataFormats().includes(mimeText)) { var text = str(data(mimeText)); if (isPassword(text)) { serverLog('Ignoring text like password'); return true; } } return false; }

var onClipboardChanged_ = onClipboardChanged; onClipboardChanged = function() { if (!isPasswdLike()) { onClipboardChanged_(); } }

var synchronizeFromSelection_ = synchronizeFromSelection; synchronizeFromSelection = function() { if (!isPasswdLike()) { synchronizeFromSelection_(); } }

var synchronizeToSelection_ = synchronizeToSelection; synchronizeToSelection = function() { if (!isPasswdLike()) { synchronizeToSelection_(); } }

— Reply to this email directly, view it on GitHubhttps://github.com/sabrogden/Ditto/issues/634#issuecomment-2413976705, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHGGKB5LHGQZ74JHSQ6UVU3Z3UMPNAVCNFSM6AAAAABP6LUDCWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJTHE3TMNZQGU. You are receiving this because you authored the thread.Message ID: @.***>

matthewacarson avatar Oct 15 '24 14:10 matthewacarson

So are you using this script with a different clipboard manager? Are you not using Ditto?

I previously used CopyQ and just switched to Ditto.

lyaaz avatar Oct 15 '24 14:10 lyaaz

I just discovered that Ditto also supports scripting, which can be found in Options > Advanced.

the version for ditto (This is my first time using ChaiScript, so there might be some bugs) :

var minLength = 8;
var maxLength = 64;
if (clip.GetAsciiString().size() < minLength || clip.GetAsciiString().size() > maxLength) {
    return false;
}
if (clip.AsciiTextMatchesRegex("^[0-9a-zA-Z!@#$%^&*=]+$") == 0) {
    return false;
}

var isEmail = clip.AsciiTextMatchesRegex("^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$");
var isBase64 = clip.AsciiTextMatchesRegex("^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=)?$");
var isHex = clip.AsciiTextMatchesRegex("^0x(?:[0-9a-f]+|[0-9A-F]+)$");
if (isEmail + isBase64 + isHex >= 1) {
    return false;
}

var hasUpperCase = clip.AsciiTextMatchesRegex(".*[A-Z].*");
var hasLowerCase = clip.AsciiTextMatchesRegex(".*[a-z].*");
var hasNumbers = clip.AsciiTextMatchesRegex(".*[0-9].*");
var hasSpecialChar = clip.AsciiTextMatchesRegex(".*[!@#$%^&*=].*");

var typeCount = hasUpperCase + hasLowerCase + hasNumbers + hasSpecialChar;
if (typeCount >= 3) {
    return true;
}

return false;

lyaaz avatar Oct 15 '24 15:10 lyaaz

As far as I can see, the issue discussed here still affects Ditto as of 03.25.76. Ticket #241 discusses the same issue. @matthewacarson: Please use a title which describes the problem. I would suggest:

No way to copy single selection without creating Ditto entry (temporary system clipboard disconnection for passwords or other confidential data)

Chealer avatar Sep 11 '25 19:09 Chealer

Stop bumping all these old issues to the top when you have nothing of value to contribute @Chealer, other than your worthless commentary or critic.

garoto avatar Sep 11 '25 22:09 garoto

@Chealer My title describes the problem just fine. If you don't like it, create a new issue yourself.

matthewacarson avatar Sep 11 '25 23:09 matthewacarson

The approach @lyaaz suggests is heuristic, which means:

  • It can mitigate the issue, but not solve it.
  • It will create false positives (selections which would bypass Ditto when they should not).

A proper implementation would need to prompt the user or provide feedback.


@matthewacarson wrote:

@Chealer My title describes the problem just fine.

Issue reports can describe solutions, but should emphasize the problem, in particular in the title.

The description you wrote does not describe the problem, but is clear enough that most readers should deduce it. However, the title does not describe the problem at all. I am not saying my suggestion is ideal, but the current title is substandard. Other possibility:

No shortcut to bypass Ditto for single copy (temporary system clipboard disconnection for passwords or other confidential data)

Additionally, the way you title your suggested solution is far from clear. "copy" is highly polysemous, even just as a noun. For example, compare a ticket titled in this one’s fashion:

❌Big text

…with a proper title for the same issue:

✅Documentation: Poor title legibility (gray on grayer background)

@matthewacarson wrote:

If you don't like it, create a new issue yourself.

Creating an issue?😂 This project already reportedly has half a thousand… let’s avoid!


@garoto: Feel free to clarify what you mean by "bumping all these old issues to the top" if you have something to contribute… or to stay quiet.


License This comment and any other I might add to this ticket is offered under the terms of CC0 1.0.

Chealer avatar Sep 12 '25 13:09 Chealer

Go fuck yourself

matthewacarson avatar Sep 12 '25 13:09 matthewacarson