Skip to content

Commit 5910180

Browse files
authored
Improve secret manager provider robustness and consistency (#65)
- Handle base64_decode returning false in AWS binary secret handling - Add recursion depth limit to Vault addSecretsFromData for consistency with Azure and Google providers - Add missing string type hint to SecretManager::getSecrets()
1 parent 775b39f commit 5910180

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Clients/AwsSecretsManagerClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ public function getSecretValue(string $secretId): array
7373
$secretValue = $result->get('SecretString');
7474
if ($secretValue === null) {
7575
$binaryData = $result->get('SecretBinary');
76-
$secretValue = $binaryData !== null ? base64_decode($binaryData) : '';
76+
if ($binaryData !== null) {
77+
$decoded = base64_decode($binaryData);
78+
$secretValue = $decoded !== false ? $decoded : '';
79+
} else {
80+
$secretValue = '';
81+
}
7782
}
7883

7984
return [

src/SecretManager/Providers/Vault.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ protected static function fetchSecretsRecursively(VaultClient $client, string $p
128128
}
129129
}
130130

131-
protected static function addSecretsFromData(Collection $collection, string $path, array $data): void
131+
protected static function addSecretsFromData(Collection $collection, string $path, array $data, int $depth = 0): void
132132
{
133+
if ($depth >= self::MAX_RECURSION_DEPTH) {
134+
return;
135+
}
136+
133137
foreach ($data as $key => $value) {
134138
$secretPath = $path.'.'.$key;
135139

@@ -139,7 +143,7 @@ protected static function addSecretsFromData(Collection $collection, string $pat
139143
// Include numeric values as strings
140144
$collection->push(new Secret($secretPath, (string) $value));
141145
} elseif (is_array($value)) {
142-
self::addSecretsFromData($collection, $secretPath, $value);
146+
self::addSecretsFromData($collection, $secretPath, $value, $depth + 1);
143147
}
144148
// Skip booleans and null values
145149
}

src/SecretManager/SecretManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class SecretManager
1010
{
11-
public static function getSecrets($provider): Collection
11+
public static function getSecrets(string $provider): Collection
1212
{
1313
$providerKey = self::getProviderKey($provider);
1414

0 commit comments

Comments
 (0)