This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Commit 08d7abf
authored
fix: Implement path containment to prevent traversal attacks (#2654)
* fix: Implement path containment to prevent traversal attacks
This patch introduces strict path validation in TransferManager.downloadManyFiles to mitigate Arbitrary File Write and Path Traversal vulnerabilities. The fix includes two layers of defense: 1. Rejects Absolute Paths: Immediately throws an error if the object name is an absolute path (e.g., /etc/passwd). 2. Containment Check: Uses path.resolve to normalize the destination path and verify it remains strictly within the intended baseDir, preventing traversal using ../ sequences. SECURITY NOTE: This changes behavior by actively rejecting files with malicious path segments that were previously susceptible to writing outside the target directory.
* fix: Use path.relative for robust path traversal check
* fix: Enforce GCS standard '/' for directory marker detection
* fix: Secure destination path against traversal
* add error message
* fix: Correct download destination logic and ensure recursive directory creation
This commit resolves several critical issues in the `downloadManyFiles` logic related to path handling, destination assignment, and concurrent directory creation, enabling proper execution of bulk downloads and passing relevant tests.
* fix: Optimize fsp.mkdir calls using a Set in downloadManyFiles
Avoids redundant file system calls (fsp.mkdir) when downloading multiple files within the same directory. The call, while idempotent, was being performed for every file download, leading to unnecessary I/O overhead. This commit introduces a to track directories that have already been created within a single call, ensuring that is executed only once per unique destination directory path.
* refactor: Extract base directory initialization/validation
Moves the logic for resolving and validating the base download directory
(`baseDir`, including initial path traversal checks) out of
`downloadManyFiles` and into the private helper
`_resolveAndValidateBaseDir`.
This change cleans up the primary download execution path, making the
file-by-file iteration loop more focused and readable.
* fix
* refactor: Remove explicit .code assignment from RequestError
Removes the 'SECURITY_ABSOLUTE_PATH_REJECTED' &
'SECURITY_PATH_TRAVERSAL_REJECTED' code assignment from the thrown
RequestError. The corresponding test assertion is updated to check the
error message and type instead of the removed .code property.1 parent b38b5d2 commit 08d7abf
File tree
4 files changed
+192
-33
lines changed- samples/system-test
- src
- test
4 files changed
+192
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | | - | |
| 68 | + | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
66 | | - | |
| 73 | + | |
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
70 | 77 | | |
71 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
72 | 83 | | |
73 | | - | |
| 84 | + | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
79 | 90 | | |
80 | 91 | | |
81 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
548 | 551 | | |
549 | 552 | | |
550 | 553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
501 | | - | |
502 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
503 | 510 | | |
504 | 511 | | |
505 | 512 | | |
| |||
587 | 594 | | |
588 | 595 | | |
589 | 596 | | |
| 597 | + | |
| 598 | + | |
590 | 599 | | |
591 | 600 | | |
592 | 601 | | |
593 | 602 | | |
594 | 603 | | |
| 604 | + | |
595 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
596 | 642 | | |
597 | 643 | | |
| 644 | + | |
598 | 645 | | |
599 | 646 | | |
600 | 647 | | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
611 | 652 | | |
612 | 653 | | |
613 | 654 | | |
| |||
618 | 659 | | |
619 | 660 | | |
620 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
621 | 667 | | |
622 | | - | |
623 | 668 | | |
624 | 669 | | |
625 | 670 | | |
| |||
867 | 912 | | |
868 | 913 | | |
869 | 914 | | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
870 | 945 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
221 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
| |||
233 | 237 | | |
234 | 238 | | |
235 | 239 | | |
236 | | - | |
| 240 | + | |
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
| |||
263 | 267 | | |
264 | 268 | | |
265 | 269 | | |
266 | | - | |
267 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
268 | 274 | | |
269 | 275 | | |
270 | 276 | | |
| |||
280 | 286 | | |
281 | 287 | | |
282 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
283 | 340 | | |
284 | 341 | | |
285 | 342 | | |
| |||
301 | 358 | | |
302 | 359 | | |
303 | 360 | | |
304 | | - | |
| 361 | + | |
305 | 362 | | |
306 | 363 | | |
| 364 | + | |
| 365 | + | |
307 | 366 | | |
308 | 367 | | |
309 | 368 | | |
310 | 369 | | |
311 | | - | |
| 370 | + | |
312 | 371 | | |
313 | 372 | | |
314 | 373 | | |
| |||
321 | 380 | | |
322 | 381 | | |
323 | 382 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
328 | 393 | | |
329 | 394 | | |
330 | 395 | | |
| |||
335 | 400 | | |
336 | 401 | | |
337 | 402 | | |
338 | | - | |
339 | | - | |
340 | | - | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
341 | 411 | | |
342 | 412 | | |
343 | 413 | | |
344 | 414 | | |
345 | 415 | | |
346 | 416 | | |
347 | | - | |
| 417 | + | |
348 | 418 | | |
349 | 419 | | |
350 | 420 | | |
| |||
0 commit comments