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

Deprecate attachment upload by file path #302

Merged
merged 8 commits into from
Jan 4, 2022
Merged

Conversation

Art4
Copy link
Collaborator

@Art4 Art4 commented Jan 2, 2022

Uploading an attachment could be made by $client->getApi('attachment')->upload('file content'); as documented in the docs: https://github.com/kbsali/php-redmine-api/blob/v2.0.1/docs/usage.md

However in #222 a new way of uploading files via filepath was introduced as a "fix". This way has led to a number of problems like #235 and #264.

This method can additionally lead to a potential security problem: Assume someone wants to upload the file file.txt, but the file contains the path to another file:

file.txt

/etc/passwd

If one now runs $client->getApi('attachment')->upload(file_get_contents('./file.txt')); the library will check with is_file() for the existence of the /etc/passwd file and will upload this file instead.

As a solution I would recommend to deprecate the attachment upload by filename and remove it in the next major version.

This PR will fix #264.

@kbsali Depending on how critical this issue is rated, I would also release version 3.0 very soon.

@Art4 Art4 requested a review from kbsali January 2, 2022 22:38
@Art4 Art4 changed the title Deprecated attachment upload by file path Deprecate attachment upload by file path Jan 2, 2022
Copy link
Owner

@kbsali kbsali left a comment

Choose a reason for hiding this comment

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

nice one! 👌

src/Redmine/Client/ClientApiTrait.php Outdated Show resolved Hide resolved
return (false !== strpos($path, '/uploads.json')) or (false !== strpos($path, '/uploads.xml'));
}

private function isUploadCallAndFilepath(string $path, string $body): bool
Copy link
Owner

Choose a reason for hiding this comment

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

The name of the method is not very clear to me. What do you mean with "AndFilePath"?

Copy link
Collaborator Author

@Art4 Art4 Jan 4, 2022

Choose a reason for hiding this comment

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

The method checks if $path is an upload call and if $body contains a valid file path using is_file(), but was previously named isUploadCall() which does not fully describe the function. I extracted the upload check into its own method (named isUploadCall()) and now I needed a name that better described the meaning of the previous method. That is the reason why I came up with isUploadCallAndFilepath().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we should remove the isUploadCall() from this method and rename isUploadCallAndFilepath() to isFilepath()?

Copy link
Owner

@kbsali kbsali Jan 4, 2022

Choose a reason for hiding this comment

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

isValidFilePath ?
isAuthorizedFilePath ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove the call of isUploadCall() and rename it to isValidFilePath().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

src/Redmine/Client/NativeCurlClient.php Outdated Show resolved Hide resolved
src/Redmine/Client/Psr18Client.php Outdated Show resolved Hide resolved
Art4 and others added 3 commits January 4, 2022 12:47
Co-authored-by: Kevin Saliou <kevin@saliou.name>
Co-authored-by: Kevin Saliou <kevin@saliou.name>
Co-authored-by: Kevin Saliou <kevin@saliou.name>
@kbsali
Copy link
Owner

kbsali commented Jan 4, 2022

@kbsali Depending on how critical this issue is rated, I would also release version 3.0 very soon.

oh? why not a minor version update?

@Art4
Copy link
Collaborator Author

Art4 commented Jan 4, 2022

oh? why not a minor version update?

Removing this functionality is a breaking change and requires a major version.

Copy link
Owner

@kbsali kbsali left a comment

Choose a reason for hiding this comment

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

👍

@Art4 Art4 merged commit 3f1395c into kbsali:v2.x Jan 4, 2022
@Art4 Art4 deleted the improve-file-upload branch January 4, 2022 13:00
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.

Uploads: is_file(): File name is longer than the maximum allowed path length on this platform (4096)
2 participants