andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.63k stars 177 forks source link

User's trash folder isn't using 700 for permissions #238

Closed Jackenmen closed 2 years ago

Jackenmen commented 2 years ago

Describe the bug Due to a change in how os.makedirs(...) works in Python 3.7 and above, when you create ~/.local/share/Trash/files folder or $rootdir/Trash/$uid/files folder, the ~/.local/share/Trash/$rootdir/.Trash/$uid folder does not use 700 for its permissions.

Relevant change: https://github.com/python/cpython/commit/e304e33c16e060932d1e2cc8a030d42b02b429b5

trash-cli version trash-put 0.22.4.16

Operating system:

To Reproduce

I probably wouldn't suggest actually removing your whole trash directory just to test this, I used a container to make it easier for me to test :)

$ rm -rf ~/.local/share/Trash
$ touch ~/foo
$ trash-put ~/foo
$ ls -al ~/.local/share/Trash
total 16
drwxr-xr-x 4 root root 4096 Jul 10 03:20 .
drwxr-xr-x 3 root root 4096 Jul 10 03:20 ..
drwx------ 2 root root 4096 Jul 10 03:20 files
drwx------ 2 root root 4096 Jul 10 03:20 info

Similarly, when using different volume for / and /home, /Trash/$uid folder has wrong permissions as well (this output is from my actual OS to show how it works with multiple volumes which is the reason why the perms are a bit different - I have a different umask from the one in the container I tested in):

❯ ls -al /.Trash/$UID
total 16
drwxrwxr-x 4 ubuntu ubuntu 4096 lip 10 04:50 .
drwxrwxrwt 3 root   root   4096 lip 10 04:50 ..
drwx------ 2 ubuntu ubuntu 4096 lip 10 04:50 files
drwx------ 2 ubuntu ubuntu 4096 lip 10 04:50 info

Expected behavior I expected ls -al ~/.local/share/Trash to return:

total 16
drwx------ 4 root root 4096 Jul 10 03:15 .
drwxr-xr-x 5 root root 4096 Jul 10 03:15 ..
drwx------ 2 root root 4096 Jul 10 03:15 files
drwx------ 2 root root 4096 Jul 10 03:15 info

Additional information This causes KDE to treat such directory as insecure:

kf.kio.slaves.trash: Directory "//.Trash/1000" exists but didn't pass the security checks, can't use it

https://github.com/KDE/kio/blob/7f02360d9d47bc734941415b57cacefe6bf6a755/src/ioslaves/trash/trashimpl.cpp#L1125-L1134