Error 404 not found for protected files (images)

Created on 26 August 2024, 8 months ago

Problem

The server returns a 404 error for files (images) managed by protected downloads, even if images are correctly uploaded in the protected directory: see the attached animation.

My settings:

Protected directory location:

MyProject
-- config
-- protected-files  <- Here
-- web
---- core
---- modules
---- [and so on with default Drupal dirs]




Protected directory path setting:

$settings['protected_download_file_path_protected'] = $app_root . '/../protected-files';




Default download method:




Caching




Upload Destination (field_images)



NGINX errors:

NGINX error when uploading the image:

nginx_1      | 2024/08/26 09:40:06 [error] 48#48: *209 open() "/var/www/html/web/protected-download/protected/66d10b80/9NmU8NGnltNWQaoucK7BMgJKlVah_Zz0vUXBQwRUOqE/styles/thumbnail/protected/2024-08/MY-IMAGE.jpg.webp" failed (2: No such file or directory), client: 192.168.144.6, server: default, request: "GET /protected-download/protected/66d10b80/9NmU8NGnltNWQaoucK7BMgJKlVah_Zz0vUXBQwRUOqE/styles/thumbnail/protected/2024-08/MY-IMAGE.jpg.webp?itok=KCsTCxxj HTTP/1.1", host: "dev.itabots.com", referrer: "http://dev.itabots.com/node/2/edit"




NGINX error when viewing the node:

nginx_1      | 2024/08/26 09:40:13 [error] 48#48: *209 open() "/var/www/html/web/protected-download/protected/66d10b80/f2BsT2bKtj8K7qyEZyrLvDt79mImN3rKL4IWy825-yA/2024-08/MY-IMAGE.jpg" failed (2: No such file or directory), client: 192.168.144.6, server: default, request: "GET /protected-download/protected/66d10b80/f2BsT2bKtj8K7qyEZyrLvDt79mImN3rKL4IWy825-yA/2024-08/MY-IMAGE.jpg HTTP/1.1", host: "dev.itabots.com", referrer: "http://dev.itabots.com/node/2"




Any suggestion to fix the problem is appreciated, thank you.

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy mxt Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mxt
  • 🇮🇹Italy mxt Milan

    Just to do a test, I tried to setup the default Drupal $settings['file_private_path'] stuff with a path similar to the one setted for $settings['protected_download_file_path_protected'] (so both dirs are at the same level), and this works fine: image styles are correctly created, and images are visible in the node.

    So it seems that there is something wrong with paths or the custom stream wrapper implemented by this module.

  • 🇮🇹Italy mxt Milan

    I also tried to set these default drupal settings just to see if this can help:

    $settings['file_additional_public_schemes'] = ['protected'];
    $settings['file_sa_core_2023_005_schemes'] = ['protected'];
    

    But the problem is still there...

  • First commit to issue fork.
  • 🇺🇦Ukraine zviryatko

    So the issue is related to core change - https://www.drupal.org/node/3346038 → , provided a fix, need testing.

  • 🇨🇭Switzerland znerol

    Thanks for the hint. I'm going to add a test case to the MR which should adequately cover the issue.

  • 🇨🇭Switzerland znerol
  • 🇨🇭Switzerland znerol

    Also found 📌 Pass the session when forwarding to image style controller Active while reviewing the image style forwarding code.

  • Pipeline finished with Skipped
    4 months ago
    #353120
  • 🇨🇭Switzerland znerol

    I manually verified the cause and the fix. I'm confident that the MR is correct. Thanks @mxt for the detailed report and @zviryatko for the Fix. Also sorry I did not react earlier. I honestly had no idea what could cause this.

  • 🇺🇦Ukraine zviryatko

    > I honestly had no idea what could cause this.

    It was the core change - https://www.drupal.org/node/3346038 → , preview simply returns 503 error with some stack trace.

    Proxying image previews with sub-request is very tricky, I've been working on https://www.drupal.org/project/cdn/issues/3179753 ✨ Improve far-future support: generate dynamically generated files automatically (f.e. image style derivatives) Needs work some time ago, and it has more problems than I expected. Btw, using cdn + cdn_cloudfront_private was an alternative in my case when existing website had many public file fields and it was just too complex to move them to private and use drupal for giving the file response, instead I kept all files public but protected it to be accessible only by cloudfront, no one else can't, and CF signed cookie did the trick. But that's aws only solution.

  • 🇨🇭Switzerland znerol

    It was the core change

    Exactly. Once you pointed that out to me it was clear, but I had difficulties to understand the problem before that point in time.

    An automated test would have caught that early on. Now there is one, so I'm confident that similar issues with image styles will

    Rolled a release and shipped the fix in 2.1.1 → .

  • 🇮🇹Italy mxt Milan

    I'm very sorry to reopen this: I tried 2.1.1 but the issue is still there.

    I'll rewrite here the nginx error, because it is the only feedback I have.

    NGINX error when uploading the image:

    nginx_1    | 2024/11/28 20:42:10
    
    [error] 46#46: *39 open() "/var/www/html/web/protected-download/protected/67523e80/jwOPk2rK5-8oX0zpl7vDAwOiZ8_6eHEILcpfFFH7RHo/styles/thumbnail/protected/2024-11/myImage.png.webp" failed (2: No such file or directory),
    
    request: "GET /protected-download/protected/67523e80/jwOPk2rK5-8oX0zpl7vDAwOiZ8_6eHEILcpfFFH7RHo/styles/thumbnail/protected/2024-11/myImage.png.webp?itok=DAd52Bxn HTTP/1.1",
    

    So it seems that nginx cannot find the file...

  • 🇨🇭Switzerland znerol

    Nginx shouldn't try to open this file. It should pass the request to Drupal.

  • 🇨🇭Switzerland znerol
Production build 0.71.5 2024