Skip to content

feat(dav): restrict allowed file types on public share uploads - #66562

Open
vlotysh wants to merge 3 commits into
nextcloud:masterfrom
vlotysh:feat/restrict-allowed-file-types-share
Open

vlotysh wants to merge 3 commits into
nextcloud:masterfrom
vlotysh:feat/restrict-allowed-file-types-share

Conversation

@vlotysh

@vlotysh vlotysh commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Name-based check: file extension and IMimeTypeDetector::detectPath(), the file content is not inspected.
  • Regular upload: PUT → beforeBind → 415 Unsupported Media Type.
  • Chunked upload, early check: MKCOL uploads/<token>/<id> with a Destination header → beforeMkcol → 415 before the first chunk is sent.
  • Chunked upload, main check: chunks are skipped, the final MOVE .file is checked in beforeBind against the destination name, before the chunks are assembled.
  • MOVE/COPY of collections that are not part of the share (upload folders) → 403.
  • Shares without the upload.allowed_types attribute are not affected.

before
image

after
image
Screenshot 2026-11-18 at 16 04 22

Checklist

AI (if applicable)

  • [ x] The content of this PR was partly or fully generated using AI

@vlotysh
vlotysh requested review from a team and skjnldsv as code owners November 13, 2026 15:13
@vlotysh
vlotysh requested review from CarlSchwan, GhassenKefi, icewind1991, kristian-zendato, pabzm and susnux and removed request for a team November 13, 2026 15:13
@vlotysh
vlotysh force-pushed the feat/restrict-allowed-file-types-share branch from 15a0d06 to 7c64154 Compare November 13, 2026 15:21
@susnux susnux added enhancement 3. to review Waiting for reviews labels Nov 13, 2026
@vlotysh
vlotysh force-pushed the feat/restrict-allowed-file-types-share branch 3 times, most recently from 5a07907 to 61382c1 Compare November 15, 2026 18:35

@icewind1991 icewind1991 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Backend wise, looks good otherwise

/**
* @param class-string $collectionClass
*/
private function isChildOf(string $path, string $collectionClass): bool {

Copy link
Copy Markdown
Member

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 doesn't really match the functionality (anymore?).

Comment thread apps/dav/appinfo/v2/publicremote.php Outdated

$linkCheckPlugin = new PublicLinkCheckPlugin();
$filesDropPlugin = new FilesDropPlugin();
$allowedFileTypesPlugin = new AllowedFileTypesPlugin(Server::get(IMimeTypeDetector::class));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can directly get the AllowedFileTypesPlugin from Server::get instead of just it's constructor parameter.

This mainly removes friction if the params of AllowedFileTypesPlugin ever need to be changed in the future.

Signed-off-by: Vladyslav Lotysh <lotysh.vm@gmail.com>
Assisted-by: ClaudeCode:claude-opus-5-5
@vlotysh
vlotysh force-pushed the feat/restrict-allowed-file-types-share branch from 61382c1 to cb0b075 Compare November 17, 2026 18:58

@salmart-dev salmart-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello @vlotysh thanks for your PR 😄

The direction looks good, I would suggest some improvements and spotted a few issues.

completeness: the PR doesn't seem to cover the file requests dialog (NewFileRequestDialog), which could benefit from the same feature.

usability: I think the current design would be quite hard to use for the following reasons:

  • the UI expects a comma-separated free-form text, which is very easy to get wrong, for example with a typo, and very hard for a non-technical person to use
  • there is no validation for either extensions or mime types, so if there is an issue with the input, the person configuring the share won't know until a user will complain that uploading is not working.
  • it is confusing to be able to provide a mime-type, but this still resulting into just an extension check and could be misleading, so should probably be mentioned in the UI that it would just be a convenience filter, or the mime-type should actually detected via the file content.

I would have a few suggestions to make this much more usable from my point of view:

  1. suggestion: free text should only be accepted for file extensions, to allow users requesting files with extensions that the server does not recognise. Free-form input of MIME-types is useless in this case, as anything the server would not recognise would be rejected.
  2. usability: MIME types should be suggested/pickable from a list, as hey are known by the backend. This eliminates the possibility of typos that would be hard to spot.
  3. nice-to-have: the server already has an extensible list of mime types, with human-readable names. This PR could build on that by adding a similar extensible list for categories that map to lists of mimes, e.g. 'Documents', Images, Audio, Video, etc... that could be also selectable and include more than one MIME-type. This way users could start typing and get a category or a MIME-type offered, or also input a custom extension.

* Main idea: Browsers take MIME types from the OS (application/x-zip-compressed e.g.),
* which can differ from the server detection, so MIME rules are checked by the server only.
* We will only check extensions here, and if the list contains MIME types, we will let the server handle it.
* Chunking will diclined unsupported file types

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: typo on word decline

* We will only check extensions here, and if the list contains MIME types, we will let the server handle it.
* Chunking will diclined unsupported file types
*
* But if extensions are provided, we will check them here, as the server will not check them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: I don't think this matches the implementation. The code is always and only checking the extension, right?

public function initialize(Server $server): void {
$this->server = $server;
$server->on('beforeMethod:MKCOL', [$this, 'beforeMkcol']);
$server->on('beforeBind', [$this, 'beforeBind']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix: this only runs after FilesDropPlugin already creates the folder structure for the upload and when upload is blocked, so those folders would be left behind when upload is rejected.

@vlotysh

vlotysh commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Hello @vlotysh thanks for your PR 😄

The direction looks good, I would suggest some improvements and spotted a few issues.

completeness: the PR doesn't seem to cover the file requests dialog (NewFileRequestDialog), which could benefit from the same feature.

usability: I think the current design would be quite hard to use for the following reasons:

  • the UI expects a comma-separated free-form text, which is very easy to get wrong, for example with a typo, and very hard for a non-technical person to use
  • there is no validation for either extensions or mime types, so if there is an issue with the input, the person configuring the share won't know until a user will complain that uploading is not working.
  • it is confusing to be able to provide a mime-type, but this still resulting into just an extension check and could be misleading, so should probably be mentioned in the UI that it would just be a convenience filter, or the mime-type should actually detected via the file content.

I would have a few suggestions to make this much more usable from my point of view:

  1. suggestion: free text should only be accepted for file extensions, to allow users requesting files with extensions that the server does not recognise. Free-form input of MIME-types is useless in this case, as anything the server would not recognise would be rejected.
  2. usability: MIME types should be suggested/pickable from a list, as hey are known by the backend. This eliminates the possibility of typos that would be hard to spot.
  3. nice-to-have: the server already has an extensible list of mime types, with human-readable names. This PR could build on that by adding a similar extensible list for categories that map to lists of mimes, e.g. 'Documents', Images, Audio, Video, etc... that could be also selectable and include more than one MIME-type. This way users could start typing and get a category or a MIME-type offered, or also input a custom extension.

Hi! Thanks for the review.

I'll build the list of MIME types from IMimeTypeDetector::getAllMappings() and map them to human-readable names with IMimeTypeDetector::getAllNamings().

Signed-off-by: Vladyslav Lotysh <lotysh.vm@gmail.com>
Assisted-by: ClaudeCode:claude-opus-5-5
…e server

Signed-off-by: Vladyslav Lotysh <lotysh.vm@gmail.com>
Assisted-by: ClaudeCode:claude-opus-5-5
@vlotysh

vlotysh commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@salmart-dev

Commit 1

  • Check the target file in beforeMethod for MKCOL, PUT and MOVE, before
    FilesDropPlugin creates the nickname and parent folders, so a rejected
    upload no longer leaves empty folders behind

  • Replaces the MKCOL-only early check; beforeBind still covers renames,
    copies and the collection whitelist

  • Fix the comment of the client-side check: the browser only checks
    lists of file extensions

    Commit 2

    • Replace the comma-separated text field with a select of the MIME types
      known to the server and the image, video, audio and text groups
  • Free input is only accepted for file extensions (pdf, *.pdf -> .pdf),
    invalid input cannot be selected

  • Explain below the field that uploads are checked by file name and
    extension, not by content

  • Add the limit to the file request dialog and keep it when emails are
    added, as the update replaces all share attributes

  • Reject MIME types and groups unknown to the server in the API

@vlotysh
vlotysh requested a review from salmart-dev November 18, 2026 15:10

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict file extension / mime type for file drop share

4 participants