V8-archive: Unauthenticated users can access the files uploaded on Directus

Created on 8 Nov 2020  Â·  3Comments  Â·  Source: directus/v8-archive

• Version of Directus: 8.8.1
• AWS EC2 Amazon Linux 2 - MariaDB 10.4.13
• Steps to Reproduce:

Clean Installation of Directus 8

Login as Admin and upload a file

Make sure Public role has no permission on any custom or system collection

Open a different browser in which the user is unauthenticated and paste the URL to access the file https://{{directus}}/{{project}}/assets/{{filename}}

The file can be viewed/downloaded

The ideal solution for me would be to have a private S3 bucket as storage, not publicly accessible.
Directus should check the user permission when requesting an assets/{{filename}}. Maybe the token should be sent as query parameter?

app

Most helpful comment

@luglia that's why

Directus should check the user permission when requesting an assets/{{filename}}.

is a good idea. It allows users that want to have it public to give access to the public role, while allowing others to more finely specify what is accessible and what's not

All 3 comments

Images are 99% assets and should be accessible to anyone in my opinion.

@luglia that's why

Directus should check the user permission when requesting an assets/{{filename}}.

is a good idea. It allows users that want to have it public to give access to the public role, while allowing others to more finely specify what is accessible and what's not

If there is anyone searching for a quick solution:

Simply add the auth middleware to the assets route in src/web.php

//$app->get('/{project}/assets/{id}', \Directus\Api\Routes\Assets::class);

$app->group('/{project}', function () use ($middleware) {
    $this->get('/assets/{id}', \Directus\Api\Routes\Assets::class)
        ->add($middleware['auth_user'])
        ->add($middleware['auth'])
        ->add($middleware['table_gateway']);

...

After that the assets url is no longer available with public access.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nitwel picture Nitwel  Â·  3Comments

ondronix picture ondronix  Â·  3Comments

rijkvanzanten picture rijkvanzanten  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments

benhaynes picture benhaynes  Â·  4Comments