Fix file access control on batched export downloads - broken by recent commit #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The security fix b22a769 seems to always return access denied even when it should allow access.
The problem is that the $filepath passed to views_data_export_is_export_file() is an absolute system path and so the strpos check doesn't work.
Wrapping realpath() around file_directory_temp() seems to solve the issue, although I'm not sure if this is the right fix. For one thing it means that every call to hook_file_download() will need to compute the realpath of the temp dir just to compare it...
Is it even correct to pass absolute system paths to hook_file_download()? The record in the files table also contains the absolute path.
This all seems to originate here in views_data_export_plugin_display_export::outputfile_create()
$path = tempnam(realpath($dir), 'views_data');
tempnam() returns an absolute path and this ends up as the filepath on the file record and we're always dealing with an absolute path from then on..
So maybe it's better to fix it there?