Skip to content

Commit 480e7d1

Browse files
jack-wormannicolas-grekas
authored andcommitted
Fix-type-error-when-revealing-broken-secret
1 parent ec77126 commit 480e7d1

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/SecretsRevealCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6161
if (!\array_key_exists($name, $secrets)) {
6262
$io->error(\sprintf('The secret "%s" does not exist.', $name));
6363

64+
return self::INVALID;
65+
} elseif (null === $secrets[$name]) {
66+
$io->error(\sprintf('The secret "%s" could not be decrypted.', $name));
67+
6468
return self::INVALID;
6569
}
6670

src/Symfony/Bundle/FrameworkBundle/Secrets/AbstractVault.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ abstract public function reveal(string $name): ?string;
3131

3232
abstract public function remove(string $name): bool;
3333

34+
/**
35+
* @return array<string, string|null>
36+
*/
3437
abstract public function list(bool $reveal = false): array;
3538

3639
protected function validateName(string $name): void

src/Symfony/Bundle/FrameworkBundle/Secrets/DotenvVault.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public function list(bool $reveal = false): array
8989

9090
foreach ($_ENV as $k => $v) {
9191
if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
92-
$secrets[$k] = $reveal ? $v : null;
92+
$secrets[$k] = \is_string($v) && $reveal ? $v : null;
9393
}
9494
}
9595

9696
foreach ($_SERVER as $k => $v) {
9797
if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
98-
$secrets[$k] = $reveal ? $v : null;
98+
$secrets[$k] = \is_string($v) && $reveal ? $v : null;
9999
}
100100
}
101101

src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsRevealCommandTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ public function testInvalidName()
4646
$this->assertStringContainsString('The secret "undefinedKey" does not exist.', trim($tester->getDisplay(true)));
4747
}
4848

49+
public function testFailedDecrypt()
50+
{
51+
$vault = $this->createMock(AbstractVault::class);
52+
$vault->method('list')->willReturn(['secretKey' => null]);
53+
54+
$command = new SecretsRevealCommand($vault);
55+
56+
$tester = new CommandTester($command);
57+
$this->assertSame(Command::INVALID, $tester->execute(['name' => 'secretKey']));
58+
59+
$this->assertStringContainsString('The secret "secretKey" could not be decrypted.', trim($tester->getDisplay(true)));
60+
}
61+
4962
/**
5063
* @backupGlobals enabled
5164
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy