Commit ce787f3
committed
Reject non-string prefix, postfix, template
The relative-value guard in `_assertPath` calls `.includes('..')` directly on
the user-supplied value. When the value is an Array the call checks element
equality (so `['../escape'].includes('..')` is false), and when the value is
an arbitrary object a duck-typed `includes` returning false defeats the check
entirely. In both cases the value is subsequently coerced to a string by
`Array.prototype.join` inside `_generateTmpName` and by `path.join`, so a
non-string carrying `../` still produces a path that escapes `tmpdir`.
Tighten `_assertPath` to require `typeof value === 'string'` before the
substring check, and apply the same type check to `template` ahead of the
existing `XXXXXX` regex match (otherwise `match` throws on a non-string with
an unrelated error). The error includes the option name so consumers can see
which option was wrong.
Adds a `test/GHSA-7c78-jf6q-g5cm-test.js` that exercises array, duck-typed
object, and primitive (number) inputs across `fileSync`, `dirSync`, and
`tmpNameSync`, and asserts that valid string inputs are still accepted.
Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>1 parent 41f7159 commit ce787f3
2 files changed
Lines changed: 105 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
530 | 536 | | |
531 | 537 | | |
532 | 538 | | |
533 | | - | |
534 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
535 | 545 | | |
536 | 546 | | |
537 | 547 | | |
538 | | - | |
| 548 | + | |
539 | 549 | | |
540 | 550 | | |
541 | 551 | | |
| |||
558 | 568 | | |
559 | 569 | | |
560 | 570 | | |
561 | | - | |
562 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
563 | 578 | | |
564 | 579 | | |
565 | 580 | | |
| |||
575 | 590 | | |
576 | 591 | | |
577 | 592 | | |
578 | | - | |
579 | | - | |
580 | | - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
581 | 596 | | |
582 | 597 | | |
583 | 598 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 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 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
0 commit comments