fix(auth): handle missing LDAP env vars in external auth #3032 #3079
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3032
Description
Solution Applied
I modified the auth_external_check() function to:
Check for environment variable existence before accessing them using isset()
Handle missing variables gracefully by setting them to null or empty strings
Apply the same pattern to all three environment variables: user, email, and description
Changes
// Before (problematic):
$EXT_AUTH_USER = $GLOBALS['_SERVER']["{$EXT_AUTH_USER_KW}"];
// After (fixed):
$EXT_AUTH_USER = null;
if (isset($GLOBALS['_SERVER']["{$EXT_AUTH_USER_KW}"])) {
$EXT_AUTH_USER = $GLOBALS['_SERVER']["{$EXT_AUTH_USER_KW}"];
}
How to test
Describe the steps required to test the changes proposed in the pull request.
✅ No PHP warnings when environment variables are missing
✅ Function returns false correctly when variables are missing
✅ Function works correctly when environment variables are present
✅ No syntax errors in the modified code
Please consider using the closing keyword if the pull request is proposed to
fix an issue already created in the repository
(https://help.github.com/articles/closing-issues-using-keywords/)