V5 missing .env file

Self-Hosted user here

I thought I had a backup of the APP_KEY, but I’m suspecting that when we migrated from v4 to v5 a new key was inadvertently set. Unfortunately I have not found any other key. I’ve also preserved an image of the old host, but the old .env had already been wiped (will try ext4magic to try and recover, but I’m not hopeful at this point). Now for the question:

I’m getting the Invalid Mac exception in the laravel logs, preventing access at this time. In reading, I see mention of clearing payment gateway configs from the database. My question is a matter of confirming which tables in the database. Some older posts mention account_gateways, but do not see that in the v5 database. Can anyone provide further clarification for v5? Am I totally hosed here?

We only used stripe with this instance, no other linked bank/payment accounts.

Hi,

@david can you please advise?

Assuming you are on v5, you’ll want to clear the config column in the company_gateways table

That should be all.

So i tried the following:

  • ALTER/MODIFY config column to allow NULL and then NULLed the column

  • DROP config FROM company_gateways then ADD config to company_gateways as medtext NOT NULL.

  • DROP config FROM company_gateways without re-adding

I restored the DB in between desired change attempts and executed php artisan optimize before any login attempts. While i’m still not able to access my instance, the error in laravel.log has changed from Invalid mac to Invalid Payload, regardless of which above change was made:

********* PRIOR TO MODIFYING DATABASE***********
[2022-02-13 19:07:12] production.ERROR: The MAC is invalid. {“userId”:1,“exception”:"[object] (Illuminate\Contracts\Encryption\DecryptException(code: 0): The MAC is invalid. at /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:227)
[stacktrace]
#0 /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(158): Illuminate\Encryption\Encrypter->getJsonPayload()
#1 /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(374): Illuminate\Encryption\Encrypter->decrypt()
#2 /var/www/foo.bar.com/app/Models/CompanyGateway.php(170): decrypt()

, , ,
********* AFTER MODIFYING DATABASE***********

[2022-02-13 19:24:59] production.ERROR: The payload is invalid. {“userId”:1,“exception”:"[object] (Illuminate\Contracts\Encryption\DecryptException(code: 0): The payload is invalid. at /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:223)
[stacktrace]
#0 /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(158): Illuminate\Encryption\Encrypter->getJsonPayload()
#1 /var/www/foo.bar.com/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(374): Illuminate\Encryption\Encrypter->decrypt()
#2 /var/www/foo.bar.com/app/Models/CompanyGateway.php(165): decrypt()
#3 /var/www/foo.bar.com/app/Models/CompanyGateway.php(251): App\Models\CompanyGateway->getConfig()

. . .

full laravel log: https://pastebin.com/raw/i7zQHZpk

ah, you may need to truncate the table then unfortunately.

Thanks. Truncating the ninjadb.company_gateways table worked in the end.

For posterity’s sake:

ninjadb.company_gateways has a Foreign Key reference to ninjadb.payments which in turn has a Foreign Key reference to ninjadb.payment_hashes

In addition to TRUNCATE company_gateways, i also wanted clear out any related foreign keys/tables. In the end this worked:

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE company gateways;
SET FOREIGN_KEY_CHECKS = 1;

1 Like