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:
@@ -0,0 +1,45 @@
|
||||
//go:build unix
|
||||
|
||||
package servertoken
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadAcceptsOnlyAPrivateRegularFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "server-token")
|
||||
token := strings.Repeat("t", 48)
|
||||
if err := os.WriteFile(path, []byte(token+"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := Read(path); err != nil || got != token {
|
||||
t.Fatalf("Read = %q, %v", got, err)
|
||||
}
|
||||
if err := os.Chmod(path, 0o640); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := Read(path); err == nil {
|
||||
t.Fatal("group-readable token accepted")
|
||||
}
|
||||
os.Chmod(path, 0o600)
|
||||
link := filepath.Join(dir, "link")
|
||||
os.Symlink(path, link)
|
||||
if _, err := Read(link); err == nil {
|
||||
t.Fatal("symlinked token accepted")
|
||||
}
|
||||
short := filepath.Join(dir, "short")
|
||||
os.WriteFile(short, []byte("short"), 0o600)
|
||||
if _, err := Read(short); err == nil {
|
||||
t.Fatal("short token accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualIsExact(t *testing.T) {
|
||||
if Equal("", "") || Equal("a", "") || !Equal("abc", "abc") || Equal("abc", "abd") {
|
||||
t.Fatal("Equal mismatch")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user