|
4 | 4 |
|
5 | 5 | namespace Stancl\Tenancy\Bootstrappers; |
6 | 6 |
|
| 7 | +use Exception; |
7 | 8 | use Illuminate\Foundation\Application; |
8 | 9 | use Illuminate\Session\FileSessionHandler; |
9 | 10 | use Illuminate\Support\Facades\Storage; |
@@ -75,8 +76,13 @@ protected function storagePath(string|false $suffix): void |
75 | 76 | : $this->originalStoragePath . '/framework/cache'; |
76 | 77 |
|
77 | 78 | if (! is_dir($path)) { |
78 | | - // Create tenant framework/cache directory if it does not exist |
79 | | - mkdir($path, 0750, true); |
| 79 | + // Create tenant framework/cache directory if it does not exist. |
| 80 | + // We ignore errors due to TOCTOU race conditions, instead we check for success below. |
| 81 | + @mkdir($path, 0750, true); |
| 82 | + |
| 83 | + if (! is_dir($path)) { |
| 84 | + throw new Exception("Unable to create tenant storage directory [{$path}]."); |
| 85 | + } |
80 | 86 | } |
81 | 87 |
|
82 | 88 | if ($suffix === false) { |
@@ -222,8 +228,13 @@ public function scopeSessions(string|false $suffix): void |
222 | 228 | : $this->originalStoragePath . '/framework/sessions'; |
223 | 229 |
|
224 | 230 | if (! is_dir($path)) { |
225 | | - // Create tenant framework/sessions directory if it does not exist |
226 | | - mkdir($path, 0750, true); |
| 231 | + // Create tenant framework/sessions directory if it does not exist. |
| 232 | + // We ignore errors due to TOCTOU race conditions, instead we check for success below. |
| 233 | + @mkdir($path, 0750, true); |
| 234 | + |
| 235 | + if (! is_dir($path)) { |
| 236 | + throw new Exception("Unable to create tenant session directory [{$path}]."); |
| 237 | + } |
227 | 238 | } |
228 | 239 |
|
229 | 240 | $this->app['config']['session.files'] = $path; |
|
0 commit comments