Skip to content

Commit ffb21c1

Browse files
committed
stop using uniqid() to create temporary files
1 parent 04f9e6d commit ffb21c1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Symfony/Component/DomCrawler/Field/FileFormField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public function setValue(?string $value): void
5555
$name = $info['basename'];
5656

5757
// copy to a tmp location
58-
$tmp = sys_get_temp_dir().'/'.strtr(substr(base64_encode(hash('xxh128', uniqid(mt_rand(), true), true)), 0, 7), '/', '_');
58+
$tmp = tempnam(sys_get_temp_dir(), $name);
5959
if (\array_key_exists('extension', $info)) {
60+
unlink($tmp);
6061
$tmp .= '.'.$info['extension'];
6162
}
6263
if (is_file($tmp)) {

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public function tempnam(string $dir, string $prefix, string $suffix = ''): strin
611611
// Loop until we create a valid temp file or have reached 10 attempts
612612
for ($i = 0; $i < 10; ++$i) {
613613
// Create a unique filename
614-
$tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true).$suffix;
614+
$tmpFile = $dir.'/'.$prefix.bin2hex(random_bytes(4)).$suffix;
615615

616616
// Use fopen instead of file_exists as some streams do not support stat
617617
// Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability

0 commit comments

Comments
 (0)