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

fix: do not accept federated shares where the name is too long #40726

Merged
merged 1 commit into from Apr 4, 2023

Conversation

DeepDiver1975
Copy link
Member

Description

Federated shares with a too long name can result in in accessible shares on the receiving server

Related Issue

  • Fixes <issue_link>

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@update-docs
Copy link

update-docs bot commented Apr 4, 2023

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@DeepDiver1975 DeepDiver1975 marked this pull request as ready for review April 4, 2023 11:27
@ownclouders
Copy link
Contributor

ownclouders commented Apr 4, 2023

💥 Acceptance tests pipeline apiProxySmoke-8-8-mariadb10.2-php7.4 failed. The build has been cancelled.

https://drone.owncloud.com/owncloud/core/38203/174

@sonarcloud
Copy link

sonarcloud bot commented Apr 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@DeepDiver1975
Copy link
Member Author

@jvillafanez please review again - thx

@DeepDiver1975 DeepDiver1975 merged commit 1ea5605 into master Apr 4, 2023
3 checks passed
@delete-merged-branch delete-merged-branch bot deleted the fix/fed-sharing-path-too-long branch April 4, 2023 15:15
@phil-davis
Copy link
Contributor

@jnweiger @pako81 is this something that is wanted for 10.12.1 release?
If so, then you will need to cherry-pick it into release-10.12.1 branch.

@saw-jan
Copy link
Member

saw-jan commented Aug 16, 2023

I don't know how to confirm this.
Steps that I tried:

  1. server1, mount an external storage (SMB) - since creating long name file is not possible from server UI
  2. create a file with long name in the SMB share folder
    aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFo.txt
  3. server1, do a federate share of that file to another server (10.13.0) - admin@<latest-server-url>
  4. server2, accept the share - (accept works)
  5. server2, open the file - (content is there)

From desktop-client:
4. add server2 account to the desktop-client
5. accept the share form activity window
6. share is there

CC @DeepDiver1975 @jvillafanez

@jnweiger
Copy link
Contributor

Not exaclty sure, where the length limit is. drone CI uses a 290 char string to trigger this. Yours is shorter: 233 chars.

@pako81
Copy link
Contributor

pako81 commented Aug 16, 2023

The verifyPath method in View.php is used:

https://github.com/owncloud/core/blob/master/lib/private/Files/View.php#L1921

which is then calling:

https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Common.php#L505-L511

where a FileNameTooLongException exception is thrown if the path is longer than 255 chars.

@jesmrec
Copy link

jesmrec commented Aug 16, 2023

where a FileNameTooLongException exception is thrown if the path is longer than 255 chars.

but, clients (including web) do not allow such amount of characters in the filename. So, that exception is never thrown.

@jnweiger
Copy link
Contributor

The verifyPath method in View.php is used:
https://github.com/owncloud/core/blob/master/lib/private/Files/View.php#L1921>
which is then calling:
https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Common.php#L505-L511
where a FileNameTooLongException exception is thrown if the path is longer than 255 chars.

Ouch. This will explode, when versioning or trashcan add their suffixes to the filename.

./files_versions/Documents/LoremIpsum.txt.v1692195415
./files_trashbin/files/Diagramm.drawio.d1692184476

@pako81
Copy link
Contributor

pako81 commented Aug 16, 2023

Ouch. This will explode, when versioning or trashcan add their suffixes to the filename.
./files_versions/Documents/LoremIpsum.txt.v1692195415
./files_trashbin/files/Diagramm.drawio.d1692184476

not related to this specific issue but, yes, we need to check what happens with occ files:scan when scanning versions and trashbin paths longer than 255 chars.

@jnweiger
Copy link
Contributor

jnweiger commented Aug 16, 2023

The code path with these checks is not executed.
Patched apps/federatedfilesharing/lib/Controller/RequestHandlerController.php

        public function createShare() {
                \OCP\Util::writeLog('federatedfilesharing', 'JW was here createShare ', \OCP\Util::ERROR);
                throw new BadRequestException('JW was here. createShare');
                try {

...

       public function acceptShare($id) {
                \OCP\Util::writeLog('federatedfilesharing', 'JW was here acceptShare ', \OCP\Util::ERROR);
                throw new BadRequestException('JW was here. acceptShare');
                try {

...
  • Incoming federated shares can still be accepted. 😱

@DeepDiver1975
Copy link
Member Author

I don't know how to confirm this.

In a regular use case this will not happen because files on all servers have the correct file name length.

This is a safety net against wrong usage of the http request. Submit an http request using curl.

@saw-jan
Copy link
Member

saw-jan commented Aug 29, 2023

Tried to re-check:

  1. Created file aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBr.txt (80 chars)
  2. Edited here to have only 55
    public function verifyPath($path, $fileName) {
    if (isset($fileName[255])) {
    throw new FileNameTooLongException();
    }
    $this->verifyPosixPath($fileName);
    }
  3. Create a fed share
    curl -XPOST "http://localhost/oc10/ocs/v1.php/apps/files_sharing/api/v1/shares?format=json" \
    -d"shareType=6&shareWith=admin@localhost/core&permissions=19&path=/aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBrownFoxJumpsOverAVeryLazyDog-aQuickBraisdiusadsagdiasdasd.txt" \
    -uadmin:admin
  4. Share is created (:exclamation:)

NOTE: The share request doesn't hit the createShare controller in

public function createShare() {
try {

but hits
public function createShare() {
$share = $this->shareManager->newShare();

@DeepDiver1975
Copy link
Member Author

curl -XPOST "http://localhost/oc10/ocs/v1.php/apps/files_sharing/api/v1/shares?format=json" \

federatedfilesharing is the app -> not files_sharing ....

@DeepDiver1975
Copy link
Member Author

4. Share is created (❗)

worth an issue for further investigation

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

Successfully merging this pull request may close these issues.

None yet

8 participants