Commit bbb8928
committed
fix(tui): use secure random temp files in external editor to prevent symlink attacks
The external editor was using predictable temp filenames based on PID
(cortex_prompt_{PID}.md), making it vulnerable to symlink attacks where
an attacker could:
1. Predict the filename before cortex creates it
2. Create a symlink pointing to a sensitive file
3. When cortex writes to the temp file, it overwrites the symlink target
This fix uses the tempfile crate which:
- Creates files with cryptographically random names (16 random bytes)
- Uses O_EXCL flag to fail if file exists (preventing TOCTOU races)
- Sets restrictive permissions (0600 on Unix)
Changes:
- Replace predictable PID-based filenames with random tempfile names
- Use tempfile::Builder for secure temp file creation
- Update both async and sync versions of open_external_editor
- Add tempfile as a runtime dependency (was already dev dependency)
Security Impact:
Prevents local privilege escalation via symlink attacks on temp files.
Fixes: issue #54051 parent c398212 commit bbb8928
2 files changed
+32
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
170 | 175 | | |
171 | | - | |
| 176 | + | |
172 | 177 | | |
173 | 178 | | |
174 | 179 | | |
175 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
176 | 184 | | |
177 | 185 | | |
178 | 186 | | |
| |||
219 | 227 | | |
220 | 228 | | |
221 | 229 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
225 | 238 | | |
226 | | - | |
| 239 | + | |
227 | 240 | | |
228 | | - | |
| 241 | + | |
229 | 242 | | |
230 | 243 | | |
231 | 244 | | |
232 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
233 | 249 | | |
234 | 250 | | |
235 | 251 | | |
| |||
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
267 | | - | |
| 283 | + | |
268 | 284 | | |
269 | | - | |
| 285 | + | |
| 286 | + | |
270 | 287 | | |
271 | 288 | | |
272 | | - | |
| 289 | + | |
273 | 290 | | |
274 | 291 | | |
275 | 292 | | |
| |||
0 commit comments