The Google Drive client secret is written with permissions readable by other local users in whatstk
Description
Incorrect Default Permissions (CWE-276) in gdrive_init() (whatstk/utils/gdrive.py), in whatstk from 0.5.0 before 0.9.0. Another user of the same machine can read the Google Drive OAuth client secret belonging to the user who ran the initialisation.
The function creates ~/.config/whatstk/gdrive with os.makedirs and no mode argument, copies the supplied client secret file to client_secrets.json with shutil.copyfile, and writes settings.yaml through a plain open call. None of the three specifies a mode, so each takes whatever the process umask allows. Under a default umask of 022 the directory is created 0755 and both files 0644.
shutil.copyfile does not carry the source file's permissions over. A client secret the user had restricted to 0600 is therefore written out at 0644, so the library widens a file its owner had deliberately protected rather than preserving its mode.
What decides whether the files end up readable by other local users is the umask in force when gdrive_init runs, together with the permissions of the directories above them. It is not the mode of the file the user supplied.
The refresh token in credentials.json is written by pydrive2 and not by whatstk, and is observed at 0600. The exposure is therefore of the OAuth client secret and of the generated settings, not of the token that authorises access to the account's Drive.
Vulnerability type (CWE)
- CWE-276: Incorrect Default Permissions
Affected versions
whatstk from 0.5.0 before 0.9.0. Default status: unaffected.
The Google Drive module arrives in 0.5.0 and releases before that carry no whatstk/utils/gdrive.py at all. Checked by reading the module at every one of the project's 26 release tags: the directory creation without a mode and the shutil.copyfile are present and unchanged from v0.5.0 through v0.8.1, the restrictive modes are in place from v0.9.0, and the module is absent again from v0.10.0.
Reproduced by replicating the exact file creation of each path against a source client secret file set to 0600. On the 0.5.0 to 0.8.1 path with umask 022: directory 0755, client_secrets.json 0644, settings.yaml 0644. The same path with umask 077: 0700 and 0600 throughout, which is the condition the exposure depends on. On the 0.9.0 path both umasks give 0700 and 0600.
Score (CVSS 4.0)
Low (2.0)
CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N
The attack vector is Local because the file is read from the filesystem of the machine that ran the initialisation. The privileges required are Low because the reader needs an account on that machine. The attack requirements are Present because the exposure is not unconditional: it depends on the umask in force when gdrive_init ran, and on the directories above the file permitting another user to traverse to it, neither of which is under the reader's control. The user interaction is None because the owner takes no further action. Confidentiality on the vulnerable system is Low because what is exposed is the OAuth client secret and the generated settings, while the refresh token that would authorise access to the account's Drive is written at 0600 by pydrive2 and is not part of this exposure. Integrity and availability are None: the files are readable, and nothing in this finding writes to them. The subsequent system metrics are None, since reading the client secret does not by itself reach the Google account.
Solution
Upgrade to whatstk 0.9.0 or later.
Running gdrive_init once on the upgraded version also tightens a directory and files left behind by an earlier version, so an existing installation does not need fixing by hand.
Google Drive support is deprecated in 0.9.0 and the module is removed in 0.10.0, which does not carry this code at all.
Patch
Released in 0.9.0, through pull request #183 and the release commit 01d66d8.
The module declares CONFIG_DIR_MODE of 0o700 and CREDENTIAL_FILE_MODE of 0o600. A _write_private helper passes the mode to os.open instead of applying it with a later chmod, so the file does not exist with open permissions even briefly, and it follows with an explicit chmod because O_TRUNC leaves an existing file's mode untouched.
os.makedirs now receives the mode, and an explicit chmod follows it, which is what also tightens a directory created by an earlier version. The copy is replaced by reading the source and writing it through _write_private, so the dropped permissions of shutil.copyfile no longer apply. credentials.json is set to 0600 once pydrive2 has written it, rather than relying on pydrive2 continuing to do so.
Credits
- a19albertons - finder
- Xoán M. Otero Jorge - analyst
- Darío Rivas - analyst
- Secur0 CNA - coordinator
- Lucas Rodés-Guirao - remediation developer Discovery source: External
Official record: CVE-2026-141426
Related records
- CVE-2026-121691 - unbounded ZIP extraction in the same library
- CVE-2026-121577 - unescaped header separators building a regular expression that backtracks exponentially in the same library
- CVE-2026-121564 - silent message loss when merging overlapping exports in the same library