public function get_file(Request $request)
{
// if the user doesn't have permission, do something.... ??
return response('')
->header('X-Accel-Redirect', $pathToFile);
}
Preventing access to URLs from GET requests sent by img tags
Hello, I am not sure if this is the job for the backend(Laravel) or the server(nginx) in my case:
I have a JavaScript code that appends images with src URL to a Controller method that sends nginx X-Accel headers (to access protected internal folders):
<img src="get_file?path=/protected_folder/image.jpg">
Now when the page loads, all the images send GET requests to the get_file URL which in turn goes to the Controller method that sends the X-Accel header back:
public function get_file(Request $request)
{
return response('')
->header('X-Accel-Redirect', $pathToFile);
}
What's working is that now users can't access to the protected folder via the URL at http://example.com/protected_folder/image.jpg but they can simply copy the URL with the get_file method in the URL and it returns the image:
http://example.com/get_file?path=/protected_folder/image.jpg
And if I copy paste this one, it does show the image.
Is there a way to add some sort of validation via Laravel so I will get some token to the get_file method and will only return the image if this token exists (Which will be only from the page that loads the images). Or, that's a job for nginx as well?
Please or to participate in this conversation.