Skip to content

Commit a658f4d

Browse files
mdeboerSpomky
authored andcommitted
Fix JWE serialiser crashing on decoding invalid JWE (#186)
The JWE serialiser crashes when attempting to decode invalid data or even a JWS. The serialiser returns null but checkData does not accept a null value and throws an exception.
1 parent 44e3330 commit a658f4d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Component/Encryption/Serializer/JSONFlattenedSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public function unserialize(string $input): JWE
8888
);
8989
}
9090

91-
private function checkData(array $data): void
91+
private function checkData(?array $data): void
9292
{
93-
if (!isset($data['ciphertext']) || isset($data['recipients'])) {
93+
if ($data === null || !isset($data['ciphertext']) || isset($data['recipients'])) {
9494
throw new InvalidArgumentException('Unsupported input.');
9595
}
9696
}

src/Component/Encryption/Serializer/JSONGeneralSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public function unserialize(string $input): JWE
9797
);
9898
}
9999

100-
private function checkData(array $data): void
100+
private function checkData(?array $data): void
101101
{
102-
if (!isset($data['ciphertext']) || !isset($data['recipients'])) {
102+
if ($data === null || !isset($data['ciphertext']) || !isset($data['recipients'])) {
103103
throw new InvalidArgumentException('Unsupported input.');
104104
}
105105
}

0 commit comments

Comments
 (0)