File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
src/Illuminate/Encryption Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -206,9 +206,8 @@ protected function getJsonPayload($payload)
206206 */
207207 protected function validPayload ($ payload )
208208 {
209- return is_array ($ payload ) && isset (
210- $ payload ['iv ' ], $ payload ['value ' ], $ payload ['mac ' ]
211- );
209+ return is_array ($ payload ) && isset ($ payload ['iv ' ], $ payload ['value ' ], $ payload ['mac ' ]) &&
210+ strlen (base64_decode ($ payload ['iv ' ], true )) === openssl_cipher_iv_length ($ this ->cipher );
212211 }
213212
214213 /**
Original file line number Diff line number Diff line change @@ -102,4 +102,19 @@ public function testExceptionThrownWithDifferentKey()
102102 $ b = new Encrypter (str_repeat ('b ' , 16 ));
103103 $ b ->decrypt ($ a ->encrypt ('baz ' ));
104104 }
105+
106+ /**
107+ * @expectedException \Illuminate\Contracts\Encryption\DecryptException
108+ * @expectedExceptionMessage The payload is invalid.
109+ */
110+ public function testExceptionThrownWhenIvIsTooLong ()
111+ {
112+ $ e = new Encrypter (str_repeat ('a ' , 16 ));
113+ $ payload = $ e ->encrypt ('foo ' );
114+ $ data = json_decode (base64_decode ($ payload ), true );
115+ $ data ['iv ' ] .= $ data ['value ' ][0 ];
116+ $ data ['value ' ] = substr ($ data ['value ' ], 1 );
117+ $ modified_payload = base64_encode (json_encode ($ data ));
118+ $ e ->decrypt ($ modified_payload );
119+ }
105120}
You can’t perform that action at this time.
0 commit comments