Skip to content

Commit befdd4f

Browse files
committed
Prevent overwriting of encrypted files
1 parent 0af1d2f commit befdd4f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Illuminate/Foundation/Console/EnvironmentDecryptCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public function handle()
8080
$encryptedFile = $environmentFile.'.encrypted';
8181
$filename = $this->option('filename') ? base_path($this->option('filename')) : $environmentFile;
8282

83+
if (Str::endsWith($filename, '.encrypted')) {
84+
$this->components->error('Invalid filename.');
85+
86+
return Command::FAILURE;
87+
}
88+
8389
if (! $this->files->exists($encryptedFile)) {
8490
$this->components->error('Encrypted environment file not found.');
8591

tests/Integration/Console/EnvironmentDecryptCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,15 @@ public function testItWritesTheEnvironmentFileCustomFilename()
225225
$this->filesystem->shouldHaveReceived('put')
226226
->with(base_path('.env'), 'APP_NAME="Laravel Two"');
227227
}
228+
229+
public function testItCannotOverwriteEncryptedFiles()
230+
{
231+
$this->artisan('env:decrypt', ['--env' => 'production', '--key' => 'abcdefghijklmnop', '--filename' => '.env.production.encrypted'])
232+
->expectsOutputToContain('Invalid filename.')
233+
->assertExitCode(1);
234+
235+
$this->artisan('env:decrypt', ['--env' => 'production', '--key' => 'abcdefghijklmnop', '--filename' => '.env.staging.encrypted'])
236+
->expectsOutputToContain('Invalid filename.')
237+
->assertExitCode(1);
238+
}
228239
}

0 commit comments

Comments
 (0)