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

[mri_violations ]Bring back clickable images #2843

Merged
merged 1 commit into from
Jul 10, 2017

Conversation

gluneau
Copy link
Contributor

@gluneau gluneau commented May 26, 2017

Being able to review mri violations visually is essential to the review process.

@gluneau gluneau added this to the 17.1 milestone May 26, 2017
@gluneau gluneau added the Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) label May 29, 2017
@AnyhowStep
Copy link
Contributor

It looks as safe as the dicom processing code but, just to be safe, maybe escapeshellarg() will be good to use on both the $dimension and $minc_file before they are used in passthru() or exec():

http://php.net/manual/en/function.escapeshellarg.php

"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

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

compile using npm run compile make sure you npm folder is up-to-date

Copy link
Collaborator

@driusan driusan left a comment

Choose a reason for hiding this comment

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

missing a case

$query = "select MincFile from mri_violations_log where LogID = :LogID";
} elseif ($l == 3) {
$query = "select MincFile from MRICandidateErrors where ID = :LogID";
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be an else here which aborts with a bad request error in an unhandled case, otherwise if a user provides bad input with url hacking it's still going to get down to the passthru case, which will result in spawning a completely unnecessary process.

There won't be any user input making it to the shell, so it couldn't be used as a remote code exploit, but it could probably be used as part of a denial of service attack.

(Unrelatedly, stylistically I think this code would be a little cleaner with a switch statement than an if/elseif chain, and the SQL keywords should be capitalized.)

@driusan driusan added the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label May 31, 2017
@gluneau
Copy link
Contributor Author

gluneau commented May 31, 2017

@driusan @jstirling91 Please take a look and confirm your comments were addressed.

@gluneau gluneau removed the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label Jun 2, 2017
driusan
driusan previously requested changes Jun 2, 2017
$minc_file = $DB->pselectOne(
$query,
array(
'MincID' => escapeshellcmd($_REQUEST['minc_id']),
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 see what's gained by calling escapeshellcmd here. It's being passed to a prepared statement binding, not being passed to a shell.

$minc_file = $DB->pselectOne($query, array('MincID' => $_REQUEST['minc_id']));
$minc_file = getMincLocation() . $minc_file;
if (strpos(escapeshellcmd($_REQUEST['minc_id']), 'l') !== false) {
list($l, $id) = explode('l', escapeshellcmd($_REQUEST['minc_id']));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are these being shell escaped here? It's not being passed to a shell or used as a command. This should be done right before the passthru command, not everywhere that the minc_id is used.

If you really want to check if the user was trying to inject something and abort early, you could probably do something like if (escapeshellcmd(x) !== x) { print error and exit} (note: I haven't tried that, but it should work.)

There's also this warning from the escapeshellcmd documentation that should be taken into account:

Warning escapeshellcmd() should be used on the whole command string, and it still allows the attacker to pass arbitrary number of arguments. For escaping a single argument escapeshellarg() should be used instead. (http://php.net/manual/en/function.escapeshellcmd.php)

@driusan driusan dismissed stale reviews from jstirling91 and themself June 5, 2017 13:12

changes done

@driusan driusan requested a review from johnsaigle June 5, 2017 13:12
jstirling91
jstirling91 previously approved these changes Jun 5, 2017
Copy link
Contributor

@jstirling91 jstirling91 left a comment

Choose a reason for hiding this comment

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

Moving to needs testing

Copy link
Contributor

@johnsaigle johnsaigle left a comment

Choose a reason for hiding this comment

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

Looks good from a security perspective! Added a couple of refactoring notes.

$query = "select File from files where FileID = :MincID";
$minc_file = $DB->pselectOne($query, array('MincID' => $_REQUEST['minc_id']));
$minc_file = getMincLocation() . $minc_file;
if (strpos($_REQUEST['minc_id'], 'l') !== false) {
Copy link
Contributor

@johnsaigle johnsaigle Jun 5, 2017

Choose a reason for hiding this comment

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

I'm not sure that this will work as intended. If you look here, !== will always return true when compared with numeric values. I tried it on the command line with -1, 0, and 1 and this was the case.

As strpos always returns a number, this condition will always be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnsaigle, it's the small case letter "L" being checked here. So it's not a number. ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

But strpos still returns a number regardless of what you check, right? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the use of !== false is deliberate; strpos returns either the offset at which the needle string begins in the haystack string, or the boolean false if the needle isn't found. Since 0 is a valid offset and 0 is "falsey", we can't use simpler constructs like !strpos($a, 'are').

https://stackoverflow.com/questions/4366730/how-do-i-check-if-a-string-contains-a-specific-word-in-php

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I'm sorry about that. I thought strpos returned a -1 on failure, not false. Bizarre behaviour...

Copy link
Collaborator

Choose a reason for hiding this comment

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

The PHP standard functions are relatively consistent (relative to the rest of PHP) in returning false if a needle isn't found.


$header = $_REQUEST['minc_headers'];
$header_data = $_REQUEST['raw_data'];
if (strpos($minc_file, 'assembly') !== false) {
Copy link
Contributor

@johnsaigle johnsaigle Jun 5, 2017

Choose a reason for hiding this comment

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

See comment above. I believe this will always return true.
Resolved above.

if (strpos($minc_file, 'assembly') === 0) {
$minc_file = getMincLocation() . $minc_file;
} else {
$minc_file = $minc_file;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is tautological.

Maybe refactor this section like the following...

if (strpos($minc_file, 'assembly') === 0) {
    $minc_file = getMincLocation() . $minc_file;
} else if (strpos($minc_file, 'assemby') < 0) {
    $minc_file = getMincLocation() . "trashbin/" . $file;
}

...and remove line 48 also.

Copy link
Contributor

Choose a reason for hiding this comment

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

This refers to line 52.. sorry I think I messed up the formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this should be changed but I won't block the PR just for this. Going to approve changes. 👍

@jstirling91 jstirling91 dismissed their stale review June 5, 2017 16:03

based on johns feedback

@jstirling91
Copy link
Contributor

@gluneau @driusan is this still relevant with the the following pull request #2861

@gluneau
Copy link
Contributor Author

gluneau commented Jun 6, 2017

Once this #2861 gets merged, I'll rebase this one.

@jstirling91 jstirling91 added the Blocked PR awaiting the merge, resolution or rejection of an other Pull Request label Jun 7, 2017
@driusan
Copy link
Collaborator

driusan commented Jun 28, 2017

@gluneau @jstirling91 This is still tagged as "Blocked". The only reason I can see is the above comment, and the PR that it references looks like it's been merged.

Does this still need to be rebased and can the tag be removed?

@kongtiaowang kongtiaowang reopened this Jul 4, 2017
@gluneau gluneau removed the Blocked PR awaiting the merge, resolution or rejection of an other Pull Request label Jul 4, 2017
@MounaSafiHarab MounaSafiHarab added the Passed Manual Tests PR has undergone proper testing by at least one peer label Jul 5, 2017
@MounaSafiHarab
Copy link
Contributor

MounaSafiHarab commented Jul 5, 2017

@gluneau

works well!
I get multiple PHP Warnings though (one example shown below, but I get many more for every violated scan), so up to the senior developer to decide if changes are needed or the pull request is good to go!

[Wed Jul 05 14:30:49.660829 2017] [:error] [pid 29712] [client 132.216.56.241:49758] PHP Warning: substr() expects parameter 1 to be string, array given in /var/www/loris/modules/brainbrowser/ajax/getMincName.php on line 23, referer: http://mouna-dev.loris.ca/brainbrowser/?minc_id=1l50

@driusan driusan merged commit cf8d4c6 into aces:17.1-dev Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) Passed Manual Tests PR has undergone proper testing by at least one peer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants