Commit ebb17cb
committed
mktemp: Prevent race condition when setting permissions for tempdir
This prevents a race conditions vulnerability in the tempdir implementation, where an attacker
potentially could modify the created temporary directory, before the restrictive permissions are
set.
The race conditions occurs in the moment between the temporary directory is created, and the proper
permissions are set.
# The fix
This patch changes the `make_temp_dir` to create the temporary directory with the proper
permissions creation time. Rather than first create, then set permissions.
This is done by giving the permissions to the builder.
See [tempfile doc](https://github.com/Stebalien/tempfile/blob/95540ed3fcb9ca74845c02aee058726b2dca58b7/src/lib.rs#L449-L450).
# Severity Low
The attack is only possible if the umask is configured to allow writes by group or other for created
file/directories.
# Related Resources
See: https://cwe.mitre.org/data/definitions/377.html1 parent 17d81bb commit ebb17cb
1 file changed
+8
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
461 | 469 | | |
462 | 470 | | |
463 | 471 | | |
464 | 472 | | |
465 | | - | |
466 | | - | |
467 | 473 | | |
468 | 474 | | |
469 | 475 | | |
| |||
0 commit comments