laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.69k stars 11.05k forks source link

EncryptionServiceprovider->key(array $config): APP_KEY sometimes null #52596

Closed susanne99 closed 3 months ago

susanne99 commented 3 months ago

Laravel Version

11.19.0

PHP Version

8.3.10

Database Driver & Version

No response

Description

(hint: Don't move it to discussion area, it is a BUG !!!!!!!!!!!!!!)

I use Laravel 11 as the backend for the middleware. Frontend is a SPA VUE application. For authentication I use Laravel Sanctum. Problem description: it happens sometimes, during the app runs, that the "appkey" is not defined That's wrong, otherwise it would never work. However, I noticed that in the class "EncryptionServiceProvider" the method "key" with "$config" as a parameter, where the "key" member is really "null". The interesting thing is that all other .env (APP) entries are there, only the "key" entry is null !!!! What's going on - unfortunately this makes the application completely unstable and unusable

protected function key(array $config) { return tap($config['key'], function ($key) { if (empty($key)) { throw new MissingAppKeyException; } }); }

**here the code where th error occurs: file: \vendor\laravel\framework\src\Illuminate\Encryption\EncryptionServiceProvider.php

` protected function registerEncrypter() { $this->app->singleton('encrypter', function ($app) { $config = $app->make('config')->get('app');

    return (new Encrypter($this->parseKey($config), $config['cipher']))
        ->previousKeys(array_map(
            fn ($key) => $this->parseKey(['key' => $key]),
            $config['previous_keys'] ?? []
        ));
});

}`** after this command $config = $app->make('config')->get('app'); the $config['key'] is null or empty

Important Hint: $config['key'] is not always null, and it is the only only member of config that is destroyed !!!!!!!!!!!!!!!!!

laravel runs on windows 10 with latest XAMPP

Steps To Reproduce

sorry, if i could reproduce the error, then can i fix it

driesvints commented 3 months ago

This is a support question and not a bug. Please don't re-open closed issues and attempt a support channel instead:

susanne99 commented 2 months ago

It's a mistake, believe it or not. No matter, PHP is not suitable for productive use anyway. You're not harming me - I'm just laughing