AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Security/Bug] interaction_webhook.go allows SSRF to loopback/private IPs (bypassing loopback admin control plane) and spawns unbounded 24h retry goroutines

Open photobrand opened this issue 1 week ago • 1 comments

发生了什么 / What happened

Summary

Unlike internal/api/remote_media.go (which blocks loopback, private, link-local, multicast, and redirect targets via checkRemoteMediaHost / checkRemoteMediaAddress), internal/api/interaction_webhook.go sends outbound POST webhooks using an unrestricted http.Client:

var interactionWebhookClient = &http.Client{Timeout: 10 * time.Second}

func (config interactionWebhookConfig) validate(background bool) error {
	if !background {
		return fmt.Errorf("webhook_config requires background to be true")
	}
	for _, uri := range config.URIs {
		if parsed, err := url.Parse(uri); err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {
			return fmt.Errorf("webhook_config.uris must be http or https URLs: %q", uri)
		}
	}
	return nil
}

Security & Resource Impact

  1. SSRF & loopback control-plane bypass: When ADMIN_AUTH_ENABLED=false (default local mode), /api/ is guarded by loopbackMiddleware + sameOriginMiddleware (internal/api/admin_auth.go:128-131). Any caller of POST /v1/interactions (background: true) can pass webhook_config.uris: ["http://127.0.0.1:<port>/api/control/stop"] (or http://169.254.169.254/...), causing the server itself to issue a loopback POST with no Origin / Sec-Fetch-Site headers, bypassing both middlewares.
  2. Unbounded 24h retry goroutines: len(config.URIs) is uncapped, and deliverInteractionWebhook (lines 83-100) loops with time.Sleep for up to 24 * time.Hour without a shutdown context (and closes response.Body without draining).

Suggested Fix

  1. Reuse the SSRF-hardened remoteMediaTransport() + checkRemoteMediaHost + CheckRedirect logic from internal/api/remote_media.go on interactionWebhookClient, and cap len(config.URIs).
  2. Pass a lifecycle context.Context into deliverInteractionWebhook and drain response.Body (bounded) before closing.

版本 / Version

v0.3.14

photobrand avatar Nov 22 '26 15:11 photobrand

These 3 issues probably won't be done either, because the trigger conditions are too narrow or they don't match the expected behavior, also please see this comment, you can edit these issues in-place, but pls dont send too much

Mag1cFall avatar Nov 22 '26 15:11 Mag1cFall