# How to prevent leakage of exif information?

**URL:** <https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508>\
**Category:** Questions\
**Tags:** v3\
**Created:** [May 16, 2022, 3:19pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508 "2022-05-16T15:19:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipptrenz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/philipptrenz/32/11084_2.png) [@philipptrenz](https://forum.getkirby.com/u/philipptrenz)\
**Post date:** [May 16, 2022, 3:19pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/1 "2022-05-16T15:19:35Z")

</div>

Hey there!

Most photos contain sensitive exif data, like geo coordinates. As I just found out via a [blogpost by Chance Arthur](https://chancearthur.com/notes/photography-and-kirby-cms), Kirby does not keep uploaded files private and original file sizes, together with sensitive information like EXIF, always are freely accessible.

Is Chance Arthurs [plugin](https://github.com/chancearthur/kirby-exifandresize) the proper way to solve this issue or are there even better alternatives? Is the security aspect possibly important enough that perhaps a Kirby core functionality should be implemented?

Thanks!

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [May 16, 2022, 4:00pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/2 "2022-05-16T16:00:36Z")

</div>

I think the plugins approach is valid: writing 2 hooks that automatically treat your files when they’re uploaded. That is opinionated enough to not be in the core though (you wanna resize too? If yes how much? etc).

For a feature request I’d rather see the ability to extend the [FileRules](https://github.com/getkirby/kirby/blob/main/src/Cms/FileRules.php#L244). Not all files are automatically published, a way to add filters to the already present ones could be helpful.

Something like (this is a proposal, doesn’t work):

```php
Kirby::plugin('rasteiner/privatefiles', [
    'validFile' => function($file) {
        //publish file only if its not a large image
        return !$file->isResizable() || max($file->width(), $file->height()) < 500;
    }
]);

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 16, 2022, 6:23pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/3 "2022-05-16T18:23:39Z")

</div>

Provided that the content folder is not accessible (like it should be) and unless I’m missing something, this should also be achievable via a `file::url()` component in combination with a route instead of the hooks. Which would also preserve the original files in the content folder in case the files with this information are needed for any purpose (only make files with exif data accessible to buyers, clients etc):

```auto
<?php

use Kirby\Cms\App;

App::plugin('texnixe/file-resizer', [

    'components' => [
        'file::url' => function ($kirby, $file) {
            if ($file->type() === 'image') {
              return $kirby->url() . '/' . $file->parent()->id() . '/' . $file->filename();
            }
            return $file->mediaUrl();
          },

    ],
    'routes' => [
        [
            'pattern' => '(:all)/(:any)',
            'action' => function($page, $file) {
                if (($page = page($page)) && $file = $page->file($file)) {
                    return $file->resize(1800)->read();
                }
            }
        ]
    ]

]);

```

---

<div class="post-metadata">

**Author:** ![sebastiangreger](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sebastiangreger/32/16176_2.png) [@sebastiangreger](https://forum.getkirby.com/u/sebastiangreger)\
**Post date:** [May 17, 2022, 4:24am UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/4 "2022-05-17T04:24:06Z")

</div>

Hmm… I just tried that `file::url` component and while this indeed works for `page($pageid)->file($filename)->url()`, a call for a thumb URL like `page($pageid)->file($filename)->thumb(['width' => 800])->url()` still returns the URL to the media folder. And once I have the media URL to a thumb, I can strip the `-800x` part and Kirby automatically makes the original file available in the media folder 🤔

I’d somehow wish there were a way to prevent Kirby from generating a copy of the original file in the media folder, while being able to continue using the thumbs engine etc. Is there a way to tap into that `validFile` method @rasteiner pointed at? Or any other place where I could use a plugin to tell Kirby “don’t create 1:1 copies of image files in the media folder” while all the other core functionalities for those files, such as the thumb engine, remain unchanged?

---

<div class="post-metadata">

**Author:** ![sebastiangreger](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sebastiangreger/32/16176_2.png) [@sebastiangreger](https://forum.getkirby.com/u/sebastiangreger)\
**Post date:** [May 17, 2022, 12:48pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/5 "2022-05-17T12:48:54Z")

</div>

This brain teaser of “how to keep certain files out of the media folder” kept hovering in my head. I did a bit of digging in the core. To test, I modified the [`FileActions::publish()` method](https://github.com/getkirby/kirby/blob/3.6.6/src/Cms/FileActions.php#L265) (other possibilities would be `Media::publish` or `FileRules::validFile()`, but I’m unsure whether these are also relevant in other flows; `FileActions::publish()` seems most specific for the task at hand?):

```php
public function publish()
{
    // experimental addition starts
    if($this->type() == 'image' && $this->mime() == 'image/jpeg') {
        go('error');
    }
    // experimental addition ends
    Media::publish($this, $this->mediaRoot());
    return $this;
}

```

Thumbs still work, but the original file for JPGs of type `image` are no longer copied into the media folder. Instead of redirecting to the error page (I couldn’t figure out how to throw a real 404 at this point), one could probably call a custom `publish` method here – e.g. to create a EXIF-free version, if desired.

Would this be possible to be turned into a plugin by [replacing the core method](https://getkirby.com/docs/cookbook/extensions/replacing-core-classes)? But the maybe more important question is: what other functionalities would this break? (Disclaimer: This is really just some explorative hacking; don’t use in production…)

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [May 17, 2022, 1:01pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/6 "2022-05-17T13:01:01Z")

</div>

The team could think about allowing “file models”, so people could override the publish method.

Or currently we could think of returning a custom “Files” collection from certain page models. Like (pseudocode):

```php
class PrivateFile extends Kirby\Cms\File {
    public function publish() {
        throw new Exception('nope!');
    }
}

class PrivateFiles extends Kirby\Cms\Files {
    public function factory(array $data) {
        //build a collection of PrivateFile
    }
}

class GalleryStorePage extends Kirby\Cms\Page {
    public function files() {
        return PrivateFiles::factory($this->inventory(... $etc));
    }
}

```

* * *

> [@sebastiangreger](#):
>
> `FileActions::publish()` seems most specific for the task at hand?

My reasoning was that for this usecase we actually don’t want to be able to specify “what happens when we publish”, but more “what files should be publishable”.  
But “what happens when we publish” could also be very interesting for other use cases: like when I want to publish on a cdn, for example.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 17, 2022, 2:01pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/7 "2022-05-17T14:01:18Z")

</div>

> [@rasteiner](#):
>
> The team could think about allowing “file models”, so people could override the publish method.

That’s what’s definitely missing, you currently would’ve to go a long way for that, or would have to limit it to particular pages.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [May 18, 2022, 4:53pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/8 "2022-05-18T16:53:07Z")

</div>

why not create a thumb of the original on upload, striping all meta data with a custom thumbdriver but copy the sensitive data into the content file?

(edited: oh. thats what arthurs plugin seems to do)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 18, 2022, 4:56pm UTC](https://forum.getkirby.com/t/how-to-prevent-leakage-of-exif-information/25508/9 "2022-05-18T16:56:50Z")

</div>

That is exactly what the plugin mentioned in the first post does. But it would be great if there was some other way of preserving the original files in the content folder, i.e. prevent publishing of them.
