@@ -54,6 +54,9 @@ public function listSecrets(): array
5454 do {
5555 $ response = $ this ->httpClient ->get ($ url );
5656 $ data = json_decode ($ response ->getBody ()->getContents (), true );
57+ if (json_last_error () !== JSON_ERROR_NONE ) {
58+ throw new SecretProviderException ('Invalid JSON response from Azure Key Vault: ' .json_last_error_msg ());
59+ }
5760
5861 foreach ($ data ['value ' ] ?? [] as $ secret ) {
5962 $ secrets [] = [
@@ -87,6 +90,9 @@ public function getSecretValue(string $name, string $version = ''): array
8790 $ path = $ version ? "/secrets/ {$ name }/ {$ version }" : "/secrets/ {$ name }" ;
8891 $ response = $ this ->httpClient ->get ($ path .'?api-version= ' .self ::API_VERSION );
8992 $ data = json_decode ($ response ->getBody ()->getContents (), true );
93+ if (json_last_error () !== JSON_ERROR_NONE ) {
94+ throw new SecretProviderException ('Invalid JSON response from Azure Key Vault: ' .json_last_error_msg ());
95+ }
9096
9197 // Extract secret name from ID URL: https://vault.azure.net/secrets/{name}/{version}
9298 $ secretName = $ name ;
@@ -203,6 +209,9 @@ protected function getManagedIdentityToken(): string
203209 ]);
204210
205211 $ data = json_decode ($ response ->getBody ()->getContents (), true );
212+ if (json_last_error () !== JSON_ERROR_NONE ) {
213+ throw new SecretProviderException ('Invalid JSON response from Azure Managed Identity endpoint: ' .json_last_error_msg ());
214+ }
206215 if (! isset ($ data ['access_token ' ])) {
207216 throw new SecretProviderException ('Invalid response from Azure Managed Identity endpoint: missing access_token ' );
208217 }
@@ -221,6 +230,9 @@ protected function getManagedIdentityToken(): string
221230 ]);
222231
223232 $ data = json_decode ($ response ->getBody ()->getContents (), true );
233+ if (json_last_error () !== JSON_ERROR_NONE ) {
234+ throw new SecretProviderException ('Invalid JSON response from Azure IMDS endpoint: ' .json_last_error_msg ());
235+ }
224236 if (! isset ($ data ['access_token ' ])) {
225237 throw new SecretProviderException ('Invalid response from Azure IMDS endpoint: missing access_token ' );
226238 }
@@ -250,6 +262,9 @@ protected function getClientCredentialsToken(string $tenantId, string $clientId,
250262 ]);
251263
252264 $ data = json_decode ($ response ->getBody ()->getContents (), true );
265+ if (json_last_error () !== JSON_ERROR_NONE ) {
266+ throw new SecretProviderException ('Invalid JSON response from Azure OAuth endpoint: ' .json_last_error_msg ());
267+ }
253268 if (! isset ($ data ['access_token ' ])) {
254269 throw new SecretProviderException ('Invalid response from Azure OAuth endpoint: missing access_token ' );
255270 }
0 commit comments