mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-08-21 06:26:39 +00:00
* fix(sandbox): avoid shell in FsBridge writes Replace sh -c with interpolated path by shell-free 'tee -- <path>' argv form, piping content via stdin. Prevents command injection through filenames containing shell metacharacters inside the sandbox container. Co-authored-by: evgyur <evgyur@gmail.com> * fix(security): fail-closed on pairing DB errors across channels On IsPaired lookup error, deny instead of granting access. Covers the shared CheckDMPolicy/CheckGroupPolicy helpers (Slack/Discord/Feishu/WhatsApp/Zalo) and the four inline Telegram pairing checks. Co-authored-by: Srini <srinis.k@gmail.com> * fix(security): harden provider URL validation against SSRF Enforce scheme check for all provider types; restrict local types (ollama, claude_cli, acp) to an explicit localhost allowlist instead of skipping checks; resolve remote hostnames and reject any IP in a private/reserved range via the shared security.IsBlocked CIDR list (covers loopback, link-local, metadata, multicast, and unspecified 0.0.0.0/::). Closes the wildcard-DNS bypass and the local-type escape hatch. Operator opt-in via GOCLAW_ALLOW_PRIVATE_PROVIDER_URLS. Exports security.IsBlocked as the single source of truth for blocked ranges. Co-authored-by: Linh Vo Van <linh.vo@e-cq.net> * feat(pipeline): add fail-closed tool call authorization gate Gate tool execution against the server-side AllowedTools allowlist built from the RBAC/tenant-aware filtered tool set. Resolve the tool-call prefix before the allowlist lookup so prefixed agents are not wrongly blocked, re-check deny on lazy MCP activation, and expand IsDenied to cover aliased tool names. Co-authored-by: Huy Doan <tui@pm.me> * fix(security): expand file-serve deny-list defense-in-depth Add absolute-path deny prefixes (/home, /Users, /srv, /var/lib, /var/www, /opt) and an explicit fail-closed log when no file-serving boundary is configured. Co-authored-by: Linh Vo Van <linh.vo@e-cq.net> * fix(providers): allow claude cli executable paths Refs: #1185 --------- Co-authored-by: evgyur <evgyur@gmail.com> Co-authored-by: Srini <srinis.k@gmail.com> Co-authored-by: Linh Vo Van <linh.vo@e-cq.net> Co-authored-by: Huy Doan <tui@pm.me>
49 lines
2.0 KiB
Go
49 lines
2.0 KiB
Go
package providers
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Provider-level defaults for HTTP clients and stream parsing.
|
|
const (
|
|
// Deprecated: DefaultHTTPTimeout set a wall-clock socket timeout that prevented
|
|
// ctx cancellation from unblocking bufio.Scanner. Use NewDefaultHTTPClient() instead.
|
|
DefaultHTTPTimeout = 300 * time.Second
|
|
|
|
// SSE stream scanner buffer sizes (OpenAI-compat, Anthropic, Codex).
|
|
SSEScanBufInit = 64 * 1024 // 64KB initial buffer
|
|
SSEScanBufMax = 1024 * 1024 // 1MB max line for large tool call / thinking chunks
|
|
|
|
// Stdio/JSONRPC scanner buffer sizes (Claude CLI, ACP).
|
|
StdioScanBufInit = 256 * 1024 // 256KB initial buffer
|
|
StdioScanBufMax = 10 * 1024 * 1024 // 10MB max for large protocol messages
|
|
)
|
|
|
|
// NewDefaultTransport returns an http.Transport with per-stage timeouts but no
|
|
// overall deadline. The absence of Client.Timeout allows LLM streaming responses
|
|
// (extended thinking, long completions) to run indefinitely while ctx cancellation
|
|
// still terminates the request promptly via CtxBody.
|
|
func NewDefaultTransport() *http.Transport {
|
|
return &http.Transport{
|
|
Proxy: http.ProxyFromEnvironment,
|
|
ResponseHeaderTimeout: 180 * time.Second, // wait for first byte of response (3min for slow providers)
|
|
IdleConnTimeout: 90 * time.Second, // close idle keep-alive connections
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
|
ExpectContinueTimeout: 1 * time.Second,
|
|
MaxIdleConns: 100,
|
|
MaxIdleConnsPerHost: 10,
|
|
}
|
|
}
|
|
|
|
// NewDefaultHTTPClient returns an *http.Client backed by NewDefaultTransport.
|
|
// No Client.Timeout is set — rely on ctx deadlines and Transport stage timeouts.
|
|
//
|
|
// SSRF protection for user-configured provider URLs is enforced at provider
|
|
// create/update time by validateProviderURL (resolves the host and rejects
|
|
// private/reserved IPs via security.IsBlocked). Dial-time DNS-rebinding
|
|
// hardening is tracked as a follow-up.
|
|
func NewDefaultHTTPClient() *http.Client {
|
|
return &http.Client{Transport: NewDefaultTransport()}
|
|
}
|