Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent copying images from Word #558

Closed
simogeo opened this issue Jun 23, 2017 · 11 comments
Closed

Prevent copying images from Word #558

simogeo opened this issue Jun 23, 2017 · 11 comments
Labels
plugin:pastefromword The plugin which probably causes the issue. type:feature A feature request.

Comments

@simogeo
Copy link

simogeo commented Jun 23, 2017

New feature regarding pastefromword (kind of bug)

Cpy-paste from Word embed images base64 encoded which may caused issue when saving content to database. For example, TEXT type in MySQL does not support more than 65,535 (2^16 – 1) characters.
See : https://stackoverflow.com/questions/2569838/mysql-data-type-text-erroring-data-too-long

Some ckeditor users have already created scripts to prevent this. For example here : http://www.isummation.com/blog/block-drag-drop-image-or-direct-image-paste-into-ckeditor-using-firefox/

I think this should be included in plugin itself as a config parameters.

Images could simply be dynamically removed or an alert should be send to users. Some options may be considered as well....

System information

  • Browser: all
  • OS: all
  • CKEditor version: all versions
  • Installed CKEditor plugins: pastefromword
@msamsel msamsel added plugin:pastefromword The plugin which probably causes the issue. type:feature A feature request. labels Jul 3, 2017
@msamsel
Copy link
Contributor

msamsel commented Jul 3, 2017

Thank you for description this situation. I mark this issue as feature request.

@jswiderski
Copy link
Contributor

@simogeo I have a question.

Of course CKEditor could have such config setting to simply block dropped image. I completely agree here but wouldn't it be better from your application point of view to save HTML pages as CLOB instead of TEXT or perhaps extract, change base64 image into real image on the server side, save it into DB and replace long string with URL to image?

@jswiderski
Copy link
Contributor

I think this issue is related to this one: #662

@jswiderski jswiderski added status:confirmed An issue confirmed by the development team. and removed status:confirmed An issue confirmed by the development team. labels Aug 3, 2017
@simogeo
Copy link
Author

simogeo commented Aug 17, 2017

thanks @jswiderski for your interesting feedback and sorry for the delay - I was on leave.

I agree regarding the DB settings. TEXT could be replaced by CLOB but in some (or many) cases, it would not follow comprehensible developer choice to store images as external files only.

I like your proposal of extracting / converting to real image / replacing / and finally save into the DB but it is related to server-side and dependant on programmation language (for my part, i use PHP). Do you think, this should be handled by the word plugin itself or should it be externalised ?

Anyway, I still think that the priority is to give the ability to dynamically remove images with plugin config settings.

@jswiderski
Copy link
Contributor

Do you think, this should be handled by the word plugin itself or should it be externalised ?

I think I wasn't clear enough in my last email. I have meant exactly what you have written - extracting base64 string, converting it to real image, saving the image on e.g. dedicated server, replacing base64string with an image tag with short url and finally saving HTML into DB should be handled by server-side code.

@simogeo
Copy link
Author

simogeo commented Oct 19, 2017

Hi @jswiderski : any chance to have an option to block dropped image soon or not ? Just to know if I shoul implement some extra code such this myself.

Thanks for your reply

@simogeo
Copy link
Author

simogeo commented Oct 22, 2017

For others :

CKEDITOR.on("instanceReady", function(evt) {
                  var editor = evt.editor;
                  editor.on("afterPasteFromWord", function(evt) {

                    
                    // Clone the filter, so that it is based on current editor filter settings.
                    // Note that this function is added in CKE 4.7.3.
                    var filter = evt.editor.filter.clone(),
                        fragment = CKEDITOR.htmlParser.fragment.fromHtml( evt.data.dataValue ),
                        writer = new CKEDITOR.htmlParser.basicWriter();

                    // Disallow image copy/paste
                    filter.disallow('img' );
        
                    // Process, and overwrite evt.data.dataValue.
                    filter.applyTo( fragment );
                    fragment.writeHtml( writer );
                    evt.data.dataValue = writer.getHtml();
                          });
                    });

@msamsel
Copy link
Contributor

msamsel commented Dec 18, 2017

@simogeo from 4.8.0 we start embed images pasted from word. You should be able now to disallow on embedding images pasted from word with this config option: https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config-cfg-pasteFromWord_inlineImages

@simogeo
Copy link
Author

simogeo commented Dec 18, 2017

Hi @msamsel : great option. Thanks for implementing it !

@simogeo simogeo closed this as completed Dec 18, 2017
@msamsel
Copy link
Contributor

msamsel commented Dec 18, 2017

No problem :) I hope this solution will cover your case.

@damien-git
Copy link

I think it would be better to have a setting to prevent inline images entirely. "Paste from Word" is only one of the many ways to insert a base64 image in CKEditor. I don't see a particular reason to prevent it with a "Paste from Word" action but allow it in another way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin:pastefromword The plugin which probably causes the issue. type:feature A feature request.
Projects
None yet
Development

No branches or pull requests

4 participants