fix(connectors): prevent SSRF in custom AI baseUrl and ActiveCampaign apiEndpoint

Aperta
#44 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
api, backend, security

Direzione di ricerca

Start with the named AI connector service and adapter files, then inspect the ActiveCampaign adapter and email connector service. Trace how each URL is saved and passed to fetch, including DNS resolution and redirects; check the relevant connector tests before changing behavior. Done means unsafe URLs are rejected on save and fetch, allowed local development URLs still work, and validation errors remain visible.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

backend bug
Problem Description

User-supplied endpoint URLs in Custom AI Connectors (baseUrl) and ActiveCampaign (apiEndpoint) are fetched by the backend without complete SSRF protection, allowing an attacker to probe internal services (127.0.0.1, localhost, 172.16.0.0/12, 10.0.0.0/8), cloud metadata (169.254.169.254), or private VPC/Docker hosts:

  1. AiConnectorsService.fetchModels (apps/api/src/ai-connectors/ai-connectors.service.ts, lines 231-246):

    • Constructs ${cleanBase}/models directly from connector.baseUrl and calls fetch(url) with no URL or IP validation.
  2. normalizeChatCompletionsUrl (packages/ai-connectors/src/adapters/index.ts, lines 41-73):

    • Misses 172.16.0.0/12, 0.0.0.0, CGNAT (100.64.0.0/10), IPv6 private/loopback/link-local ranges (::1, fc00::/7, fe80::/10), and IPv4-mapped IPv6 (::ffff:127.0.0.1, ::ffff:169.254.169.254).
    • Only inspects the raw hostname string rather than the resolved DNS IP, allowing DNS rebinding or a domain with an A record pointing to 127.0.0.1 / 169.254.169.254 to bypass it.
    • Follows HTTP 301/302 redirects by default and silently swallows new URL(trimmed) parse errors in its catch block.
  3. ActiveCampaignAdapter.normalizeBaseUrl (packages/email-connectors/src/adapters/activecampaign.adapter.ts, lines 11-14):

    • Accepts credentials.apiEndpoint directly (or falls back to youraccount.api-us1.com if missing) and calls fetch in testConnection, getAudiences, and upsertSubscriber with zero URL/IP validation. Furthermore, getAudiences catches all errors and returns [], hiding validation failures.

Expected Behavior
  1. Strict in production, dev-friendly locally: In production (unless ALLOW_PRIVATE_CONNECTOR_URLS=true is explicitly set), only https: URLs resolving to public IPs are allowed. Local/dev testing (e.g., Ollama http://localhost:11434/v1) continues to work when NODE_ENV !== 'production' or ALLOW_PRIVATE_CONNECTOR_URLS=true.
  2. Full IP & DNS validation: Resolve hostnames via dns.lookup(..., { all: true }), unwrap IPv4-mapped IPv6 (::ffff:...), and block all loopback, private (RFC1918), link-local (169.254.0.0/16), CGNAT (100.64.0.0/10), unspecified (0.0.0.0), and IPv6 (::1, fc00::/7, fe80::/10) ranges.
  3. Validate on save + clear errors: Reject invalid/unsafe URLs when saving AI or Email connectors, do not swallow SSRF/validation errors as [] in ActiveCampaignAdapter.getAudiences, and require a valid apiEndpoint instead of falling back to youraccount.api-us1.com.
  4. Safe redirect handling: Block redirects (redirect: 'error') with a clear user-facing error ("Redirects are not allowed; please use the final HTTPS URL") or manually re-validate redirect Location targets.

Where to Look
  • apps/api/src/ai-connectors/ai-connectors.service.ts (fetchModels, createConnector/updateConnector, testConnection, runPlayground)
  • packages/ai-connectors/src/adapters/index.ts (normalizeChatCompletionsUrl)
  • packages/email-connectors/src/adapters/activecampaign.adapter.ts (normalizeBaseUrl, testConnection, getAudiences, upsertSubscriber)
  • apps/api/src/email-connectors/email-connectors.service.ts (validate apiEndpoint on save)

Solution / Implementation Guide
  1. Create a shared assertSafeExternalUrl(rawUrl: string) helper:
    • Parse with new URL(rawUrl) (fail closed on parse error) and enforce https: (allowing http: / private IPs only when NODE_ENV !== 'production' or ALLOW_PRIVATE_CONNECTOR_URLS === 'true').
    • Resolve DNS (dns.lookup(hostname, { all: true })), unwrap IPv4-mapped IPv6 (::ffff: prefix), and reject any private, loopback, link-local, CGNAT, multicast, or reserved IPv4/IPv6 CIDR.
  2. Apply at both save-time and fetch-time:
    • Validate baseUrl / apiEndpoint on connector create/update and inside normalizeChatCompletionsUrl, AiConnectorsService.fetchModels, and ActiveCampaignAdapter.normalizeBaseUrl (removing the youraccount.api-us1.com fallback).
    • Pass redirect: 'error' to fetch(...) and catch redirect failures with a clear error message; rethrow validation/SSRF errors in ActiveCampaignAdapter.getAudiences.
Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
6m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sumamakhan761/tryinstance

Tutte le issue di sumamakhan761/tryinstance

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.