# Static File Hack Updated For Members

**URL:** <https://forum.ghost.org/t/static-file-hack-updated-for-members/10265>\
**Category:** Memberships & subscriptions\
**Created:** [November 15, 2019, 1:08am UTC](https://forum.ghost.org/t/static-file-hack-updated-for-members/10265 "2019-11-15T01:08:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![redstern](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/redstern/32/3295_2.png) [@redstern](https://forum.ghost.org/u/redstern)\
**Post date:** [November 15, 2019, 1:08am UTC](https://forum.ghost.org/t/static-file-hack-updated-for-members/10265/1 "2019-11-15T01:08:58Z")

</div>

In [2018](https://drakeor.com/2018/09/11/serving-static-files-within-ghost/) and [2015](https://fayimora.com/hosting-static-files-with-ghost/) there were articles published for how to serve static files. I wanted to do the same, for my free (and hopefully one day soon paid) members.

For self-ghosters, Nginx can read the ghost cookies to serve files if a member is logged in. However, the cookie name contains dashes. There’s a little trick to map it to a variable Nginx can read.

1. In your conf file: nano /etc/nginx/sites-enabled/ghost add the following **above** the server { }

map $http\_cookie $ghostly\_cookie {  
default 0;  
“~ghost-members-ssr.sig=(?[^;]+)” $mc;  
}  
2. Create your folder under /var/www/ghost/[your folder name]

1. Under the other location entry add:  
location /media/ {  
if ($ghostly\_cookie = 0) {return 401;}  
alias /var/www/ghost/[your folder name]/;  
}

Here are the [blog](https://www.ur-ban.com/2012/03/18/logging-nginx-cookies-with-dashes/) and [stack overflow](https://stackoverflow.com/questions/26128412/how-to-extract-some-value-from-cookie-in-nginx) sources for reading cookies with special characters:

Now, I’m working on creating a custom error message for 401 (unauthorized).

---

<div class="post-metadata">

**Author:** ![egg](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/egg/32/1691_2.png) [@egg](https://forum.ghost.org/u/egg)\
**Post date:** [November 15, 2019, 2:53am UTC](https://forum.ghost.org/t/static-file-hack-updated-for-members/10265/2 "2019-11-15T02:53:06Z")

</div>

Bare in mind that this does not check if the cookie is valid, just that it exists - so it would be trivial to get around this by setting cookies with arbitrary content so long as it has the correct name!

---

<div class="post-metadata">

**Author:** ![redstern](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/redstern/32/3295_2.png) [@redstern](https://forum.ghost.org/u/redstern)\
**Post date:** [November 15, 2019, 3:41am UTC](https://forum.ghost.org/t/static-file-hack-updated-for-members/10265/3 "2019-11-15T03:41:18Z")

</div>

Indeed!

To be clear this was not meant to model a secure system.

The ghost cookies are passed to nginx automatically, so I was curious to see if I could track them. It was a fun little project.

If anyone has any ideas on how to expand this into a secure system, that would really cool. I’d be happy to test it out.

---

<div class="post-metadata">

**Author:** ![redstern](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/redstern/32/3295_2.png) [@redstern](https://forum.ghost.org/u/redstern)\
**Post date:** [November 15, 2019, 6:53pm UTC](https://forum.ghost.org/t/static-file-hack-updated-for-members/10265/4 "2019-11-15T18:53:25Z")

</div>

If a non-member tries to download, then they will receive the nginx error page. Haven’t figured out how to route it back through ghost.
