os.networkInterfaces() can throw and crash the process when listening on 0.0.0.0
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- backend, networking
Direzione di ricerca
Inizia da lib/server.js, in corrispondenza di getAddresses(), e segui il modo in cui logServerAddress() gestisce gli indirizzi restituiti per un binding wildcard. Riproduci l’errore facendo sì che os.networkInterfaces() generi un’eccezione, poi controlla i test del server relativi alla registrazione degli indirizzi e aggiungi test per il fallback. Il lavoro è terminato quando il server si avvia e segnala l’indirizzo a cui è associato se l’enumerazione delle interfacce non riesce.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When the server binds to the wildcard address 0.0.0.0, logServerAddress() calls getAddresses(), which calls os.networkInterfaces() unguarded. On platforms where enumerating the interface list is not permitted, os.networkInterfaces() throws, and because the call happens inside the server's listening event handler the exception escapes as an uncaught exception — the process dies instead of the server starting.
Concrete case: Android. A Node.js binary linked against glibc (e.g. a single-executable build) calls getifaddrs(), which needs CAP_NET_ADMIN for its NETLINK_ROUTE RTM_GETLINK dump and also reads /proc/net/if_inet6. Android denies both to ordinary apps, so getifaddrs() returns EACCES and Node throws:
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_interface_addresses returned Unknown system error 13 (Unknown system error 13)
at Object.networkInterfaces (node:os:218:16)
at getAddresses (/path/to/fastify/lib/server.js:...)
at Object.logServerAddress (/path/to/fastify/lib/server.js:...)
at Server.listeningEventHandler (/path/to/fastify/lib/server.js:...)
The same crash happens in any sandbox/container that forbids reading the interface list, not only Android. Note that binding to a specific address is unaffected — getAddresses() only calls os.networkInterfaces() for the 0.0.0.0 case.
Steps to reproduce
// repro.mjs
import os from 'node:os'
import Fastify from 'fastify'
// Stand in for a platform where interface enumeration is denied.
// (On Android this happens for real, see the stack trace above.)
const real = os.networkInterfaces
os.networkInterfaces = () => {
throw Object.assign(new Error('uv_interface_addresses returned Unknown system error 13'), {
code: 'ERR_SYSTEM_ERROR',
})
}
const app = Fastify()
app.get('/', async () => 'hello')
await app.listen({ host: '0.0.0.0', port: 0 })
console.log('listening')
The await never settles: the exception is thrown in the listening event handler, so it is reported as an uncaught exception and the process exits with a non-zero code, instead of the server starting.
Expected behavior
Failing to enumerate the interface list should not be fatal. The server should still start, and the address list should fall back to the bound address (as it already does for a non-wildcard bind).
Suggested fix
Guard the call in getAddresses() and fall back to the bound address:
function getAddresses (address) {
if (address.address === '0.0.0.0') {
let interfaces
try {
interfaces = os.networkInterfaces()
} catch {
return [address.address]
}
return Object.values(interfaces).flatMap((iface) => {
return iface.filter((iface) => iface.family === 'IPv4')
}).sort((iface) => {
/* c8 ignore next 2 */
// Order the interfaces so that internal ones come first
return iface.internal ? -1 : 1
}).map((iface) => { return iface.address })
}
return [address.address]
}
System Info
- fastify version: 5.8.5
- Node.js version: v24.15.0
- Platform: Android 12 (aarch64), Node linked against glibc
- Lingua principale
- JavaScript
- Stelle
- 37.5k
- Fork
- 3.2k
- Merge medio
- 2g 1h
- PR unite (30g)
- 22
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fastify/fastify
-
Document using preClose to stop starting new plugin work during shutdownForse già presa @lazerg l’ha presa 49 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
fastify/fastify#7083 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
docs(Getting-Started): Install section only documents npm and yarnForse già presa @Shreya657 l’ha presa 85 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
fastify/fastify#6983 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`path` alias missing from RouteOptions typeForse già presa @veeceey l’ha presa 285 giorni fa. Apertatypescript
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
fastify/fastify#6012 · 10 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Using $ref in response work really strange/not at allForse già presa @mcollina l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
I maintainer di solito rispondono entro 1 giorno
-
Null entry in schema content map crashes startup with TypeError instead of FST_ERR_SCH_CONTENT_MISSING_SCHEMAForse già presa @Ganesh1729-ui l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di fastify/fastify
Issue simili
-
FEATURE REQUEST
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
linuxmint/cinnamon-spices-applets#9356 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage Platform(Default)
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
linagora/twake-drive#4659 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno