laravel 5.5.39 升级到 5.5.45 出现 cookie 序列化异常问题的解决
把项目里的 laravel 5.5.39 升级到 5.5.45 后,出现如下报错:
ErrorException
openssl_encrypt() expects parameter 1 to be string, array given
vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php in handleError at line 91
vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php in handleError at line 34
vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php in openssl_encrypt
vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php in encrypt at line 91
vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php in encrypt at line 139
vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php in handle at line 66
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in then at line 102
vendor/laravel/framework/src/Illuminate/Routing/Router.php in runRouteWithinStack at line 660
vendor/laravel/framework/src/Illuminate/Routing/Router.php in runRoute at line 635
vendor/laravel/framework/src/Illuminate/Routing/Router.php in dispatchToRoute at line 601
vendor/laravel/framework/src/Illuminate/Routing/Router.php in dispatch at line 590
vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php in Illuminate\Foundation\Http\{closure} at line 176
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 30
vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php in handle at line 58
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/fideloper/proxy/src/TrustProxies.php in handle at line 56
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php in handle at line 30
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php in handle at line 30
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php in handle at line 27
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php in handle at line 46
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in Illuminate\Pipeline\{closure} at line 149
vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php in Illuminate\Routing\{closure} at line 53
vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php in then at line 102
vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php in sendRequestThroughRouter at line 151
vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php in handle at line 116
public/index.php at line 55
观察上面的堆栈记录,并且打断点排查,终于确定是由于 Cookie 序列化加密导致的问题。
查阅 laravel 5.5 upgrade 官方文档,laravel 5.5.42 版开始为了防止 PHP 对象的序列化/反序列化漏洞被利用,不再对 Cookie 值进行自动的序列化和反序列化处理。
举个栗子:
\Cookie::queue('user', ['id' => 1, 'name' => 'admin'], 720, '/')
Laravel 更新到 v5.5.42 后,因为 Laravel 不再自动对 Cookie 值 ['id' => 1, 'name' => 'admin'] 进行序列化处理,而 openssl_encrypt ( string $data ... ) 只能加密字符串数据,这个时候程序就会抛出错误:openssl_encrypt() expects parameter 1 to be string, array given。
解决方法:
- 新版里面在中间件 App\Http\Middleware\EncryptCookies 新增静态属性 $serialize,当设置为 true 时可开启 Cookie 值的自动序列化和反序列化处理。
/**
* Indicates if cookies should be serialized.
*
* @var bool
*/
protected static $serialize = true;
- 【推荐】将 Cookie 值使用 JSON 函数编码成字符串后再进行存储(获取 Cookie 值后需调用 json_decode 函数进行解码)。
\Cookie::queue('user', json_encode(['id' => 1, 'name' => 'admin']), 720, '/');
首发于知乎专栏《PHP和Laravel学习》:https://zhuanlan.zhihu.com/p/60861964
laravel 5.5.39 升级到 5.5.45 出现 cookie 序列化异常问题的解决的更多相关文章
- spark升级后 集成hbase-1.0.0-cdh5.4.5异常
.具体场景如下: spark1.6 升级 spark2.2 后 分析查询hbase 数据报异常: 具体错误如下: ERROR TableInputFormat: java.io ...
- 4412开发板升级4.2之后改了logo开机后屏幕闪解决办法
荣品4412开发板升级到4.2请注意增加虚拟机内存. 问:荣品4412开发板升级到Android4.2之后,改了logo.4412板子开机后,过一会屏幕就一闪一闪,是什么原因? Android4.2编 ...
- 排错-升级Exchange 2013 CU22后程序名称显示异常
近期在按需更新Exchange 2013 CU22补丁以便解决Microsoft Exchange Server ADV190007 Guidance for "PrivExchange&q ...
- 【原创】大叔问题定位分享(28)openssh升级到7.4之后ssh跳转异常
服务器集群之间忽然ssh跳转不通 # ssh 192.168.0.1The authenticity of host '192.168.0.1 (192.168.0.1)' can't be esta ...
- osx升级到10.10后,使用pod install报错解决的方法
先看下网上的解决方法例如以下: 先依照这个文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概过程例如以下: Open Xcode ...
- android升级adt和sdk之后无法识别SDK Location的一个解决方式
我把android的adt和sdk从4.0升级到4.2,发现eclipse的android设置里面原来列出的各种api level的platform消失了,而且无法新建android工程.而且检查过了 ...
- 升级了git版本后git clone报ssl错误的解决方法
由于升级了git版本,git clone 的时候报了如下的错误 fatal: unable to access 'https://github.com/open-falcon/falcon-plus. ...
- Win10升级后VMWare内的系统连不了网如何解决
一些既想要体验新系统又不愿放弃旧系统的用户,一般都会在电脑中安装VMWare虚拟机.不过,他们偶尔也会遇到这样一个问题,当win10系统自动升级后,VMWare虚拟机内的系统就会出现无法连接网络的情况 ...
- 当node升级后导致webpack打包出错,node-saas出问题的解决办法
报错信息如下: ERROR in ./node_modules/_extract-text-webpack-plugin@3.0.2@extract-text-webpack-plugin/dist/ ...
随机推荐
- Vue中使用iconfont
学习博客:https://www.imooc.com/article/33597?block_id=tuijian_wz
- 【Spring MVC】Properties文件的加载
[Spring MVC]Properties文件的加载 转载:https://www.cnblogs.com/yangchongxing/p/10726885.html 参考:https://java ...
- where和having区别
壹: where后面不能跟聚合函数(sum.avg.count.max.min) having后面可以跟 贰: where和having都能用: select goods_price,goods_na ...
- React一键复制
如题,我们怎么在React或者其他的框架中实现一键复制呢,实际上实现一键复制的代码与框架无关,因为他是用的是原生的API,下面我们用React来实现一下 效果: 核心代码: 直接将红框处改为需要 ...
- So Easy - 在Linux服务器上部署 .NET Core App
.NET Core 是微软提供的免费.跨平台和开源的开发框架,可以构建桌面应用程序.移动端应用程序.网络应用程序.物联网应用程序和游戏应用程序等.如果你是 Windows 平台下的 dotnet 开发 ...
- PHP中抽象类和接口的区别
抽象类 抽象类无法被实例化,它的作用是为所有继承自它的类定义(或部分实现)接口. 使用 abstract 关键字定义抽象类. 可以像在普通类中那样在抽象类中创建方法和属性,在大多数情况下,一个抽象类至 ...
- 一个小工具帮你搞定实时监控Nginx服务器
Linux运维工程师的首要职责就是保证业务7 x 24小时稳定的运行,监控Web服务器对于查看网站上发生的情况至关重要.关注最多的便是日志变动,查看实时日志文件变动大家第一反应应该是'tail -f ...
- python获取淘宝登入cookies
重点:去新浪微博登入接口登入 一.代码 # coding=utf-8 import requests from selenium.webdriver.common.by import By from ...
- JS---获取元素计算后的样式属性值 (getComputedStyle)---兼容函数
获取计算后的样式属性----获取一个元素任意一个样式属性值 获取元素距离左边位置的值 会有如下兼容性问题: my$("btn").onclick = function () { / ...
- 使用react-app-rewired和customize-cra对默认webpack自定义配置
最近在学习react框架,之前一直都是用vue 开发,知道在vue 中知道如何配置一下相关的webpack 有助于开发,学react 过程中,我也在想这些该怎么配置啊,所以就有这篇文章. 这篇文章主要 ...