Commit d82fa5f
committed
fix: create temp dirs with mkdtemp, not a name built from Date.now()
Closes nine open `js/insecure-temporary-file` alerts — the technically
correct ones. An audit of all 29 open alerts for that rule split them
three ways:
- 19 false positives: the write lands inside a directory the caller
already made with `mkdtempSync`, and CodeQL's dataflow reaches
`tmpdir()` without seeing the mkdtemp in between.
- 1 mitigated: `fontCompression.ts` writes with `flag: "wx"` and only
takes the tmpdir branch inside Lambda, where /tmp is single-tenant.
- 9 real, and these are them. A name built from `Date.now()` under the
shared temp dir, followed by `mkdirSync`, is guessable to the
millisecond AND leaves a window between choosing the name and creating
it, so on a shared machine another user can pre-create or symlink the
path first.
`mkdtempSync` closes both halves: it picks the random suffix and creates
the directory 0700 in one syscall. Same shape, one line shorter, and the
alerts go away rather than being dismissed.
Six sites in `normalize.test.ts` (its `mkdirSync` import goes with them),
one in `generate-catalog-previews.ts` — that single construction accounted
for three alerts, since the other two were writes into the directory it
made.
No shared helper. `mkdtempSync` is already the stdlib primitive for
exactly this, and the two callers live in different packages, so a wrapper
would need a home in core to serve one CLI test and one build script —
more indirection than the line it saves.
Deliberately not touching the other 20: excluding the rule repo-wide would
hide this class of bug from future code, which is the reason these are
fixed rather than silenced.1 parent 5752d22 commit d82fa5f
2 files changed
Lines changed: 12 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
478 | 477 | | |
479 | 478 | | |
480 | 479 | | |
481 | | - | |
482 | | - | |
| 480 | + | |
483 | 481 | | |
484 | 482 | | |
485 | 483 | | |
| |||
501 | 499 | | |
502 | 500 | | |
503 | 501 | | |
504 | | - | |
505 | | - | |
| 502 | + | |
506 | 503 | | |
507 | 504 | | |
508 | 505 | | |
| |||
516 | 513 | | |
517 | 514 | | |
518 | 515 | | |
519 | | - | |
520 | | - | |
| 516 | + | |
521 | 517 | | |
522 | 518 | | |
523 | 519 | | |
| |||
530 | 526 | | |
531 | 527 | | |
532 | 528 | | |
533 | | - | |
534 | | - | |
| 529 | + | |
535 | 530 | | |
536 | 531 | | |
537 | 532 | | |
| |||
572 | 567 | | |
573 | 568 | | |
574 | 569 | | |
575 | | - | |
| 570 | + | |
576 | 571 | | |
577 | 572 | | |
578 | 573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
174 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| |||
0 commit comments