danielmiessler.fabric/internal/cli/setup_server.go
Kayvan Sylvan f37c71f9f7 fix: secure storage paths and authenticate REST and Ollama servers
- Reject unsafe cross-platform storage names and traversal attempts.
- Confine symlink targets within configured filesystem storage directories.
- Require API keys for every non-loopback server binding.
- Authenticate Ollama routes and securely forward configured credentials.
- Validate chat pattern, context, and session names early.
- Sanitize client errors to hide internal filesystem details.
- Default REST server binding to loopback port 8080.
- Add regression coverage for traversal, symlinks, and authentication.
2026-09-02 15:59:59 -07:00

35 lines
1 KiB
Go

package cli
import (
"github.com/danielmiessler/fabric/internal/core"
restapi "github.com/danielmiessler/fabric/internal/server"
)
// serveOllama is a seam for tests, because the real entry point blocks
// on a listening socket.
var serveOllama = restapi.ServeOllama
// handleSetupAndServerCommands handles setup and server-related commands
// Returns (handled, error) where handled indicates if a command was processed and should exit
func handleSetupAndServerCommands(currentFlags *Flags, registry *core.PluginRegistry, version string) (handled bool, err error) {
// if the setup flag is set, run the setup function
if currentFlags.Setup {
err = registry.Setup()
return true, err
}
if currentFlags.Serve {
registry.ConfigureVendors()
err = restapi.Serve(registry, currentFlags.ServeAddress, currentFlags.ServeAPIKey)
return true, err
}
if currentFlags.ServeOllama {
registry.ConfigureVendors()
err = serveOllama(registry, currentFlags.ServeAddress, version, currentFlags.ServeAPIKey)
return true, err
}
return false, nil
}