question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can put editor compatible content into clipboard and bypass paste rules

See original GitHub issue

What’s the bug you are facing?

When I copied content from editor, I noticed that it actually copied the HTML and add special attribute data-pm-slice to mark this content copied from editor.

Then I can programmatically put content with the same data-pm-slice attribute into the clipboard, then paste content to editor. It will not trigger extension paste rules, but will trigger parseHTML function.

Users can also do the same thing from the console panel in browser DevTool. So I need to write repetitive rules in parseHTML function to verify everything is right.

How can we reproduce the bug on our side?

Open DevTool Console Panel in Chrome and execute following codes:

function setClipboard(html) {
    const type = "text/html";
    const blob = new Blob([text], { type });
    const data = [new ClipboardItem({ [type]: blob })];
    navigator.clipboard.write(data).then(
        function () {
          console.log('success');
        },
        function (e) {
            console.log('failed', e);
        }
    );
}

setTimeout(() => setClipboard(`<meta charset='utf-8'><p data-pm-slice="">{{ your content }}</p>`), 3000)

Focus current window

Paste to editor

Can you provide a CodeSandbox?

No response

What did you expect to happen?

I expect only content actually copied from editor will bypass paste rules. And when user mock the content programmatically, it should not be recognized as content copied from editor.

I am not sure if this is an issue or not. But it cause complex verify logic in parseHTML function. Because this content might come from user in an unexpected way.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
philippkuehncommented, Feb 9, 2022

You can do even more bad things in the console. I don’t think there is anything we can do about it.

0reactions
Luminqicommented, Feb 9, 2022

User can do this kind of thing in console panel in DevTool which I can not control

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure the copy and paste behavior
Fonto Editor can interact with the browser's clipboard to read pasted content from it and to write copied content to it. The data...
Read more >
Controlling copy-paste - Trellix Product Documentation
Clipboard protection rules are used to block or request justification for copying sensitive content from one application to another. The rule can define...
Read more >
Deprecated: Copying and pasting content in the rule editor - IBM
To cut or paste content in the rule editor, complete the following steps: You can copy the contents of an individual rule to...
Read more >
Interact with the clipboard - Mozilla - MDN Web Docs
This lets you access the data in the clipboard without pasting it into an editable element. Once you have the "clipboard-read" permission from ......
Read more >
Allow cut, copy or paste operations from the clipboard via script
This policy setting allows you to manage whether scripts can perform a clipboard operation (for example, cut, copy, and paste) in a specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found