Refactor environment loading and handling for FrankenPHP + add more s…#397
Refactor environment loading and handling for FrankenPHP + add more s…#397tudor-timcu merged 8 commits intomainfrom
Conversation
…afe-guards for AIKIDO_DISABLE
| @@ -185,12 +190,16 @@ bool GetBoolFromString(const std::string& env, bool default_value) { | |||
| return default_value; | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Let's rename this function to GetEnvBoolWithAllGetters or smth like this so it's more explicit what it does. Can remove the comment from the Includes.h after that.
| std::string sapiName = sapi_module.name; | ||
|
|
||
| if (sapiName == "frankenphp") { | ||
| if (GetEnvBoolWithAllGetters("FRANKENPHP_WORKER", false)) { |
There was a problem hiding this comment.
Calling GetEnvBoolWithAllGetters("FRANKENPHP_WORKER", ...) here can dereference AIKIDO_GLOBAL(server) via GetFrankenEnvVariable before server is initialized; guard AIKIDO_GLOBAL(server) or delay this check.
Details
✨ AI Reasoning
The code attempts to detect a FrankenPHP warm-up request by calling GetEnvBoolWithAllGetters("FRANKENPHP_WORKER", false) early in RequestProcessor::RequestInit. GetEnvBoolWithAllGetters uses the complete set of getters including GetFrankenEnvVariable, which calls AIKIDO_GLOBAL(server).GetVar. Because the FRANKENPHP_WORKER check was moved earlier in RequestInit (before environment/server-related initialization and before LoadEnvironment/LoadLaravelEnvFile), AIKIDO_GLOBAL(server) may not be initialized yet, leading to dereferencing an uninitialized or null server object and causing a segmentation fault. This regression was introduced by moving the FRANKENPHP_WORKER check to earlier lines and by using the "all getters" helper at that point.
🔧 How do I fix it?
Add null checks before dereferencing pointers, validate array bounds before access, avoid using pointers after free/delete, don't write to string literals, and prefer smart pointers in modern C++.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
…afe-guards for AIKIDO_DISABLE
Summary by Aikido
⚡ Enhancements
🔧 Refactors
More info