Skip to content

Commit b8a981d

Browse files
committed
@AlliBalliBaba suggestion, empty out script_name if it's not in server root
1 parent fd6595e commit b8a981d

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

caddy/caddy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,9 @@ func TestWorkerPHPServerGlobals(t *testing.T) {
639639
tester.AssertGetResponse(
640640
"http://localhost:"+testPortThree+"/en",
641641
http.StatusOK,
642-
"SCRIPT_NAME: "+documentRoot+"/server-globals.php<br>"+
642+
"SCRIPT_NAME: <br>"+
643643
"SCRIPT_FILENAME: "+scriptFilename+"<br>"+
644-
"PHP_SELF: "+documentRoot+"/server-globals.php<br>"+
644+
"PHP_SELF: <br>"+
645645
"PATH_INFO: <br>"+
646646
"DOCUMENT_ROOT: "+documentRoot2+"<br>"+
647647
"REQUEST_URI: /en<br>",
@@ -650,9 +650,9 @@ func TestWorkerPHPServerGlobals(t *testing.T) {
650650
tester.AssertGetResponse(
651651
"http://localhost:"+testPortThree+"/server-globals.php/en",
652652
http.StatusOK,
653-
"SCRIPT_NAME: "+documentRoot+"/server-globals.php<br>"+
653+
"SCRIPT_NAME: <br>"+
654654
"SCRIPT_FILENAME: "+scriptFilename+"<br>"+
655-
"PHP_SELF: "+documentRoot+"/server-globals.php/en<br>"+
655+
"PHP_SELF: /en<br>"+
656656
"PATH_INFO: /en<br>"+
657657
"DOCUMENT_ROOT: "+documentRoot2+"<br>"+
658658
"REQUEST_URI: /server-globals.php/en<br>",

cgi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ func splitCgiPath(fc *frankenPHPContext) {
213213
// If a worker is already assigned explicitly, derive SCRIPT_NAME from its filename
214214
if fc.worker != nil {
215215
fc.scriptFilename = fc.worker.fileName
216-
fc.scriptName = filepath.ToSlash(strings.TrimPrefix(fc.worker.fileName, fc.documentRoot))
216+
if strings.HasPrefix(fc.worker.fileName, fc.documentRoot) {
217+
fc.scriptName = filepath.ToSlash(strings.TrimPrefix(fc.worker.fileName, fc.documentRoot))
218+
}
217219
return
218220
}
219221

0 commit comments

Comments
 (0)