Page MenuHomePhorge

Add config option for maximum file size
Open, Needs TriagePublic

Description

Hello, we'd like a configuration option to cap the maximum file size, as we don't want to host 180+ MB files (as some users have uploaded in the past ^^;).

Additionally, @valerio.bozzolan has suggested that there be a way to exempt users in certain projects (such as Trusted Contributors) from the size limit.

Ideas for the config name and a small description:

  • files.maximum-file-size: The maximum file size that is allowed to be uploaded. This limit is ignored for users in any of the projects listed in files.ignore-file-size-projects
  • files.ignore-file-size-projects: An array of PHIDs to projects where users in any of the specified projects can ignore files.maximum-file-size

(Downstream task: https://issue-tracker.miraheze.org/T10537)

Revisions and Commits

Event Timeline

Thanks

I like your option names. I like to specify PHIDs and not numeric IDs so it's more portable against import/exports 👍 Let's add Discussion Needed to attract some +1 or nice suggestions.

About the implementation, maybe we can:

  1. add some early lines in PhabricatorFileStorageEngine#loadStorageEngines($size) to throw an early exception if the $size is over this new configuration. Maybe adding a new parameter to receive the PhabricatorUser $viewer
  2. perhaps a refactor inside FileAllocateConduitAPIMethod::execute() to pass the $viewer
  3. SOME MAGIC STUFF to check if an user is in a group (I don't know lol) 🦄

Sounds reasonable.

I think files.ignore-file-size- can maybe be a Policy object, to allow maximum flexibility?

Uh, that would be so good. So you can say "When the moon is full".

Sub-task is maybe, add "Policy" type support for Config.

Yeah, I agree, though I would then only work on implementing files.maximum-file-size because we don't really care that much about adding exceptions to the rule (as far as I know lol)

add some early lines in PhabricatorFileStorageEngine#loadStorageEngines($size) to throw an early exception if the $size is over this new configuration. Maybe adding a new parameter to receive the PhabricatorUser $viewer

I've done it a bit earlier, in PhabricatorFile#buildFromFileData($data, $params). As for getting the viewer (which I presume is the uploader?), I nabbed it off from $params['authorPHID']

We can also ship this feature in two phases, so, first, adding the option files.maximum-file-size, and then the second one when it's ready or requested lol

So still patch welcome upstream (here), especially if you don't want to maintain that locally

Wrote the code for the first phase :p

Should I submit the patch right now, or after the Discussion Needed tag is removed?

Screenshot 2024-12-11 at 17-59-37 Unhandled Exception ( Exception ).png (1×3 px, 132 KB)

Feel free to show something early :) That would attract more attention than the Discussion Needed tag I bet

(we can probably keep this ticket open, so that we have the 2nd part on the backlog. I'm pretty sure we want it to happen "eventually".)