# Add security or remove public access to files

**URL:** <https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569>\
**Category:** Parse Server 📡\
**Created:** [July 22, 2020, 11:50am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569 "2020-07-22T11:50:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fzidar](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@fzidar](https://community.parseplatform.org/u/fzidar)\
**Post date:** [July 22, 2020, 11:50am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/1 "2020-07-22T11:50:00Z")

</div>

Is it possible to remove the public access to the URL (https:///files//) that gets automatically created when I save a file to Parse? I would like to secure the access to these files but can’t quite determine how to go about this.

Thanks,  
Frank

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 22, 2020, 4:59pm UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/2 "2020-07-22T16:59:36Z")

</div>

What is the file adapter that you are using? What is the rule you want to implement?

---

<div class="post-metadata">

**Author:** ![fzidar](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@fzidar](https://community.parseplatform.org/u/fzidar)\
**Post date:** [July 22, 2020, 5:14pm UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/3 "2020-07-22T17:14:05Z")

</div>

I’m using the default GridStoreAdapter so a couple of collections are automatically generated for the storage in my MongoDB (fs.files and fs.chunks).

I’m just trying to prevent someone from potentially guessing the file URL and accessing it via a web browser. The URL of [https://myserver.com/files/myappname/....myfile.txt](https://myserver.com/files/myappname/....myfile.txt) is just wide open for viewing and if the data happens to need to be secured this option won’t work.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [July 22, 2020, 5:20pm UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/4 "2020-07-22T17:20:59Z")

</div>

Since there is a random component in the file name, it is really hard for someone to guess the file name. There is no built-in solution to add protection layer to these files. How would you want to differentiate the user that has access to the one that does not have? You can try to write an Express.js middleware in order to add some custom logic. One idea could be the generation of temp links.

---

<div class="post-metadata">

**Author:** ![fzidar](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@fzidar](https://community.parseplatform.org/u/fzidar)\
**Post date:** [July 22, 2020, 5:58pm UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/5 "2020-07-22T17:58:36Z")

</div>

Thanks. That makes sense and I figured that would be the case. I’ll try a different approach or add the middleware option.

---

<div class="post-metadata">

**Author:** ![dblythy](https://community.parseplatform.org/user_avatar/community.parseplatform.org/dblythy/32/231_2.png) [@dblythy](https://community.parseplatform.org/u/dblythy)\
**Post date:** [October 25, 2020, 11:03am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/6 "2020-10-25T11:03:54Z")

</div>

How would you feel about a secureFileOption in parse server config, which enforces X-Parse-Session-Token to match with a \_File object saved in the DB with ACLs?

For this option, there would have to be a .getData() function for the SDKs (as you’ve mentioned, accessing the URL wouldn’t work as headers wouldn’t get passed through), which returns a base64 string from the server to be rendered as an image / file.

The .getData function would only return fileData if session, ACL, CLP, etc are validated.

Or, maybe even a temporary token passed to the url, that expires 5 min after each time the Parse.File is requested.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [October 26, 2020, 4:03am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/7 "2020-10-26T04:03:40Z")

</div>

I have discussed some ideas with @cbaker6 on how to improve the files security. Basically we have two different ideas:

1. generate temporary links for certain files
2. verify session token in the getData function for certain files (it would not work for s3 adapter when directAccess is set to true)

---

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [October 26, 2020, 6:55am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/8 "2020-10-26T06:55:44Z")

</div>

I personally prefer serving files directly from S3 bucket. Implementing session token for files will require files to be proxied by parse server which is an extra load-headache for server.

I personally try to keep file url secure first. If user is able to get file url then let them see.

Also if you plan to proxy all files through parse server, then maybe a file trigger would be great. Like beforeGetFile, afterGetFile … just an example

---

<div class="post-metadata">

**Author:** ![lsmilek1](https://community.parseplatform.org/user_avatar/community.parseplatform.org/lsmilek1/32/629_2.png) [@lsmilek1](https://community.parseplatform.org/u/lsmilek1)\
**Post date:** [May 12, 2021, 7:28am UTC](https://community.parseplatform.org/t/add-security-or-remove-public-access-to-files/569/9 "2021-05-12T07:28:46Z")

</div>

What do you think about encrypting the image under the link with the parent objectID as key (user profile id for example)? The encryption would happen on the client side before uploading…

That way even if someone would guess the direct URL, he would access the encrypted image and she would see nothing. Only the real user accessing it through app would know to what user/object ID it belongs and therefore would know encryption key. The encryption itself does not need to be extremely secure and costly (depending on your needs)…
