Skip to content

Conversation

@pierre-p-s
Copy link
Contributor

@pierre-p-s pierre-p-s commented Mar 11, 2021

Brief summary of changes

Solves an issue when if using special characters (&, <, >, ") the file download fails and the name of the file appears incorrectly in the browse tab of the media module.
The script removes the special characters from the sql data table media as well as from the file system.

Testing instructions (if applicable)

  1. Before checking out this branch, on 23.0-release, upload a file with special characters &, <, >, " into media.
  2. Check that the file name appears incorrectly in the media table
  3. Check out this branch.
  4. Upload a different file with special characters &, <, >, " into media.
  5. Look for the file in the browse tab, check that the file name appears correctly
  6. Try downloading the file and opening it.
  7. run (need sudo to be able to change the name of the files under /data/media_uploads/): sudo php /var/www/loris/tools/single_use/Cleanup_Special_Chars_Media.php
  8. Check that the first file now appears correctly in the data table and that when downloading you are able to read the file correctly.

@pierre-p-s
Copy link
Contributor Author

The test suite seems to be failing when running make checkstatic however on my VM the command runs without errors.

@pierre-p-s pierre-p-s added the "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help label Mar 11, 2021
@pierre-p-s pierre-p-s added State: Blocked PR or issue awaiting an external event such as the merge or another PR to proceed and removed "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help labels Mar 15, 2021
@pierre-p-s
Copy link
Contributor Author

Blocked by #7390

@pierre-p-s
Copy link
Contributor Author

After discussion with Rida: Remove encoding when inserting into SQL table, line 186 of fileUpload use unsafe insert and fix issues in the database

@ridz1208 ridz1208 added the State: Needs work PR awaiting additional work by the author to proceed label Mar 18, 2021
@pierre-p-s
Copy link
Contributor Author

@ridz1208 Let me know if this is a better fix please.

checkDateTaken($dateTaken);

$fileName = preg_replace('/\s/', '_', $_FILES["file"]["name"]);
$fileName = str_replace("%22", "\"", $fileName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this mean you are accepting quotes in the name of the file ? also its a bit clearer if you use '"' in the second argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I wanted to include the double quotes because right now we can add a file with it in the name. However we need this check fo it to work. Otherwise I could also send an error through swal refusing the quotes, but in that case what else are we not allowing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

%22 is URI encoding, your $filename is never coming from the URI... I'm not clear on why its being "decoded" (and BTW decoding should be done with urldecode() https://www.php.net/manual/en/function.urldecode.php not manually like this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to urldecode but I cant find where the fileName is being encoded...

@pierre-p-s pierre-p-s removed State: Blocked PR or issue awaiting an external event such as the merge or another PR to proceed State: Needs work PR awaiting additional work by the author to proceed labels Mar 23, 2021
@pierre-p-s
Copy link
Contributor Author

This PR still needs a script to change the file names in the sql table as well as in /data/uploads

@pierre-p-s pierre-p-s added the State: Needs work PR awaiting additional work by the author to proceed label Mar 24, 2021
@pierre-p-s pierre-p-s removed the State: Needs work PR awaiting additional work by the author to proceed label Mar 31, 2021
Co-authored-by: Rida Abou-Haidar <ridz1208@users.noreply.github.com>
@pierre-p-s pierre-p-s requested a review from ridz1208 March 31, 2021 18:13
@pierre-p-s pierre-p-s requested a review from jesscall April 1, 2021 01:34
@jesscall jesscall added the Passed manual tests PR has been successfully tested by at least one peer label Apr 12, 2021
@jesscall
Copy link
Contributor

Looks good!

);

// update name in file system
shell_exec("mv " . escapeshellarg($media_path . $fileNameURLencoded) . " " . escapeshellarg($media_path . $fileName));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why isn't this just using rename?

https://www.php.net/manual/en/function.rename.php

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed it while reviewing the document_repository PR, but can you change it in that script too?

Copy link
Contributor Author

@pierre-p-s pierre-p-s Apr 16, 2021

Choose a reason for hiding this comment

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

I changed it to rename and I will create a new PR for the document repository script and link it here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed the doc repo script in this PR: #7428

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@driusan let me know if it needs more changes

driusan pushed a commit that referenced this pull request Apr 20, 2021
@driusan driusan merged commit e7e3650 into aces:23.0-release Apr 20, 2021
@ridz1208 ridz1208 added this to the 23.0.3 milestone Apr 20, 2021
@@ -0,0 +1,54 @@
<?php
Copy link
Collaborator

Choose a reason for hiding this comment

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

before SQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Passed manual tests PR has been successfully tested by at least one peer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants