Issue with PHP 8.3 and v5.10

Hi,

I tried to run Invoice Ninja v5.10.24 on PHP 8.3 and I get a “Server error” every time I try to login.
Here is the laravel.log file:


[2024-08-18 09:34:47] production.ERROR: unserialize(): Extra data starting at offset 314 of 315 bytes {"userId":1,"exception":"[object] (ErrorException(code: 0): unserialize(): Extra data starting at offset 314 of 315 bytes at *********************/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:196)
[stacktrace]
#0 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 *********************/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(196): unserialize()
#3 *********************/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(398): Illuminate\\Encryption\\Encrypter->decrypt()
#4 *********************/app/Models/CompanyGateway.php(263): decrypt()
#5 *********************/app/Transformers/CompanyGatewayTransformer.php(70): App\\Models\\CompanyGateway->getConfigTransformed()
#6 *********************/vendor/league/fractal/src/Scope.php(357): App\\Transformers\\CompanyGatewayTransformer->transform()
#7 *********************/vendor/league/fractal/src/Scope.php(295): League\\Fractal\\Scope->fireTransformer()
#8 *********************/vendor/league/fractal/src/Scope.php(173): League\\Fractal\\Scope->executeResourceTransformers()
#9 *********************/vendor/league/fractal/src/TransformerAbstract.php(134): League\\Fractal\\Scope->toArray()
#10 *********************/vendor/league/fractal/src/TransformerAbstract.php(106): League\\Fractal\\TransformerAbstract->includeResourceIfAvailable()
#11 *********************/vendor/league/fractal/src/Scope.php(383): League\\Fractal\\TransformerAbstract->processIncludedResources()
#12 *********************/vendor/league/fractal/src/Scope.php(361): League\\Fractal\\Scope->fireIncludedTransformers()
#13 *********************/vendor/league/fractal/src/Scope.php(292): League\\Fractal\\Scope->fireTransformer()
#14 *********************/vendor/league/fractal/src/Scope.php(173): League\\Fractal\\Scope->executeResourceTransformers()
#15 *********************/vendor/league/fractal/src/TransformerAbstract.php(134): League\\Fractal\\Scope->toArray()
#16 *********************/vendor/league/fractal/src/TransformerAbstract.php(106): League\\Fractal\\TransformerAbstract->includeResourceIfAvailable()
#17 *********************/vendor/league/fractal/src/Scope.php(383): League\\Fractal\\TransformerAbstract->processIncludedResources()
#18 *********************/vendor/league/fractal/src/Scope.php(361): League\\Fractal\\Scope->fireIncludedTransformers()
#19 *********************/vendor/league/fractal/src/Scope.php(295): League\\Fractal\\Scope->fireTransformer()
#20 *********************/vendor/league/fractal/src/Scope.php(173): League\\Fractal\\Scope->executeResourceTransformers()
#21 *********************/app/Http/Controllers/BaseController.php(898): League\\Fractal\\Scope->toArray()
#22 *********************/app/Http/Controllers/Auth/LoginController.php(160): App\\Http\\Controllers\\BaseController->timeConstrainedResponse()
#23 *********************/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\Auth\\LoginController->apiLogin()
#24 *********************/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction()
#25 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(21): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#26 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingRoutingDispatcher.php(18): Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing->Sentry\\Laravel\\Tracing\\Routing\\{closure}()
#27 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(20): Sentry\\Laravel\\Tracing\\Routing\\TracingRoutingDispatcher->wrapRouteDispatch()
#28 *********************/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing->dispatch()
#29 *********************/vendor/laravel/framework/src/Illuminate/Routing/Route.php(206): Illuminate\\Routing\\Route->runController()
#30 *********************/vendor/laravel/framework/src/Illuminate/Routing/Router.php(808): Illuminate\\Routing\\Route->run()
#31 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#32 *********************/app/Http/Middleware/ApiSecretCheck.php(31): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\ApiSecretCheck->handle()
#34 *********************/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(124): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 *********************/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(89): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter()
#36 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle()
#37 *********************/app/Http/Middleware/QueryLogging.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#38 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\QueryLogging->handle()
#39 *********************/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(51): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#40 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#41 *********************/app/Http/Middleware/SetEmailDb.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\SetEmailDb->handle()
#43 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#44 *********************/vendor/laravel/framework/src/Illuminate/Routing/Router.php(807): Illuminate\\Pipeline\\Pipeline->then()
#45 *********************/vendor/laravel/framework/src/Illuminate/Routing/Router.php(786): Illuminate\\Routing\\Router->runRouteWithinStack()
#46 *********************/vendor/laravel/framework/src/Illuminate/Routing/Router.php(750): Illuminate\\Routing\\Router->runRoute()
#47 *********************/vendor/laravel/framework/src/Illuminate/Routing/Router.php(739): Illuminate\\Routing\\Router->dispatchToRoute()
#48 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(201): Illuminate\\Routing\\Router->dispatch()
#49 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#50 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/FlushEventsMiddleware.php(13): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#51 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\FlushEventsMiddleware->handle()
#52 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\SetRequestIpMiddleware->handle()
#54 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(31): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Http\\SetRequestMiddleware->handle()
#56 *********************/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#58 *********************/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#60 *********************/app/Http/Middleware/Cors.php(24): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#61 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\Cors->handle()
#62 *********************/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#63 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#64 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#65 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#66 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#67 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#68 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#69 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#70 *********************/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#71 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#72 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#73 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#74 *********************/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(79): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#75 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Sentry\\Laravel\\Tracing\\Middleware->handle()
#76 *********************/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#77 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Pipeline\\Pipeline->then()
#78 *********************/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#79 *********************/public/index.php(56): Illuminate\\Foundation\\Http\\Kernel->handle()
#80 {main}
"} 

regards

Hi,

It’s the first time I’ve seen this error, maybe the suggestions here will help:

Thanks.
But I already tried to clear Laravel optimization without any success :worried:.

And regenerating an App Key is not an option due to the fact my InvoiceNinja instance runs from many years and I can’t loose any data.

Does changing back to PHP 8.2 resolve the error?

Yes it does.
Switching back to PHP 8.2 works fine.

I’m not sure, you may want to create an issue or discussion on GitHub

Thanks.
I just opened an issue on the github repository : Issue with PHP 8.3 and v5.10 · Issue #9915 · invoiceninja/invoiceninja · GitHub

1 Like

This is interesting. I’ve been using PHP8.3 since May and have not had any problems. I’m not completely sure the error is specifically related to PHP8.3. Especially, considering the link from @hillel is nearly 7 years old.

I could be wrong, but I did not think that regenerating the app key causes any data loss. I’ve done so several times and without any problems. Maybe @david can confirm whether this happens or not with regenerating a new key.

I’m not sure changing the key is a good idea, I believe it will cause the two-way encryption in the app (ie. gateway credentials) to fail.

2 Likes

Hi @northhill ,

Interesting. Did you use PHP 8.3 at first start on your InvoiceNinja instance or did you upgrade it later ?
On my case I used PHP 8.2 when installed InvoiceNinja and used it many months/years. The error occured on switching from PHP 8.2 to PHP 8.3.

Regarding the app key regeneration, as @hillel mentionned, changing the key on a running installation will broke the 2-way encryption as your config will have a new key that wasn’t the one used to encrypt data already stored in your database.

No problem, as I shared, I wasn’t sure if it did that or not.

@Gaetan To answer your question. My original installation, almost 2 years ago, was using PHP8.1 and I upgraded to 8.3 in May.

I can confirm, both from my own experience and from assisting others. Upgrading to 8.3 does cause some minor breakages due to packaging changes. Some modules that had previously been packaged separately were incorporated into other packages. I find i had to go through the list of PHP dependencies and do a little searching to satisfy them all to fix my broken system.

Thanks for the details :smiling_face:.
I think I’ll wait for the official support.

Official support or not, the situation will still be the same. The issue is not with InvoiceNinja, it relates to changes made by the PHP packagers and will still remain even when the supported version moves to 8.3.

It’s not difficult to fix. Please ask if you have questions.

@Gaetan I have created an upgrade guide if that is of any assistance to you.

I’ve also upgraded to php8.3 w/ no problems (once I satisfied all dependencies)

Have you tried running php artisan optimize?
Have you tried clearing your browser cache + cookies?
How are you logging in? (email + password? social? 2FA enabled?)

Do you have any payment gateways configured?

Thanks a lot. I had a look and there is nothing more than what I already did :frowning:

Hi @thirstyice ,

I tried to run php artisan optimize and also php artisan optimize:clear. I also tried to clear my browser data (cache, cookies). I’m logging with email + password + 2FA. And yes I have payments gateways confgured.

The issue is from decrypting data already stored encrypted in the DB.

I also tried to generate a new encryption key (saved the current one before :smiley: ) but I still have the same error when running with PHP 8.3 :frowning:

After multiple tests and debug I finally made it work by removing and reconfiguring all my payment gateways.

I put the server on PHP 8.2, login, remove all gateways, remove gateways entries from DB directly then switch server to PHP 8.3, login, reconfigure all my gateways.

Don’t know why I had to do this but it’s now working on PHP 8.3 :smiley: :partying_face:

2 Likes

I’m not sure why you had to either. I have both a production version and a testing version running in two different VMs and didn’t have problems upgrading either of the to php8.3. However, I don’t have any payment gateways setup on either instance.