Page MenuHomePhabricator

Wrong permissions on created .pywikibot folder
Closed, ResolvedPublicBUG REPORT

Description

When pywikibot/config.py creates a ~/.pywikibot folder, it does so with mode 0600, whereas it should be 0700.

On line 350) it is doing

os.makedirs(dir_s, mode=private_files_permission)

with private_files_permission defined on line 255 as

private_files_permission = stat.S_IRUSR | stat.S_IWUSR

These make sense for _files_ permissions, but for a folder it should include stat.S_IXUSR (+x) as well

I suppose it would probably need a line

private_directories_permission = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR

used for this

Event Timeline

0700 was changed previously to 0600 in rPWBC049cd8a7 due to T206385.

@Urbanecm: As you committed rPWBC049cd8a7 due to T206385 could you give your comment to this issue or decline it if appropriate?

Hi, I think it is appropriate to set +x for directories (for those, it means "can be cd'ed into"). My concern in T206385 was only for files, and I didn't realize the directive applies to directories as well.

@Urbanecm My understanding of +x for directories is that it it allows the directory to be used as part of a pathname (i.e. translating the path into an inode). Which effectively means you can't access the files in it. The fact that you can't cd into a directory is just a side-effect of that.

This can lead to bizarre behavior such as being able to do shell expansion on filenames in the directory, but not actually be able to access those files, because the shell expansion only relies on read permission on the directory:

$ ls -ld .pywikibot/
drw---S--- 3 tools.dyk-tools tools.dyk-tools 4096 Oct 11 23:54 .pywikibot/
$ cat .pywikibot/user-config.py     <-- I typed ".pywikibot/u<tab>" and got this
cat: .pywikibot/user-config.py: Permission denied

The bottom line is, yes, the .pywikibot directory should be executable.

Change 841875 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] Revert "Change default file mode for private files to 600"

https://gerrit.wikimedia.org/r/841875

Xqt triaged this task as High priority.

Change 841875 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Add a new variable 'private_folder_permission' to config.py

https://gerrit.wikimedia.org/r/841875