Skip to content

Commit 50538c6

Browse files
author
Sergey Shvets
committed
MAGETWO-96983: M2.3 – Sodium crypto adapter errors on unexpected input
1 parent 2a65cc6 commit 50538c6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/internal/Magento/Framework/Encryption/Adapter/SodiumChachaIetf.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ public function decrypt(string $data): string
5959
$nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
6060
$payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');
6161

62-
$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
63-
$payload,
64-
$nonce,
65-
$nonce,
66-
$this->key
67-
);
62+
try {
63+
$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
64+
$payload,
65+
$nonce,
66+
$nonce,
67+
$this->key
68+
);
69+
} catch (\SodiumException $e) {
70+
$plainText = '';
71+
}
6872

6973
return $plainText !== false ? $plainText : '';
7074
}

0 commit comments

Comments
 (0)