Skip to content
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

Merge $_ENV into $_SERVER earlier in phprouter file #333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kick-the-bucket
Copy link

Tried running a non-symfony application with the symfony-cli local server and was puzzled why it could not detect that it's running on https. Apparently 'https' => 'on' was only set in $_ENV (that's done with require $envFile;), but not in $_SERVER, where PHP applications usually look for that parameter.

This was because the $_SERVER = array_merge($_SERVER, $_ENV); line was never executed, because the router exited a few lines before it with return false;.

Also fixed a few whitespace and indentation inconsistencies.

@tucksaun
Copy link
Contributor

PHP documents the presence of HTTPS within $_SERVER (see https://www.php.net/manual/en/reserved.variables.server.php), not $_ENV.
And I believe most of the literature online also references $_SERVER.

So I think we are within spec here, your app should probably be fixed instead.

@tucksaun
Copy link
Contributor

Also I don't quite understand how your application could even be reached if the router exited before the call to array_merge 🤔

@kick-the-bucket
Copy link
Author

After that return false; it just continues to my index.php, not really sure how that works, maybe the router file is set as an auto_prepend_file 🤔

@kick-the-bucket
Copy link
Author

PHP documents the presence of HTTPS within $_SERVER (see https://www.php.net/manual/en/reserved.variables.server.php), not $_ENV.
And I believe most of the literature online also references $_SERVER.

The problem is that the code in the $envFile only sets $_ENV['https'] = 'on', but nothing on the $_SERVER and that is why the merge is needed in the first place

@tucksaun
Copy link
Contributor

tucksaun commented Nov 3, 2023

Oh ok sorry I got that the wrong way.

So I believe the change might makes sense, but at the same time this is the location this merge has been present for quite a long time in Symfony so I'm not entirely sure of the consequences this could have...

Another approach would be to change how we generate the env for the PHP CLI server to make sure the right keys are populated for _SERVER, something along those lines: https://github.com/symfony-cli/symfony-cli/compare/main...tucksaun:symfonycli:fix-generate-server-superglobal-cli-server?expand=1

wdyt @fabpot ?

@kick-the-bucket
Copy link
Author

@tucksaun I actually like your version, no point in setting the variables on $_ENV which are supposed to be in $_SERVER anyways 👍

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

Successfully merging this pull request may close these issues.

None yet

3 participants