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

Abierto
#44 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
api, backend, security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
2
Forks
1
Merge medio
6 min
PR fusionados (30 d)
27

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sumamakhan761/tryinstance

Todos los issues de sumamakhan761/tryinstance

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.