0

I'm developing a web-tool (a TiddlyWiki Classic plugin) with contenteditable elements where I'd like to insert images by copy-pasting; then they should be then stored locally via a (PHP) server.

Among other stuff, the back-end should store images by url which are generated by copy-pasting an image from a web-page. My draft of the image-grabbing function is the following:

function loadImageByUrlAndSave($url,$path,$name)
{
    $url = filter_var($url,FILTER_SANITIZE_URL); //# not sure if this is really needed
    $img = file_get_contents($url);
    $type = "png";
    //# check for request errors, ensure we got an image, get its type automatically
    file_put_contents($path . $name . "." . $type,$img);
};

It works so far; however, I've read that using file_get_contents is not encouraged in such direct manner. I guess when this is used locally and by me only, the only security issue here is to avoid images that contain JavaScript (I've heard about this very little). What security measures would you suggest? Is it possible to automatically remove JavaScript from images? Is it removed in this workflow on the copy-paste stage so that I don't need to worry at all? I'd like to avoid any unexpected behaviour since that may corrupt data in my TW.

YakovL
  • 7,557
  • 12
  • 62
  • 102
  • This should be helpful: https://codereview.stackexchange.com/q/24824/166475, will read it carefully – YakovL Apr 07 '18 at 22:11
  • May be also https://codereview.stackexchange.com/q/144880/166475 , https://codereview.stackexchange.com/q/36411/166475 and more here: https://codereview.stackexchange.com/search?q=upload+image+security+is%3Aquestion – YakovL Apr 07 '18 at 22:22

0 Answers0