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

Add share attributes + prevent download permission #32482

Merged
merged 13 commits into from
Aug 1, 2022

Conversation

PVince81
Copy link
Member

@PVince81 PVince81 commented May 18, 2022

Close #16413

  • brings in share attributes column in oc_share
  • store download permission in extended share attributes
  • enforces download restriction
  • backend
  • frontend, add "hide download" permission
  • extension points for secure view ? not for now
  • BUG: share view-only file with link, open link then download => this should be blocked on backend level and in UI
  • BUG: share view-only folder with link, open link then download any entry => this should be blocked on backend level and in UI
  • BUG: reshare with public link should automatically tick "hide download"
  • BUG: reshare with public link should not allow to tick "hide download"
  • BUG: viewer app still opens (optional)
  • TEST: try increasing attribute permissions in reshare create
  • TEST: try increasing attribute permissions in reshare update
  • TODO: make sure versions endpoint also doesn't allow download past versions

@PVince81

This comment was marked as outdated.

@PVince81 PVince81 force-pushed the enh/noid/share-attributes branch from 39e0151 to 98fa5b9 Compare May 19, 2022 15:05
@PVince81
Copy link
Member Author

PVince81 commented May 24, 2022

to test:

  1. Share a folder "test" with another local user
  2. Upload some files into "test", for example and a file "test.odt"
  3. Find share id in the network console
  4. Run curl with the share id:
curl -u admin:admin 'https://domain.tld/ocs/v2.php/apps/files_sharing/api/v1/shares/$shareId` \
  -X 'PUT' \
  -H 'OCS-APIRequest: true' \
-H 'Accept: application/json, text/plain, */*' \
  -H 'Content-Type: application/json' \
  --data-raw '{"attributes":[{"scope": "permissions", "key": "download", "enabled": "false"}]}'
  1. Login as the share recipient
  2. Try downloading the file

=> "Access denied".

Note: this PR doesn't adjust the frontend yet, so the download action is still visible

@PVince81 PVince81 force-pushed the enh/noid/share-attributes branch from 98fa5b9 to e35f472 Compare May 24, 2022 10:08
@PVince81
Copy link
Member Author

PVince81 commented May 25, 2022

  • consider renaming "enabled" to "value" as we likely want more than a boolean there for flexibility ? (also change the method interfaces then)
    • need to consider what happens when merging shares (aka super shares / when receiving the same file/folder through multiple shares). with bools, true would have precedence

=> no, keep booleans due to prioritization

@PVince81 PVince81 force-pushed the enh/noid/share-attributes branch 2 times, most recently from d79d7aa to d70c3e3 Compare May 25, 2022 14:23
@PVince81
Copy link
Member Author

I've fixed more tests, hope they all pass now (minus the node one that is broken on master)

@PVince81
Copy link
Member Author

sqlite only not reproducible locally 😮

1) Test\Share20\DefaultShareProviderTest::testGetShareByIdUserShare
Invalid argument supplied for foreach()

/drone/src/lib/private/Share20/DefaultShareProvider.php:1563
/drone/src/lib/private/Share20/DefaultShareProvider.php:1082
/drone/src/lib/private/Share20/DefaultShareProvider.php:814
/drone/src/tests/lib/Share20/DefaultShareProviderTest.php:221

@PVince81 PVince81 force-pushed the enh/noid/share-attributes branch from d70c3e3 to 4661ad3 Compare May 30, 2022 09:12
@PVince81 PVince81 requested review from artonge and CarlSchwan May 30, 2022 09:12
@PVince81 PVince81 force-pushed the enh/noid/share-attributes branch from 4661ad3 to 9def5b3 Compare May 31, 2022 11:00
@PVince81
Copy link
Member Author

rebased for CI, hopefully everything green after that!

@PVince81
Copy link
Member Author

PVince81 commented Jun 2, 2022

  • simplify permissions in DB ?

    • ex: ["permissions","download",false] or even: {'permissions': {'download': false}}
    • => seems it's already stored

    JSON / HTTP: [{scope:'', permission: 'download': 'enabled': true}, {...}]
    DB `` [$scope, $permission, $enabled]```

=> let's keep this as is

@PVince81
Copy link
Member Author

PVince81 commented Jun 2, 2022

I've added a "Allow download" checkbox now in the frontend and also the logic to read and save it.
Additionally, the share attributes are now available in a "nc:share-attributes" DAV property for clients and is also used by the web UI.

More work needed to:

  • make sure resharing cannot increase download perms

  • make sure public link page doesn't show download action when resharing a received share that has no download perm

  • see if possible to have JS tests for the new bits (at first look it seems we don't have any)

@PVince81 PVince81 requested a review from juliusknorr June 2, 2022 09:35
@PVince81 PVince81 marked this pull request as ready for review June 2, 2022 09:35
@PVince81
Copy link
Member Author

PVince81 commented Jun 2, 2022

would be good to have a first pass review already.
I'll fix conflicts/CI in my next pass

if (this.share.hasDownloadPermission !== isDownloadChecked) {
this.share.hasDownloadPermission = isDownloadChecked
this.queueUpdate('attributes')
}
Copy link
Member Author

Choose a reason for hiding this comment

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

optional: check if we can also skip "permissions"

This comment was marked as resolved.

@PVince81 PVince81 added the 4. to release Ready to be released and/or waiting for tests to finish label Jul 29, 2022
- Fix tests
- Use non deprecated event stuff
- Add a bit of type hinting to the new stuff
- More safe handling of instanceOfStorage (share might not be the first
  wrapper)
- Fix resharing

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan CarlSchwan force-pushed the enh/noid/share-attributes branch from 73e3c4a to 7b72381 Compare July 31, 2022 17:38
Copy link
Member

@CarlSchwan CarlSchwan left a comment

Choose a reason for hiding this comment

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

ci issue unrelated

@CarlSchwan CarlSchwan merged commit f74e89b into master Aug 1, 2022
@CarlSchwan CarlSchwan deleted the enh/noid/share-attributes branch August 1, 2022 07:44
@PVince81
Copy link
Member Author

PVince81 commented Aug 1, 2022

/backport to stable24

@elhananjair
Copy link

Hello, @PVince81
I was waiting for this commit for so long, I tested it recently, and didn't work well with PDF files 😢. It works fine with other files I tested such as .docx .md.

Screenshot from 2022-08-17 20-23-40
Screenshot from 2022-08-17 20-50-31

@PVince81
Copy link
Member Author

@elhananjair yes, the different apps also need to be adjusted to properly recognize the permission and act accordingly.
for apps that don't support view only, they should simply not view the document at all

@juliusknorr
Copy link
Member

I filed nextcloud/files_pdfviewer#649 about this

@iMoshi
Copy link

iMoshi commented Nov 1, 2022

So, I've finally tried the feature, and unchecked "Allow download" when sharing a folder with an internal user, and the user would get "Access forbidden" with basically any document including .pdf.

Is there something I'm missing inside the Administration Settings?

Also, can we have the option to "Allow download" when sharing a single file with an internal user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Download Permission restriction like Hide Download option for internal (user/group) shares
8 participants