Commit 67c730e
committed
fix(storage): write userData JSON files owner-only
writeJson backs secrets.json (provider API keys), sessions.json,
settings.json and projects.json. It wrote with no mode, so the files landed
at the process umask — 0644 normally, 0664 under the umask 002 several
distributions ship — leaving their contents readable to anything that
reaches them: another account on a shared machine, a backup or sync tool,
an archive unpacked elsewhere. The userData directory is usually
restrictive enough to cover that on a single-user desktop, but a stored
credential shouldn't depend on its parent directory's mode.
The mode has to go on the temp file rather than the destination: writeJson
writes to a temp path and renames over the target, so the destination inode
is replaced on every write and takes the temp file's mode with it. Chmod'ing
the destination instead would leave a window where the contents are
readable and be undone by the next write — which also means a user who
chmod 600'd the file by hand had it silently reset.
Because writeFileSync only applies `mode` when it creates the file, the temp
path is removed first rather than chmod'd afterwards; that keeps a stale
temp file from a crashed write from carrying its old mode through, without
adding a syscall that could fail between the write and the rename and lose
the data.
Existing files are tightened on first read, once per path per run — a key
set once and never changed is only ever read, so fixing this on write alone
would never reach the installs that already have the problem. That step is
best-effort and logs rather than throwing. No behaviour change on Windows,
where the mode has no meaning and the tests are skipped.1 parent 07895f0 commit 67c730e
2 files changed
Lines changed: 70 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
37 | 65 | | |
38 | 66 | | |
39 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
46 | 78 | | |
47 | 79 | | |
48 | 80 | | |
49 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
50 | 91 | | |
51 | 92 | | |
0 commit comments