Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion caddy/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ c
if documentRoot == "" && frankenphp.EmbeddedAppPath != "" {
documentRoot = frankenphp.EmbeddedAppPath
}
documentRootOption = frankenphp.WithRequestDocumentRoot(documentRoot, *f.ResolveRootSymlink)
//If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
//resolve to a different directory than the one we are currently in.
//This is especially important if there are workers running.
Comment on lines +151 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
//resolve to a different directory than the one we are currently in.
//This is especially important if there are workers running.
// If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
// resolve to a different directory than the one we are currently in.
// This is especially important if there are workers running.

documentRootOption = frankenphp.WithRequestDocumentRoot(documentRoot, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking for symlinks here seems like it might break some setups. Definitely would be nice to test all the edge cases somehow (should be possible with caddy_tests?).

Tbh though, I don't know what the current edge cases with symlinks are

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m pretty sure we don’t want to evaluate symlinks here. In the case where a document root was expressly given (such as prod setups), we will never even enter this branch. In the case where a document root isn’t given, we need to be compatible with how we resolve workers. There is an edge case here that I didn’t cover, and I’m working out how to handle it: chained symlinks.

I suspect I’ll have to go back to the drawing board.

} else {
documentRoot = f.resolvedDocumentRoot
documentRootOption = frankenphp.WithRequestResolvedDocumentRoot(documentRoot)
Expand Down
10 changes: 9 additions & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package frankenphp
import "C"
import (
"fmt"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -74,7 +75,14 @@ func getWorkerKey(name string, filename string) string {
}

func newWorker(o workerOpt) (*worker, error) {
absFileName, err := fastabs.FastAbs(o.fileName)
//Order is important!
//This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
//If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.
Comment on lines +78 to +80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Order is important!
//This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
//If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.
// Order is important!
// This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
// If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.

absFileName, err := filepath.EvalSymlinks(o.fileName)
if err != nil {
return nil, fmt.Errorf("worker filename is invalid %q: %w", o.fileName, err)
}
Comment on lines +81 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍 explicitly checking if a worker exists is something I actually wanted to do for a long time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or wait, evalSymlinks will just evaluate symlinks. In that case it would also be nice to error right away if there's no file there. Can also be done in another PR though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it errors if the file doesn't exist (I had to update a failing test -- haven't pushed the commit yet)

absFileName, err = fastabs.FastAbs(absFileName)
if err != nil {
return nil, fmt.Errorf("worker filename is invalid %q: %w", o.fileName, err)
}
Expand Down
Loading