@@ -25,6 +25,15 @@ class EncryptCookies
2525 */
2626 protected $ except = [];
2727
28+ /**
29+ * The cookies that should not be serialized.
30+ *
31+ * @var array
32+ */
33+ protected $ serialization = [
34+ 'XSRF-TOKEN ' => false ,
35+ ];
36+
2837 /**
2938 * Create a new CookieGuard instance.
3039 *
@@ -73,7 +82,7 @@ protected function decrypt(Request $request)
7382 }
7483
7584 try {
76- $ request ->cookies ->set ($ key , $ this ->decryptCookie ($ cookie ));
85+ $ request ->cookies ->set ($ key , $ this ->decryptCookie ($ key , $ cookie ));
7786 } catch (DecryptException $ e ) {
7887 $ request ->cookies ->set ($ key , null );
7988 }
@@ -85,14 +94,15 @@ protected function decrypt(Request $request)
8594 /**
8695 * Decrypt the given cookie and return the value.
8796 *
97+ * @param string $name
8898 * @param string|array $cookie
8999 * @return string|array
90100 */
91- protected function decryptCookie ($ cookie )
101+ protected function decryptCookie ($ name , $ cookie )
92102 {
93103 return is_array ($ cookie )
94104 ? $ this ->decryptArray ($ cookie )
95- : $ this ->encrypter ->decrypt ($ cookie );
105+ : $ this ->encrypter ->decrypt ($ cookie, $ this -> serialization [ $ name ] ?? true );
96106 }
97107
98108 /**
@@ -107,7 +117,7 @@ protected function decryptArray(array $cookie)
107117
108118 foreach ($ cookie as $ key => $ value ) {
109119 if (is_string ($ value )) {
110- $ decrypted [$ key ] = $ this ->encrypter ->decrypt ($ value );
120+ $ decrypted [$ key ] = $ this ->encrypter ->decrypt ($ value, $ this -> serialization [ $ key ] ?? true );
111121 }
112122 }
113123
@@ -127,8 +137,10 @@ protected function encrypt(Response $response)
127137 continue ;
128138 }
129139
140+ $ serialize = $ this ->serialization [$ cookie ->getName ()] ?? true ;
141+
130142 $ response ->headers ->setCookie ($ this ->duplicate (
131- $ cookie , $ this ->encrypter ->encrypt ($ cookie ->getValue ())
143+ $ cookie , $ this ->encrypter ->encrypt ($ cookie ->getValue (), $ serialize )
132144 ));
133145 }
134146
0 commit comments