mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
In ARTEX_SANDBOX=required the panel must not start agent-controlled local processes. discoverAndCacheMCP now refuses stdio before connectMCP, which covers startup auto-discovery, the operator add/refresh paths and ScopeSentry; the Auto agent's create_mcp and update_mcp reject stdio transports as well. HTTP and SSE MCP clients keep their existing checks. The canary test proves the command is not spawned.
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/artex/agent"
|
|
"github.com/Autumn-27/artex/db"
|
|
"github.com/Autumn-27/artex/sandbox"
|
|
)
|
|
|
|
func withSandboxRequired(t *testing.T) {
|
|
t.Helper()
|
|
prev := agent.CurrentSandboxExecutor()
|
|
agent.SetSandboxExecutor(&agent.SandboxExecutor{Mode: sandbox.ModeRequired})
|
|
t.Cleanup(func() { agent.SetSandboxExecutor(prev) })
|
|
}
|
|
|
|
// The panel must never start a stdio MCP process in required mode. The canary
|
|
// command would create a file if connectMCP reached it; the guard returns before
|
|
// the process is spawned.
|
|
func TestSandboxSkipsStdioMCPDiscovery(t *testing.T) {
|
|
withSandboxRequired(t)
|
|
dir := t.TempDir()
|
|
canary := filepath.Join(dir, "stdio-mcp-ran")
|
|
args, _ := json.Marshal([]string{"-c", "touch " + canary})
|
|
m := &db.MCPServer{Name: "t-sandbox-stdio", Transport: "stdio", Command: "sh", Args: args, Enabled: true}
|
|
s := &Server{}
|
|
err := s.discoverAndCacheMCP(context.Background(), m)
|
|
if err == nil || !strings.Contains(err.Error(), "ARTEX_SANDBOX=required") {
|
|
t.Fatalf("discovery error = %v, want the sandbox refusal", err)
|
|
}
|
|
if _, statErr := os.Stat(canary); statErr == nil {
|
|
t.Fatal("stdio MCP command ran on the panel in required mode")
|
|
}
|
|
}
|
|
|
|
func TestSandboxMCPToolGuardsStdioOnly(t *testing.T) {
|
|
withSandboxRequired(t)
|
|
for _, tc := range []struct {
|
|
transport string
|
|
blocked bool
|
|
}{
|
|
{"", true},
|
|
{"stdio", true},
|
|
{"http", false},
|
|
{"sse", false},
|
|
} {
|
|
if got := sandboxBlocksStdioMCP(&db.MCPServer{Transport: tc.transport}); got != tc.blocked {
|
|
t.Errorf("transport %q blocked=%v, want %v", tc.transport, got, tc.blocked)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSandboxCreateMCPRejectsStdio(t *testing.T) {
|
|
withSandboxRequired(t)
|
|
tool := (&Server{}).toolCreateMCP()
|
|
res, err := tool.Call(context.Background(), json.RawMessage(`{"name":"t-stdio","transport":"stdio","command":"sh"}`), nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !res.IsError || !strings.Contains(res.Flatten(), "ARTEX_SANDBOX=required") {
|
|
t.Fatalf("create_mcp result = %q, want the sandbox refusal", res.Flatten())
|
|
}
|
|
}
|