Skip to content

[5.x]: Invalid token "An internal server error occurred." instead of 400 bad request #16630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeroenlammerts opened this issue Feb 4, 2025 · 2 comments
Assignees
Labels

Comments

@jeroenlammerts
Copy link
Contributor

What happened?

Description

When having an invalid token in the url https://craftcms.com/?token=! you get a 500 server error in production mode instead of 400 bad request.

After debugging vendor/yiisoft/yii2/base/ErrorHandler.php:164

 catch (\Throwable $e) {
     echo $e->getMessage() . "\n";
     echo $e->getTraceAsString() . "\n";
     exit;
     // additional check for \Throwable introduced in PHP 7
     $this->handleFallbackExceptionMessage($e, $exception);
}

I get the error Typed property craft\web\Application::$edition must not be accessed before initialization
It has something to do with vendor/craftcms/cms/src/base/ApplicationTrait.php _preInit() where the edition is set after $this->getLog();
Setting the edition before $this->getLog(); looks like it solved the problem.

Steps to reproduce

  1. Set CRAFT_ENVIRONMENT=production in .env file
  2. Go to your site https://mysite.test/?token=!

Expected behavior

A styled page saying
Bad Request
Invalid token

Actual behavior

In dev mode you get a HTTP 400 – Bad Request
In production mode you get an unstyled "An internal server error occurred." 500 error

Craft CMS version

5.6.4

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Fixed for the next release.

@brandonkelly
Copy link
Member

Craft 5.6.5 is out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants