AIStudio2API
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
发生了什么 / 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
- SSRF & loopback control-plane bypass: When
ADMIN_AUTH_ENABLED=false(default local mode),/api/is guarded byloopbackMiddleware+sameOriginMiddleware(internal/api/admin_auth.go:128-131). Any caller ofPOST /v1/interactions(background: true) can passwebhook_config.uris: ["http://127.0.0.1:<port>/api/control/stop"](orhttp://169.254.169.254/...), causing the server itself to issue a loopbackPOSTwith noOrigin/Sec-Fetch-Siteheaders, bypassing both middlewares. - Unbounded 24h retry goroutines:
len(config.URIs)is uncapped, anddeliverInteractionWebhook(lines 83-100) loops withtime.Sleepfor up to24 * time.Hourwithout a shutdown context (and closesresponse.Bodywithout draining).
Suggested Fix
- Reuse the SSRF-hardened
remoteMediaTransport()+checkRemoteMediaHost+CheckRedirectlogic frominternal/api/remote_media.gooninteractionWebhookClient, and caplen(config.URIs). - Pass a lifecycle
context.ContextintodeliverInteractionWebhookand drainresponse.Body(bounded) before closing.
版本 / Version
v0.3.14
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