fastify / forwarded

Parse HTTP X-Forwarded-For header (fork)
MIT License
8 stars 4 forks source link

Handling destroyed sockets necessary? #42

Closed Uzlopak closed 2 years ago

Uzlopak commented 2 years ago

Prerequisites

Issue

In the original repo of forwarded is an old issue regarding destroyed sockets. https://github.com/jshttp/forwarded/issues/12

So I think it is something like the following scenario

Browser connects to server by obviously opening a socket connection. While the request is being processed, browser disconnects and so the socket gets destroyed on server-side. Now the socketAddr is undefined.

What should be then the actual behaviour? I mean it is a very very slim chance, that exactly in that moment while the forwarded header is processed the socket gets destroyed, but in the current implementation we will end up with an undefined value as first element in the resulting array.

mcollina commented 2 years ago

What should be then the actual behaviour? I mean it is a very very slim chance, that exactly in that moment while the forwarded header is processed the socket gets destroyed, but in the current implementation we will end up with an undefined value as first element in the resulting array.

I think there should be no chance of this happening. If there is no underlining socket, processing the request should be aborted immediately. I would rather add some protection in Fastify for this use case.