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

FastCGI: SCRIPT_NAME must have leading slash (or be empty) #3569

Closed
sorbits opened this issue Jul 11, 2020 · 2 comments · Fixed by #3570
Closed

FastCGI: SCRIPT_NAME must have leading slash (or be empty) #3569

sorbits opened this issue Jul 11, 2020 · 2 comments · Fixed by #3570
Labels
bug 🐞 Something isn't working
Milestone

Comments

@sorbits
Copy link

sorbits commented Jul 11, 2020

I have /index.php that serves requests for non-existing files (custom router).

When requesting / then SCRIPT_NAME is correctly set to /index.php, but when requesting e.g. /about then SCRIPT_NAME is index.php (notice that there is no leading slash).

According to RFC3875 then SCRIPT_NAME must either be empty, or have a leading slash:

The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded)
which could identify the CGI script (rather than the script's
output).  The syntax is the same as for PATH_INFO (section 4.1.5)

   SCRIPT_NAME = "" | ( "/" path )

The leading "/" is not part of the path.  It is optional if the path
is NULL; however, the variable MUST still be set in that case.

The SCRIPT_NAME string forms some leading part of the path component
of the Script-URI derived in some implementation-defined manner.  No
PATH_INFO segment (see section 4.1.5) is included in the SCRIPT_NAME
value.

It is causing a compatibility problem with a PHP framework that calls dirname on the value of SCRIPT_NAME.

@francislavoie
Copy link
Member

Okay, that should be an easy fix. It's because of the try_files built into the php_fastcgi directive rewrites to index.php as a fallback but not /index.php.

See here: https://caddyserver.com/docs/caddyfile/directives/php_fastcgi#expanded-form

I'd still consider that a minor bug in that framework though, it works with every other framework we've thrown at it so far (Laravel, Symfony, Wordpress, etc.)

@francislavoie
Copy link
Member

The more "correct" change is to change it at the actual fastcgi implementation to ensure the trailing slash is kept. I did both in the PR but I might remove the first change since it shouldn't really be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants