Guard the Go server's request boundary: loopback Host, no Origin on /connect, shared token
The server answered any Host, so a DNS-rebinding page reached /connect (101) and could drive terminals. Every route now refuses a non-loopback Host on a loopback connection (421), /connect refuses any Origin (403), and a server started with -token-file requires X-Pipelines-Token (401; /mcp and /healthz exempt). The CLI/TUI send the token only to loopback URLs.
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/servertoken"
|
||||
"git.a-wan.net/alan/pipelines/internal/summarise"
|
||||
)
|
||||
|
||||
@@ -39,7 +40,22 @@ func main() {
|
||||
db := flag.String("db", defaultDB, "SQLite database path (honors XDG_DATA_HOME)")
|
||||
mdnsOn := flag.Bool("mdns", envEnabled(os.Getenv("PIPELINES_MDNS")), "Advertise the server on the LAN with mDNS/DNS-SD ("+discovery.ServiceType+"); PIPELINES_MDNS=off disables")
|
||||
mdnsPort := flag.Int("mdns-port", envPort(os.Getenv("PIPELINES_MDNS_PORT")), "Port LAN clients dial: the authenticated web proxy fronting this server (default: the -addr port when it is not loopback)")
|
||||
tokenFile := flag.String("token-file", os.Getenv(servertoken.EnvKey), "Require the shared secret in this private file on every request (the installer's server-token; PIPELINES_SERVER_TOKEN_FILE)")
|
||||
flag.Parse()
|
||||
accessToken := ""
|
||||
if *tokenFile != "" {
|
||||
if absolute, absErr := filepath.Abs(*tokenFile); absErr == nil {
|
||||
*tokenFile = absolute
|
||||
}
|
||||
if accessToken, err = servertoken.Read(*tokenFile); err != nil {
|
||||
log.Fatalf("server token: %v", err)
|
||||
}
|
||||
// Stages, chat harnesses and their `pipelines` CLI calls inherit the
|
||||
// file's location, never the token itself.
|
||||
_ = os.Setenv(servertoken.EnvKey, *tokenFile)
|
||||
} else {
|
||||
log.Printf("no server token configured (-token-file): local clients reach this server without the shared secret")
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(*db), 0700); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -80,7 +96,7 @@ func main() {
|
||||
// Each new run gets a bounded one-line title from the configured default
|
||||
// harness; the summariser falls back to the prompt's first line, so title
|
||||
// generation never blocks or fails run creation.
|
||||
options := server.Options{AllowAuthoring: *allowAuthoring, ArtifactsRoot: artifactsRoot, RunTitles: summarise.GenerateTitle, StepVerdicts: summarise.GenerateVerdictReason, VerificationFixtures: server.VerificationFixturesFromEnvironment(os.Getenv), DetachSessions: detach}
|
||||
options := server.Options{AllowAuthoring: *allowAuthoring, ArtifactsRoot: artifactsRoot, RunTitles: summarise.GenerateTitle, StepVerdicts: summarise.GenerateVerdictReason, VerificationFixtures: server.VerificationFixturesFromEnvironment(os.Getenv), DetachSessions: detach, AccessToken: accessToken}
|
||||
recorded := ""
|
||||
if value, err := store.OpenCodeEndpoint(ctx); err != nil {
|
||||
log.Printf("OpenCode endpoint setting unreadable: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user