core icon indicating copy to clipboard operation
core copied to clipboard

Fix exception on external storages public links when encryption enabled

Open pako81 opened this issue 1 year ago • 8 comments

Description

Having masterkey encryption enabled, when trying to upload into a public link created on an external storage (i.e. of type "Local" or "WND") being assigned to at least one user/group, an exception Attempted to initialize mount points for null user and no user in session is being thrown and no upload is possible.

Related Issue

  • Fixes https://github.com/owncloud/enterprise/issues/6626

Motivation and Context

There was a problem around https://github.com/owncloud/core/blob/master/lib/private/Encryption/Util.php#L303 as the uid provided to the method is false in this case. This happens because the external storage doesn't really have an owner and there is no user in the session. Therefore, when checking for isMountPointApplicableToUser, the provided user is false which will never find a match, so the mount point isn't considered system wide.

How Has This Been Tested?

  1. enable masterkey encryption
  2. create an external storage through the "local" option (also reproducible with WND) and mount it for user admin
  3. as user admin creates a public link on the external storage root
  4. try to upload into the created public link: an exception Attempted to initialize mount points for null user and no user in session is shown and file cannot be uploaded
  5. try to download an existing file works. Try to download any other file added by user admin after the storage has been mounted into oC fails with File cannot be downloaded and same exception in logs
  6. With this change in place both exceptions at 4. and 5. are solved.

Types of changes

  • [X] 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:

  • [X] Code changes
  • [ ] Unit tests added
  • [ ] Acceptance tests added
  • [ ] Documentation ticket raised
  • [x] Changelog item

pako81 avatar May 06 '24 07:05 pako81

There was an additional problem according to https://github.com/owncloud/enterprise/issues/6626#issuecomment-2084853496 , is it solved? or will it be fixed later?

jvillafanez avatar May 06 '24 08:05 jvillafanez

There was an additional problem according to https://github.com/owncloud/enterprise/issues/6626#issuecomment-2084853496 , is it solved? or will it be fixed later?

I guess we can try to fix it here. But I don't quite get why we are not getting into https://github.com/owncloud/core/blob/master/lib/private/Preview.php#L1229-L1231 as $user should be empty at that point.

pako81 avatar May 06 '24 10:05 pako81

https://github.com/owncloud/core/blob/master/lib/private/Files/View.php#L1475 The user isn't empty. It's likely a RemoteUser.

The case where the user is false isn't being handled properly. Even if the storage returns a null or false owner, the view will consider it as a remote user. I guess that's what the Filesystem::getOwner is returning.

jvillafanez avatar May 06 '24 10:05 jvillafanez

I guess that's what the Filesystem::getOwner is returning.

AFAICT from https://github.com/owncloud/core/blob/master/lib/private/Preview.php#L1228 we get false back.

pako81 avatar May 07 '24 14:05 pako81

Note: a changelog was added by #41247 but was named https://github.com/owncloud/core/blob/master/changelog/unreleased/41246

So that is why there is a conflict here!

I made #41248 to fix that.

phil-davis avatar May 07 '24 14:05 phil-davis

@pako81 is this ready to go into 10.15.0?

jnweiger avatar Jul 09 '24 15:07 jnweiger

After 10.15.0 - converting to draft for now.

jnweiger avatar Jul 09 '24 20:07 jnweiger

cleaning up - I think this is no longer of anybody's interest

DeepDiver1975 avatar Nov 19 '24 07:11 DeepDiver1975