diff --git a/changes/changelog.d/public-media.bugfix b/changes/changelog.d/public-media.bugfix new file mode 100644 index 000000000..4fa615c24 --- /dev/null +++ b/changes/changelog.d/public-media.bugfix @@ -0,0 +1 @@ +Fixes an issue which made it possible to download all media files without access control (#2101) diff --git a/deploy/nginx.template b/deploy/nginx.template index 4f4d8e379..214bc2ca4 100644 --- a/deploy/nginx.template +++ b/deploy/nginx.template @@ -120,8 +120,15 @@ server { proxy_pass http://funkwhale-api; } - location /media/ { - alias ${MEDIA_ROOT}/; + # Allow direct access to only specific subdirectories in /media + location /media/__sized__/ { + alias ${MEDIA_ROOT}/__sized__/; + add_header Access-Control-Allow-Origin '*'; + } + + # Allow direct access to only specific subdirectories in /media + location /media/attachments/ { + alias ${MEDIA_ROOT}/attachments/; add_header Access-Control-Allow-Origin '*'; } diff --git a/docker/nginx/conf.dev b/docker/nginx/conf.dev index 0a931289b..7ddd3396a 100644 --- a/docker/nginx/conf.dev +++ b/docker/nginx/conf.dev @@ -112,8 +112,15 @@ http { proxy_pass http://funkwhale-api; } - location /media/ { - alias /protected/media/; + # Allow direct access to only specific subdirectories in /media + location /media/__sized__/ { + alias /protected/media/__sized__/; + add_header Access-Control-Allow-Origin '*'; + } + + # Allow direct access to only specific subdirectories in /media + location /media/attachments/ { + alias /protected/media/attachments/; add_header Access-Control-Allow-Origin '*'; } diff --git a/front/docker/funkwhale.conf.template b/front/docker/funkwhale.conf.template index de876ce2c..08e25c8be 100644 --- a/front/docker/funkwhale.conf.template +++ b/front/docker/funkwhale.conf.template @@ -85,8 +85,15 @@ server { proxy_pass http://funkwhale-api; } - location /media/ { - alias ${MEDIA_ROOT}/; + # Allow direct access to only specific subdirectories in /media + location /media/__sized__/ { + alias ${MEDIA_ROOT}/__sized__/; + add_header Access-Control-Allow-Origin '*'; + } + + # Allow direct access to only specific subdirectories in /media + location /media/attachments/ { + alias ${MEDIA_ROOT}/attachments/; add_header Access-Control-Allow-Origin '*'; }