Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prePackagedDownloadPath and EEGChunksPath config #9523

Draft
wants to merge 3 commits into
base: 26.0-release
Choose a base branch
from

Conversation

laemtl
Copy link
Contributor

@laemtl laemtl commented Jan 7, 2025

Add prePackagedDownloadPath and EEGChunksPath configs to LORIS.
Those options are available in LORIS-MRI since v24 and we omitted to add it into LORIS.

@laemtl laemtl changed the base branch from main to 26.0-release January 7, 2025 17:12
@laemtl laemtl force-pushed the prePackagedDownloadPath-config branch from 4c571ff to 915513b Compare January 7, 2025 17:15
@jeffersoncasimir
Copy link
Contributor

Both files tested; error-free.

@laemtl laemtl marked this pull request as draft January 7, 2025 19:45
Copy link
Contributor

@jeffersoncasimir jeffersoncasimir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pipelinearchive endpoint should instead be (auto-)handled in a new file, called pipelinearchive.class.inc

I personally would not extend Endpoint in the PipelineArchive class

I also think there should be a default value in the Config table for prePackagedDownloadPath

@laemtl
Copy link
Contributor Author

laemtl commented Jan 8, 2025

I think the pipelinearchive endpoint should instead be (auto-)handled in a new file, called pipelinearchive.php
I personally would not extend Endpoint in the PipelineArchive class

@jeffersoncasimir I think you are right about that, unless we want an endpoint to download archive files. @driusan @cmadjar thoughts?

I also think there should be a default value in the Config table for prePackagedDownloadPath

We can do that if we want the BIDS archives to be always outside the assembly_bids folder. @cmadjar thoughts?

@cmadjar PipelineArchive is an attempt to replace the htdocs/mri/jiv/get_file.php logic for imaging archives. It is only used in the EEG ecosystem for now, is there a scenario it would be useful for imaging as well?

@laemtl laemtl changed the title prePackagedDownloadPath config prePackagedDownloadPath and EEGChunksPath config Jan 8, 2025
@driusan
Copy link
Collaborator

driusan commented Jan 9, 2025

Since this has SQL changes please rebase to the main branch

use \LORIS\Http\Endpoint;

/**
* This class handles pipeline archives downlaod. It should
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class appears to be specific to the EEG browser and should go in the appropriate module. If it's intended to be a generic way to download files, I don't think the name "PipelineArchive" is appropriate.

Copy link
Contributor Author

@laemtl laemtl Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is specific to EEG and MRI BIDS and maybe MRI TARCHIVES, so I don't think having it inside the EEG Browser is ideal. What would be the appropriate location? Maybe changing the name for ImagingArchive will make it clearer?
Its aims is to replace the logic in htdocs/mri/jiv

*
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
*/
class PipelineArchive extends Endpoint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an endpoint design, the FilesPassthruHandler (ie. as used by the media module) https://github.com/aces/Loris/blob/main/modules/media/php/files.class.inc) seems to be much simpler and uses existing infrastructure such as the FilesDownloadHandler (which does validation to address the security issues mentioned in this PR and has more generic support for any mime type.)

}

$data_path = \NDB_Config::singleton()->getSetting('dataDirBasepath');
$fullpath = $data_path . "/" . $request->getQueryParams()["filename"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vulnerable to a path traversal attack. Anyone who has access to this endpoint can download anything on the filesystem by crafting a filename like "../../../../etc/passwd"


if (!file_exists($fullpath)) {
$package_path = \NDB_Config::singleton()->getSetting('prePackagedDownloadPath');
$fullpath = $package_path . "/" . $pipeline . ($version ? "/" . $version : "") . "/" . $request->getQueryParams()["filename"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also uses direct string concatenation of user input and allows an attacker to traverse to an arbitrary file on the file system by either manipulatig the filename, pipeline, or version sent in the request.

$fullpath = $data_path . "/" . $request->getQueryParams()["filename"];

if (!file_exists($fullpath)) {
$package_path = \NDB_Config::singleton()->getSetting('prePackagedDownloadPath');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not set, "$fullpath" will be relative to "/" because of the string concatenation below.

$ext = $path_parts['extension'];
switch ($ext) {
case 'zip':
$mime = "application/x-zip";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this mime type is correct. zip (without x-) is a standardized mime type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants