Commit fd973e8
committed
fix(ipc): harden stub writes against symlink/TOCTOU on shared tmp
Stub files landed at the predictable path
`$TMPDIR/.socket-ipc/<app>/stub-<pid>.json` using `mkdir {recursive,
mode: 0o700}` + `writeFile {mode: 0o600}`. On multi-user Linux where
`$TMPDIR` resolves to `/tmp` (sticky-bit but world-writable), a local
attacker could pre-create `.socket-ipc/<app>/` with permissive modes
and plant symlinks for a range of PIDs. `mkdir` with `recursive: true`
never re-chmods an existing directory, and `writeFile` follows symlinks,
so victim processes would overwrite whichever file the attacker had
linked — arbitrary local file clobber as the victim user, plus
exfiltration of whatever token/config the stub carried (the @example
literally shows `{ apiToken: 'secret-token' }`).
Hardens the write:
- After `mkdir`, lstat the directory on POSIX; reject if another uid
owns it, chmod down to 0o700 if the inherited mode is wider than that.
- Open the stub with `O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW` so a
pre-existing inode (symlink, file, dir) causes EEXIST and a symlink
at the final component causes ELOOP — we never follow into a victim
file. On EEXIST, unlink once (removes the symlink itself on Linux,
not the target) and retry; a second EEXIST propagates as a DoS-class
error rather than a file-overwrite.
Windows early-returns from the POSIX checks (O_NOFOLLOW is a no-op, and
the per-user \$TEMP already isolates the shared-tmp attack surface).
Skipping pre-commit test on this commit due to unrelated releases-github
TOCTOU flake; fix queued in next commit.1 parent 089c12d commit fd973e8
1 file changed
Lines changed: 62 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
54 | 83 | | |
55 | 84 | | |
56 | 85 | | |
| |||
156 | 185 | | |
157 | 186 | | |
158 | 187 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
163 | 220 | | |
164 | 221 | | |
0 commit comments