Skip to content

Prevent .part upload via dav#29011

Merged
PVince81 merged 2 commits intomasterfrom
prevent_dav_partfile_upload
Oct 13, 2017
Merged

Prevent .part upload via dav#29011
PVince81 merged 2 commits intomasterfrom
prevent_dav_partfile_upload

Conversation

@IljaN
Copy link
Contributor

@IljaN IljaN commented Sep 14, 2017

Description

Prevent creating, moving, copying to paths with extension .part

Related Issue

#7496

How Has This Been Tested?

Manually, Integration-Tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@IljaN IljaN changed the title Prevent .part upload via dav #7496 Prevent .part upload via dav Sep 14, 2017
@IljaN IljaN requested a review from PVince81 September 14, 2017 12:25
@mmattel
Copy link
Contributor

mmattel commented Sep 14, 2017

@IljaN
one question, what would happen if somone creates a folder called .part ?

@IljaN
Copy link
Contributor Author

IljaN commented Sep 14, 2017

@mmattel Good catch! It is not possible via webdav: mkcol .part Fails with 405 Method not allowed, not sure if it is the correct code tough.

If you create the directory directly in your storage with mkdir .part it is ignored by owncloud since we don`t support dotfiles afaik

@PVince81
Copy link
Contributor

@IljaN we should also block "$name.part" folders. Ignoring is not good. If you had the impression that OC ignores it, did you check the FS ? Maybe it created the folder still but it wasn't visible in the UI ?

Better block those as well.

@mmattel
Copy link
Contributor

mmattel commented Sep 14, 2017

@IljaN maybe you could use from #19235
lib/private/Files/Filesystem.php function isForbiddenFileOrDir and add .part into the query array

@IljaN
Copy link
Contributor Author

IljaN commented Sep 15, 2017

@PVince81 .part directory creation is already prevented by this change:

dav:/remote.php/dav/files/admin/> mkcol path.with.ext.part
Creating `path.with.ext.part': failed:
400 Bad Request

@mmattel I extended verfiyPath method with a extension check, this seems to catch all cases with the benefit that it is used in all codepaths (Single point of truth), what benefits does extending isForbiddenFileOr dir give us?

@PVince81
Copy link
Contributor

@IljaN prove it with an integration test 😉

Is 400 bad request the correct code, same as for files ? Just asking, I thought we returned 403 for those but don't remember exactly.

@mmattel
Copy link
Contributor

mmattel commented Sep 15, 2017

@IljaN nothing special, just remembered that we excluded stuff some time ago and thought it is maybe usable for your PR, never mind

@PVince81
Copy link
Contributor

rebase conflicts

@IljaN
Copy link
Contributor Author

IljaN commented Sep 18, 2017

@PVince81 let me fix them, I am also in the process adding a missing test

@IljaN IljaN force-pushed the prevent_dav_partfile_upload branch 2 times, most recently from f971a38 to dc8004a Compare September 18, 2017 14:11
@IljaN
Copy link
Contributor Author

IljaN commented Sep 19, 2017

@PVince81 Ready

}


if (pathinfo($fileName, PATHINFO_EXTENSION) == 'part') {
Copy link
Contributor

Choose a reason for hiding this comment

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

@IljaN IljaN force-pushed the prevent_dav_partfile_upload branch from 1d4f821 to e97ac64 Compare September 20, 2017 16:02
@IljaN
Copy link
Contributor Author

IljaN commented Sep 20, 2017

Ready for next review round


if (preg_match('/' . FileInfo::BLACKLIST_FILES_REGEX . '/', $fileName) !== 0) {
throw new InvalidPathException(
'Can`t upload files with extension .part because this extension is used internally by owncloud.'
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldnt it be good to get the filename/component in question from the constant instead of hardcoding it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@IljaN see above comment

Also we cannot use the name "ownCloud" in error messages due to theming, please remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I understand I am getting it from FileInfo::BLACKLIST_FILES_REGEX

Copy link
Contributor

Choose a reason for hiding this comment

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

To be precise, it is not the query but the text.

Here you state hardcoded .part
But the regex says const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
One name is missing.
What happens when the regex is extended with more names?
Extract the names and print them to be futureproof.

@IljaN
Copy link
Contributor Author

IljaN commented Oct 11, 2017

Ready for next round of review

Copy link
Contributor

@PVince81 PVince81 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 to me, thanks a lot!

@PVince81 PVince81 merged commit 7feb07a into master Oct 13, 2017
@PVince81 PVince81 deleted the prevent_dav_partfile_upload branch October 13, 2017 08:45
@PVince81
Copy link
Contributor

@IljaN please backport to stable10

DeepDiver1975 pushed a commit that referenced this pull request Nov 3, 2017
DeepDiver1975 added a commit that referenced this pull request Nov 3, 2017
…d16643b1caf86bd16845

[stable10] Merge pull request #29011 from owncloud/prevent_dav_partfi…
@PVince81
Copy link
Contributor

PVince81 commented Nov 6, 2017

stable10: #29432

@lock
Copy link

lock bot commented Aug 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants