`client-ip` is not an IP address when `x-forwarded-for` holds a list or a port
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
Línea de trabajo
Empieza en src/lib/functions/server.ts, en createHandler, y compara después el manejo de requests circundante con src/utils/proxy.ts. Ejecuta la reproducción del issue con functions:serve usando ambos ejemplos de x-forwarded-for. Se considera terminado cuando client-ip y x-nf-client-connection-ip contienen una IP válida para esas entradas, mientras netlify dev no se ve afectado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Under netlify functions:serve, the client-ip and x-nf-client-connection-ip headers that
reach a serverless function are not always an IP address. They can be the whole
x-forwarded-for list, or a port number.
createHandler builds the value like this (src/lib/functions/server.ts):
let remoteAddress = request.header('x-forwarded-for') || request.connection.remoteAddress || ''
remoteAddress = remoteAddress.split(remoteAddress.includes('.') ? ':' : ',').pop()?.trim() ?? ''
The separator is chosen from whether the string contains a dot, so a comma-separated IPv4 list
is never split on the comma.
Steps to reproduce
mkdir -p netlify/functions
cat > netlify/functions/whoami.js <<'EOF'
exports.handler = async (event) => ({
statusCode: 200,
body: JSON.stringify({ clientIp: event.headers['client-ip'] }),
})
EOF
netlify functions:serve --port 9999 &
curl -s -H 'x-forwarded-for: 1.2.3.4, 5.6.7.8' localhost:9999/.netlify/functions/whoami
curl -s -H 'x-forwarded-for: 1.2.3.4:5678' localhost:9999/.netlify/functions/whoami
Expected behavior
One IP address, i.e. net.isIP(clientIp) !== 0.
Actual behavior
{"clientIp":"1.2.3.4, 5.6.7.8"}
{"clientIp":"5678"}
net.isIP() returns 0 for both. A function that parses client-ip, compares it, or
passes it to a geo/rate-limit library gets a value that cannot be an address, and this
only shows up locally — in production Netlify sends a single address.
Note that netlify dev is unaffected: the dev proxy overwrites x-forwarded-for with
req.connection.remoteAddress before the functions server sees it
(src/utils/proxy.ts), so a single address always arrives. functions:serve runs the
functions server without that proxy, so the client's own header is used verbatim.
Environment
- netlify-cli 27.10.0 (
mainat 904515c) - Node 22.23.3
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.9k
- Forks
- 480
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 66
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de netlify/cli
-
db-status.test fails if the database is disabledPosiblemente ocupada @paulleephp la tomó hoy. Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`netlify dev` with `--cwd` from outside the project: every function 500s with "module is not defined in ES module scope" (`detectZisiBuilder` passes a string to `readPackageUp`)Posiblemente ocupada @bsplatt92 la tomó hace 62 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
area: command: deploy area: docs type: feature
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
netlify/cli#1984 · 19 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
type: bug
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
Los mantenedores suelen responder en 1 día
-
type: bug
Dificultad 3/5 1-2 días Aptitud para principiantes 38/100
Los mantenedores suelen responder en 1 día
Todos los issues de netlify/cli
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
paperclipai/paperclip#16785 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
code-yeongyu/senpi#3661 ·
Los mantenedores suelen responder en 1 día
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
lingdojo/kana-dojo#32731 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
bug status: needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
mastra-ai/mastra#27538 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Yeachan-Heo/oh-my-codex#3822 ·
Los mantenedores suelen responder en 1 día