Hi all,
TL;DR:
Today, upload permissions, when set numerically, are applied verbatim to uploaded files and the folders created to hold them. It is suggested to use the process umask to limit these permissions.
Details:
In unix-like systems, umask is a process-level setting, which helps determine the permissions of new files and folders when they are created. It is a mask of bits, which specifies the permissions to deny by default. As an example, if a process has it set to 0o022, then, by default, new files and directories created by that process will be readable by everyone, but writable only by the process’ user (2 is the write bit, and it is removed from the group and other sets of permissions).
A couple of months ago, we were handling CVE-2026-25674 in the Security Team. The fix, in essence, was to set permissions on folders directly, where older code was relying on umask manipulations. But in the discussions around that fix, it occurred to us that it may be preferable to respect the process umask – something we don’t do today.
Today, the permissions set for uploaded files and the directories created to hold them, are taken from the FILE_UPLOAD_PERMISSIONS and FILE_UPLOAD_DIRECTORY_PERMISSIONS settings, and without regard to the process umask (unless the setting is None).
Making the permissions of saved files subject to umask means that access to these files may become more (but never less) restricted than specified by the permissions. But more importantly, the umask is a parameter that is familiar to sysadmins, and is easier for them to handle than a Django-specific parameter in a Django-and-deployment-specific settings definition.
On the other hand, naive users might be surprised if they set specific permissions, and the files end up created with less permissions.
We think this is a worth-while hardening, but as such, it deserves public discussion. Opinions, suggestions and arguments are more than welcome.